Skip to content

Commit

Permalink
Merge pull request #141 from mcanoy/get-e-by-uuid
Browse files Browse the repository at this point in the history
add a retrieve by engagement uuid api
  • Loading branch information
mcanoy authored Aug 11, 2021
2 parents a472dc3 + 81646fc commit ce15a84
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ public Response createEngagement(Engagement engagement, @Context UriInfo uriInfo
return Response.created(builder.build()).build();

}

@GET
@Path("uuid/{uuid}")
public Response getEngagementByUuid(@PathParam("uuid") String uuid) {
Optional<Engagement> engagement = Optional.ofNullable(engagementService.getEnagementByUuid(uuid));

if(engagement.isPresent()) {
return Response.ok(engagement).build();
}
return Response.noContent().status(404).entity(String.format("{ \"message\": \"Unable to find engagement for uuid %s in git-api\"}", uuid)).build();
}

@GET
@Counted(name = "get-all-engagement", description = "Count of get all engagements")
Expand Down Expand Up @@ -191,7 +202,7 @@ public Response getProjectByUuid(@PathParam("uuid") String uuid, @QueryParam("mi
Optional<Project> p = engagementService.getProjectByUuid(uuid);

if(p.isEmpty()) {
return Response.status(404).build();
return Response.status(404).entity("{ \"message\": \"Unable to get project by uuid\" }").build();
}

if(mini) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,16 @@ private List<Engagement> getEngagementsFromProject(List<Project> projects, Optio
.collect(Collectors.toList());

}

public Engagement getEnagementByUuid(String uuid) {
Engagement engagement = null;
Optional<Project> project = getProjectByUuid(uuid);
if(project.isPresent()) {
engagement = getEngagement(project.get(), false, false).orElse(null);
}

return engagement;
}

public Engagement getEngagement(String namespaceOrId, boolean includeStatus) {
Engagement engagement = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,26 @@ void testGetAllEngagementsSuccess() {
+ " }\n" + "]"));

}

@Test
void testGetEngagementByUuid() {
MockUtils.setFindProjectByEngagementId(gitLabService, 2, "abcd", Project.builder().id(1).build());
MockUtils.setGetFileForEngagementJsonMock(gitLabService, 2, true);

String engagementUuid = "k";

// Not found
given().pathParam("engagementUuid", engagementUuid).when().contentType(ContentType.JSON)
.get("/api/v1/engagements/uuid/{engagementUuid}").then().statusCode(404).body("message", is("Unable to find engagement for uuid k in git-api"));

engagementUuid = "abcd";
// Found
given().pathParam("engagementUuid", engagementUuid).when().contentType(ContentType.JSON)
.get("/api/v1/engagements/uuid/{engagementUuid}").then().statusCode(404);
}

@Test
void tesetGetEngagementByNamespace() {
void testGetEngagementByNamespace() {

// get projects by id
Integer projectId = MockUtils.setGetProjectByPathMock(gitLabService, "top/dog/jello/tutti-frutti/iac", true,
Expand Down

0 comments on commit ce15a84

Please sign in to comment.