From 99349dce4a1b5c1cbe38d13899a3941e1357ffd1 Mon Sep 17 00:00:00 2001 From: Atifsid Date: Sun, 12 May 2024 13:49:44 +0530 Subject: [PATCH] fix: match endorsementId with the DB --- .../skilltree/Endorsement/EndorsementController.java | 2 +- .../RDS/skilltree/Endorsement/EndorsementService.java | 2 +- .../skilltree/Endorsement/EndorsementServiceImpl.java | 10 ++++------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementController.java b/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementController.java index cc873a3c..7b154118 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementController.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementController.java @@ -82,7 +82,7 @@ public ResponseEntity> postEndorsement( @PatchMapping(value = "/{id}") public ResponseEntity> 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)); } } diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementService.java b/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementService.java index 0ce9c796..a7254a48 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementService.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementService.java @@ -17,5 +17,5 @@ Page getEndorsementsFromDummyData( EndorsementModel createEndorsement(EndorsementDRO endorsementDRO); - GenericResponse updateEndorsementStatus(String id, String status); + GenericResponse updateEndorsementStatus(UUID id, String status); } diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementServiceImpl.java b/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementServiceImpl.java index 4455325d..965155cf 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementServiceImpl.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementServiceImpl.java @@ -136,7 +136,7 @@ public EndorsementModel createEndorsement(EndorsementDRO endorsementDRO) { } @Override - public GenericResponse updateEndorsementStatus(String id, String status) { + public GenericResponse updateEndorsementStatus(UUID id, String status) { UserModel user = (UserModel) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (!user.getRole().equals(UserRole.SUPERUSER)) { @@ -146,13 +146,11 @@ public GenericResponse 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 optionalEndorsementModel = - endorsementRepository.findById(endorsementId); + Optional optionalEndorsementModel = endorsementRepository.findById(id); if (optionalEndorsementModel.isPresent()) { EndorsementModel updatedEndorsementModel = EndorsementModel.builder()