-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create approve/reject endorsement (#116)
* feat: Create updateEndorsementStatus API * feat: Implement role restrictions in updateEndorsementStatus API * feat: improve logic for updateEndorsementStatus API * fix: switch to InsufficientAuthenticationException (401, Unauthorized) if user in not superuser * chore: update return message for updateEndorsementStatus * temp: validate endorsementId for updateEndorsementStatus UUID.fromString does not throw exception in case of "1-1-1-1-1". Hence temporarily validating it until #109 is merged. * chore: update switch to string.equals() to compare endorsement status * chore: update exceptions for update-endorsement-status * fix: switch to AccessDeniedException to handle Unauthorized * chore: move isValidUUID out of UUIDValidationInterceptor * fix: remove unnecessary RuntimeException * chore: update api-contracts * fix: match endorsementId with the DB * chore: handle endorsement status already updated case and handle invalid status * fix: remove unnecessary validations * fix: simply endorsement status check AS we are checking for invalid status via `EndorsementStatus.fromString()` we can simply condition to check for `PENDING` status * fix: api-contracts
- Loading branch information
Showing
7 changed files
with
151 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 19 additions & 1 deletion
20
skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
package com.RDS.skilltree.Endorsement; | ||
|
||
import com.RDS.skilltree.Exceptions.InvalidParameterException; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public enum EndorsementStatus { | ||
APPROVED, | ||
PENDING, | ||
REJECTED | ||
REJECTED; | ||
|
||
private static final Map<String, EndorsementStatus> endorsementStatusMap = | ||
Stream.of(values()) | ||
.collect(Collectors.toMap(EndorsementStatus::toString, Function.identity())); | ||
|
||
public static EndorsementStatus fromString(final String name) { | ||
EndorsementStatus endorsementStatus = endorsementStatusMap.get(name); | ||
if (endorsementStatus == null) { | ||
throw new InvalidParameterException("endorsement status", name); | ||
} | ||
return endorsementStatus; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
skill-tree/src/main/java/com/RDS/skilltree/utils/CommonUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.RDS.skilltree.utils; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public class CommonUtils { | ||
private static final Pattern UUID_REGEX = | ||
Pattern.compile( | ||
"^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); | ||
|
||
public static boolean isValidUUID(String uuidString) { | ||
|
||
return UUID_REGEX.matcher(uuidString).matches(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters