Skip to content

Commit

Permalink
added endpoints for deleting a contact. close #2868
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed Mar 4, 2025
1 parent 0e9d52c commit d2f9d9c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -686,4 +686,6 @@ public interface ContactsEndpointLocalV2 {

Response updateContact(RestfulContactV2 contact);

Response deleteContact(String id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ You should also get your employer (if you work as a programmer) or school,
import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
Expand Down Expand Up @@ -881,6 +882,41 @@ public Response createContact(RestfulContactV2 contact) {
}

}

/**
* Creates a new contact
*
* @param id contact id
* @response 401 User not authorized
* @response 403 User not authenticated
* @response 404 Contact not found
*/
@Override
@DELETE
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
@Path("/{id}/delete")
@RolesAllowed({"createAddressRole"})
public Response deleteContact(@PathParam("id") String id) {
try {

InitialContext ic = new InitialContext();
AddressServiceLocal addresses = (AddressServiceLocal) ic.lookup("java:global/j-lawyer-server/j-lawyer-server-ejb/AddressService!com.jdimension.jlawyer.services.AddressServiceLocal");

AddressBean a=addresses.getAddress(id);
if(a==null) {
return Response.status(Response.Status.NOT_FOUND).build();
}

addresses.removeAddress(id);
Response res = Response.ok().build();
return res;
} catch (Exception ex) {
log.error("can not delete address " + id, ex);
Response res = Response.serverError().build();
return res;
}

}

/**
* Updates an existing contact based on its ID. The external ID of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ public interface AddressServiceLocal {
ArrayList<String> getAllAddressIds();

public void updateAddress(AddressBean dto);
public void removeAddress(String id);

Collection<AddressTagsBean> getTags(String addressId);

Expand Down

0 comments on commit d2f9d9c

Please sign in to comment.