Skip to content

Commit

Permalink
fix: match endorsementId with the DB
Browse files Browse the repository at this point in the history
  • Loading branch information
Atifsid committed May 12, 2024
1 parent 0fb19dd commit 99349dc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public ResponseEntity<GenericResponse<EndorsementDTO>> postEndorsement(

@PatchMapping(value = "/{id}")
public ResponseEntity<GenericResponse<Void>> updateEndorsementStatus(
@PathVariable(value = "id") String id, @RequestParam String status) {
@PathVariable(value = "id") UUID id, @RequestParam String status) {
return ResponseEntity.ok().body(endorsementService.updateEndorsementStatus(id, status));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ Page<EndorsementModelFromJSON> getEndorsementsFromDummyData(

EndorsementModel createEndorsement(EndorsementDRO endorsementDRO);

GenericResponse<Void> updateEndorsementStatus(String id, String status);
GenericResponse<Void> updateEndorsementStatus(UUID id, String status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public EndorsementModel createEndorsement(EndorsementDRO endorsementDRO) {
}

@Override
public GenericResponse<Void> updateEndorsementStatus(String id, String status) {
public GenericResponse<Void> updateEndorsementStatus(UUID id, String status) {
UserModel user =
(UserModel) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (!user.getRole().equals(UserRole.SUPERUSER)) {
Expand All @@ -146,13 +146,11 @@ public GenericResponse<Void> updateEndorsementStatus(String id, String status) {
|| status.equals(EndorsementStatus.REJECTED.name()))) {
throw new InvalidParameterException("endorsement status", status);
}
if (!CommonUtils.isValidUUID(id)) {
throw new InvalidParameterException("endorsement id", id);
if (!CommonUtils.isValidUUID(id.toString())) {
throw new InvalidParameterException("endorsement id", id.toString());
}

UUID endorsementId = UUID.fromString(id);
Optional<EndorsementModel> optionalEndorsementModel =
endorsementRepository.findById(endorsementId);
Optional<EndorsementModel> optionalEndorsementModel = endorsementRepository.findById(id);
if (optionalEndorsementModel.isPresent()) {
EndorsementModel updatedEndorsementModel =
EndorsementModel.builder()
Expand Down

0 comments on commit 99349dc

Please sign in to comment.