Skip to content

Commit

Permalink
filter engagement counts by region (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanoy authored Feb 22, 2022
1 parent 86b80a5 commit 9f383f5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public Response getAll(@Context UriInfo uriInfo, @BeanParam ListFilterOptions fi
@APIResponses(value = { @APIResponse(responseCode = "401", description = "Missing or Invalid JWT"),
@APIResponse(responseCode = "200", description = "Engagement counts computed.") })
@Operation(summary = "Gets a map of engagement counts by status")
public Map<EngagementState, Integer> countByStatus(@QueryParam(value = "localTime") String localTime) {
public Map<EngagementState, Integer> countByStatus(@QueryParam(value = "localTime") String localTime, @QueryParam("region") Set<String> regions) {

Instant currentTime = localTime == null ? Instant.now() : Instant.parse(localTime);

return engagementService.getEngagementCountByStatus(currentTime);
return engagementService.getEngagementCountByStatus(currentTime, regions);
}

//TODO metrics is saying this is not called
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface EngagementApiClient {
//TODO support time shifting
@GET
@Path("count")
Map<Engagement.EngagementState, Integer> getEngagementCounts();
Map<Engagement.EngagementState, Integer> getEngagementCounts(@QueryParam("region") Set<String> region);

@GET
@Path("category/{category}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,8 @@ public Engagement getByProjectId(int projectId) {
return engagementApiClient.getEngagementByProject(projectId);
}

public Map<EngagementState, Integer> getEngagementCountByStatus(Instant currentTime) {
return engagementApiClient.getEngagementCounts();
public Map<EngagementState, Integer> getEngagementCountByStatus(Instant currentTime, Set<String> regions) {
return engagementApiClient.getEngagementCounts(regions);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.equalTo;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -41,7 +42,7 @@ void resourceCount() {
counts.put(Engagement.EngagementState.PAST, 2);
counts.put(Engagement.EngagementState.ANY, 42);

Mockito.when(engagementApiClient.getEngagementCounts()).thenReturn(counts);
Mockito.when(engagementApiClient.getEngagementCounts(Collections.emptySet())).thenReturn(counts);

given().when().auth().oauth2(token).get(url).then().statusCode(200).body("UPCOMING", equalTo(16))
.body("ACTIVE", equalTo(8))
Expand Down

0 comments on commit 9f383f5

Please sign in to comment.