-
Notifications
You must be signed in to change notification settings - Fork 24
Dev To Main #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev To Main #209
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,5 +10,6 @@ public interface EndorsementService { | |
|
|
||
| EndorsementViewModel create(CreateEndorsementViewModel endorsement); | ||
|
|
||
| EndorsementViewModel update(Integer endorsementId, UpdateEndorsementViewModel endorsement); | ||
| EndorsementViewModel update( | ||
| Integer endorsementId, UpdateEndorsementViewModel endorsement, boolean isDev); | ||
This comment was marked as resolved.
Sorry, something went wrong.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this repository, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair point. If 'isDev' is the standard feature flag naming in your codebase, keeping it consistent makes sense. I'll resolve this comment. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import com.RDS.skilltree.dtos.RdsGetUserDetailsResDto; | ||
| import com.RDS.skilltree.exceptions.EndorsementAlreadyExistsException; | ||
| import com.RDS.skilltree.exceptions.EndorsementNotFoundException; | ||
| import com.RDS.skilltree.exceptions.ForbiddenException; | ||
| import com.RDS.skilltree.exceptions.SelfEndorsementNotAllowedException; | ||
| import com.RDS.skilltree.exceptions.SkillNotFoundException; | ||
| import com.RDS.skilltree.models.Endorsement; | ||
|
|
@@ -130,30 +131,39 @@ public EndorsementViewModel create(CreateEndorsementViewModel endorsementViewMod | |
| } | ||
|
|
||
| @Override | ||
| public EndorsementViewModel update(Integer endorsementId, UpdateEndorsementViewModel body) { | ||
| Optional<Endorsement> exitingEndorsement = endorsementRepository.findById(endorsementId); | ||
|
|
||
| if (exitingEndorsement.isEmpty()) { | ||
| log.info(String.format("Endorsement with id: %s not found", endorsementId)); | ||
| throw new EndorsementNotFoundException(ExceptionMessages.ENDORSEMENT_NOT_FOUND); | ||
| public EndorsementViewModel update( | ||
| Integer endorsementId, UpdateEndorsementViewModel body, boolean isDev) { | ||
| if (isDev) { | ||
| Optional<Endorsement> existingEndorsement = endorsementRepository.findById(endorsementId); | ||
|
|
||
| if (existingEndorsement.isEmpty()) { | ||
| log.info("Endorsement with id: {} not found", endorsementId); | ||
| throw new EndorsementNotFoundException(ExceptionMessages.ENDORSEMENT_NOT_FOUND); | ||
| } | ||
|
|
||
| Endorsement endorsement = existingEndorsement.get(); | ||
|
|
||
| JwtUser jwtDetails = | ||
| (JwtUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | ||
| String userId = jwtDetails.getRdsUserId(); | ||
|
|
||
| if (endorsement.getEndorserId().equals(userId)) { | ||
| RdsGetUserDetailsResDto endorseDetails = | ||
| rdsService.getUserDetails(endorsement.getEndorseId()); | ||
| RdsGetUserDetailsResDto endorserDetails = rdsService.getUserDetails(userId); | ||
|
|
||
| endorsement.setMessage(body.getMessage()); | ||
| Endorsement savedEndorsementDetails = endorsementRepository.save(endorsement); | ||
|
|
||
| return EndorsementViewModel.toViewModel( | ||
| savedEndorsementDetails, | ||
| UserViewModel.toViewModel(endorseDetails.getUser()), | ||
| UserViewModel.toViewModel(endorserDetails.getUser())); | ||
| } else { | ||
| log.warn("User: {} is not authorized to update endorsement: {}", userId, endorsementId); | ||
| throw new ForbiddenException(ExceptionMessages.UNAUTHORIZED_ENDORSEMENT_UPDATE); | ||
| } | ||
| } | ||
|
|
||
| Endorsement endorsement = exitingEndorsement.get(); | ||
| String updatedMessage = body.getMessage(); | ||
|
|
||
| if (updatedMessage != null) { | ||
| endorsement.setMessage(updatedMessage); | ||
| } | ||
|
|
||
| Endorsement savedEndorsementDetails = endorsementRepository.save(endorsement); | ||
| RdsGetUserDetailsResDto endorseDetails = | ||
| rdsService.getUserDetails(savedEndorsementDetails.getEndorseId()); | ||
| RdsGetUserDetailsResDto endorserDetails = | ||
| rdsService.getUserDetails(savedEndorsementDetails.getEndorserId()); | ||
|
|
||
| return EndorsementViewModel.toViewModel( | ||
| savedEndorsementDetails, | ||
| UserViewModel.toViewModel(endorseDetails.getUser()), | ||
| UserViewModel.toViewModel(endorserDetails.getUser())); | ||
| throw new IllegalStateException(ExceptionMessages.UPDATE_DISABLED_IN_NON_DEV_MODE); | ||
|
Comment on lines
+136
to
+167
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deep Nesting in Update Method
Tell me moreWhat is the issue?The update method has deeply nested logic within an if-statement, making the code flow harder to follow. The dev mode check should be inverted to handle the non-dev case first. Why this mattersDeep nesting reduces code readability and makes it harder to understand the main flow of the method. Early returns improve code clarity by reducing cognitive load. Suggested change ∙ Feature Previewpublic EndorsementViewModel update(Integer endorsementId, UpdateEndorsementViewModel body, boolean isDev) {
if (!isDev) {
throw new IllegalStateException(ExceptionMessages.UPDATE_DISABLED_IN_NON_DEV_MODE);
}
Optional<Endorsement> existingEndorsement = endorsementRepository.findById(endorsementId);
// ... rest of the logic ...
}Provide feedback to improve future suggestions💬 Looking for more details? Reply to this comment to chat with Korbit. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,5 +8,14 @@ public static final class ExceptionMessages { | |
| public static final String SKILL_NOT_FOUND = "Skill does not exist"; | ||
| public static final String ENDORSEMENT_ALREADY_EXISTS = "Endorsement already exists"; | ||
| public static final String ENDORSEMENT_NOT_FOUND = "Endorsement not found"; | ||
| public static final String ENDORSEMENT_MESSAGE_EMPTY = "Endorsement message cannot be empty"; | ||
| public static final String USER_NOT_FOUND = "Error getting user details"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent Error Message for User Not Found Scenario
Tell me moreWhat is the issue?The error message 'Error getting user details' does not accurately reflect the USER_NOT_FOUND constant name and scenario. Why this mattersUsing a generic error message instead of a specific one can make debugging harder and may confuse users about the actual issue - that the user was not found in the system. Suggested change ∙ Feature PreviewChange the message to be consistent with the constant name and specific to the scenario: public static final String USER_NOT_FOUND = "User not found";Provide feedback to improve future suggestions💬 Looking for more details? Reply to this comment to chat with Korbit. |
||
| public static final String UNAUTHORIZED_ENDORSEMENT_UPDATE = | ||
| "Not authorized to update this endorsement"; | ||
| public static final String INVALID_ACCESS_TOKEN = | ||
| "The access token provided is expired, revoked, malformed, or invalid for other reasons."; | ||
| public static final String ACCESS_DENIED = "Access Denied"; | ||
| public static final String UPDATE_DISABLED_IN_NON_DEV_MODE = | ||
| "Update is not allowed outside of development mode"; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,13 @@ | ||
| package com.RDS.skilltree.viewmodels; | ||
|
|
||
| import jakarta.validation.constraints.NotNull; | ||
| import com.RDS.skilltree.utils.Constants.ExceptionMessages; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| public class UpdateEndorsementViewModel { | ||
| @NotNull(message = "Message cannot be empty") | ||
| @NotBlank(message = ExceptionMessages.ENDORSEMENT_MESSAGE_EMPTY) | ||
| private String message; | ||
| } |
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I understand it's used for feature flags, exposing dev flags via API parameters creates security risks. Consider using a proper feature flag management system or environment-based configuration instead. This provides better security and control over feature rollouts.