Skip to content

Commit

Permalink
consider only non-remote registrations for count of registered partic…
Browse files Browse the repository at this point in the history
…ipants (#44)

this works always, as for non-hybrid events, "remote" attribute is always "false", no matter if it's an onsite or remote event
  • Loading branch information
dasniko committed Sep 20, 2022
1 parent ad32d80 commit 1b7cf77
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/main/java/de/jugda/registration/dao/RegistrationDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -67,11 +68,19 @@ public List<Registration> findByEventId(String eventId) {
}

public List<Registration> findWaitlistByEventId(String eventId) {
return findByEventId(eventId).stream().filter(Registration::isWaitlist).collect(Collectors.toUnmodifiableList());
return findByEventId(eventId).stream().filter(Registration::isWaitlist).toList();
}

public int getCount(String eventId) {
return dynamoDB.query(builder -> byEventIdQueryBuilder(builder, eventId).projectionExpression(null).expressionAttributeNames(null).select(Select.COUNT)).count();
HashMap<String, AttributeValue> attributeValues = new HashMap<>(getBaseAttributeValues(eventId));
attributeValues.put(":v_remote", AttributeValue.builder().bool(false).build());
return dynamoDB.query(builder -> byEventIdQueryBuilder(builder, eventId)
.projectionExpression(null)
.expressionAttributeNames(null)
.filterExpression("remote = :v_remote")
.expressionAttributeValues(attributeValues)
.select(Select.COUNT)
).count();
}

public Registration delete(String id) {
Expand Down Expand Up @@ -103,12 +112,16 @@ private QueryRequest.Builder baseQueryRequestBuilder(QueryRequest.Builder builde
private QueryRequest.Builder byEventIdQueryBuilder(QueryRequest.Builder builder, String eventId) {
return baseQueryRequestBuilder(builder)
.keyConditionExpression("eventId = :v_eventId")
.expressionAttributeValues(Map.of(":v_eventId", toAttribute(eventId)))
.expressionAttributeValues(getBaseAttributeValues(eventId))
;
}

private AttributeValue toAttribute(String value) {
return AttributeValue.builder().s(value).build();
}

private Map<String, AttributeValue> getBaseAttributeValues(String eventId) {
return Map.of(":v_eventId", toAttribute(eventId));
}

}

0 comments on commit 1b7cf77

Please sign in to comment.