Skip to content

Commit

Permalink
Issue #43 - DELETE REST calls should not expect a RequestBody
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-d-taylor committed Jul 20, 2015
1 parent 05e3361 commit 01be2e8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 27 deletions.
2 changes: 1 addition & 1 deletion smwc/src/main/java/edu/usm/web/CommitteeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Response updateCommitteeDetails(@PathVariable("id") String id, @RequestBo

@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces={"application/json"})
public Response updateCommittee(@PathVariable("id") String id) {
public Response deleteCommittee(@PathVariable("id") String id) {
Committee committee = committeeService.findById(id);
if (null == committee) {
return new Response(null, Response.FAILURE, "Committee with ID "+id+" does not exist.");
Expand Down
18 changes: 8 additions & 10 deletions smwc/src/main/java/edu/usm/web/ContactController.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,15 @@ public Response addContactToOrganization(@PathVariable("id") String id, @Request
}

@ResponseStatus(HttpStatus.OK)
@RequestMapping(method = RequestMethod.DELETE, value = "/{id}/organizations", consumes= {"application/json"})
public Response removeContactFromOrganization(@PathVariable("id") String id, @RequestBody IdDto idDto) {
String idStringed = idDto.getId();
@RequestMapping(method = RequestMethod.DELETE, value = "/{id}/organizations/{orgId}", consumes= {"application/json"})
public Response removeContactFromOrganization(@PathVariable("id") String id, @PathVariable("orgId") String orgId) {

Organization organization = organizationService.findById(idStringed);
Organization organization = organizationService.findById(orgId);
Contact contact = contactService.findById(id);

if (organization == null) {
logger.debug("No org");
return new Response(null,Response.FAILURE, "Organization with ID " + idStringed + " does not exist");
return new Response(null,Response.FAILURE, "Organization with ID " + orgId + " does not exist");

} else if (contact == null) {
logger.debug("No contact");
Expand Down Expand Up @@ -334,16 +333,15 @@ public Response addContactToCommittee(@PathVariable("id") String id, @RequestBod
}

@ResponseStatus(HttpStatus.OK)
@RequestMapping(method = RequestMethod.DELETE, value = "/{id}/committees", consumes= {"application/json"})
public Response removeContactFromCommittee(@PathVariable("id") String id, @RequestBody IdDto idDto) {
String idStringed = idDto.getId();
@RequestMapping(method = RequestMethod.DELETE, value = "/{id}/committees/{comId}", consumes= {"application/json"})
public Response removeContactFromCommittee(@PathVariable("id") String id, @PathVariable("comId") String comId) {

Committee committee = committeeService.findById(idDto.getId());
Committee committee = committeeService.findById(comId);
Contact contact = contactService.findById(id);

if (committee == null) {
logger.debug("No committee");
return new Response(null,Response.FAILURE, "Committee with ID " + idStringed + " does not exist");
return new Response(null,Response.FAILURE, "Committee with ID " + comId + " does not exist");

} else if (contact == null) {
logger.debug("No contact");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,9 @@ public void testRemoveContactFromOrganization () throws Exception {

String orgID = organizationService.create(organization);


IdDto organizationIdDto = new IdDto(orgID);
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(organizationIdDto);

mockMvc.perform(delete("/contacts/" + id + "/organizations")
mockMvc.perform(delete("/contacts/" + id + "/organizations/"+orgID)
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content(json))
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.status", is("SUCCESS")));
}
Expand Down Expand Up @@ -444,18 +438,17 @@ public void testRemoveContactFromCommittee () throws Exception {

Committee committee = new Committee();
committee.setName("orgName");
HashSet members = new HashSet();
members.add(contact);
committee.setMembers(members);

String committeeID = committeeService.create(committee);

committeeService.create(committee);

IdDto organizationIdDto = new IdDto(committeeID);
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(organizationIdDto);
String committeeID = committeeService.create(committee);

mockMvc.perform(delete("/contacts/" + id + "/committees")
mockMvc.perform(delete("/contacts/" + id + "/committees/"+committeeID)
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content(json))
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.status", is("SUCCESS")));
}
Expand Down

0 comments on commit 01be2e8

Please sign in to comment.