diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Authentication/UserAuthenticationToken.java b/skill-tree/src/main/java/com/RDS/skilltree/Authentication/UserAuthenticationToken.java index dc798d0..7780b9b 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/Authentication/UserAuthenticationToken.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/Authentication/UserAuthenticationToken.java @@ -2,12 +2,11 @@ import com.RDS.skilltree.enums.UserRoleEnum; import com.RDS.skilltree.models.JwtUser; +import java.util.List; +import javax.security.auth.Subject; import org.springframework.security.authentication.AbstractAuthenticationToken; import org.springframework.security.core.authority.SimpleGrantedAuthority; -import javax.security.auth.Subject; -import java.util.List; - public class UserAuthenticationToken extends AbstractAuthenticationToken { private final JwtUser user; diff --git a/skill-tree/src/main/java/com/RDS/skilltree/annotations/AuthorizedRoles.java b/skill-tree/src/main/java/com/RDS/skilltree/annotations/AuthorizedRoles.java index dae0601..c788b99 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/annotations/AuthorizedRoles.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/annotations/AuthorizedRoles.java @@ -1,7 +1,6 @@ package com.RDS.skilltree.annotations; import com.RDS.skilltree.enums.UserRoleEnum; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/skill-tree/src/main/java/com/RDS/skilltree/apis/SkillsApi.java b/skill-tree/src/main/java/com/RDS/skilltree/apis/SkillsApi.java index 961833d..8259e35 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/apis/SkillsApi.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/apis/SkillsApi.java @@ -9,13 +9,12 @@ import com.RDS.skilltree.viewmodels.EndorsementViewModel; import com.RDS.skilltree.viewmodels.SkillViewModel; import jakarta.validation.Valid; +import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.util.List; - @Slf4j @RestController @RequiredArgsConstructor diff --git a/skill-tree/src/main/java/com/RDS/skilltree/aspects/AuthorizedRolesAspect.java b/skill-tree/src/main/java/com/RDS/skilltree/aspects/AuthorizedRolesAspect.java index 4e880ca..6505c3c 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/aspects/AuthorizedRolesAspect.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/aspects/AuthorizedRolesAspect.java @@ -4,6 +4,7 @@ import com.RDS.skilltree.enums.UserRoleEnum; import com.RDS.skilltree.exceptions.ForbiddenException; import com.RDS.skilltree.models.JwtUser; +import java.lang.reflect.Method; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; @@ -11,8 +12,6 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Component; -import java.lang.reflect.Method; - @Aspect @Component public class AuthorizedRolesAspect { diff --git a/skill-tree/src/main/java/com/RDS/skilltree/config/SecurityConfig.java b/skill-tree/src/main/java/com/RDS/skilltree/config/SecurityConfig.java index fb77183..520aff3 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/config/SecurityConfig.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/config/SecurityConfig.java @@ -4,6 +4,8 @@ import com.RDS.skilltree.Authentication.CustomAccessDeniedHandler; import com.RDS.skilltree.enums.UserRoleEnum; import com.RDS.skilltree.utils.JWTAuthenticationFilter; +import java.util.Arrays; +import java.util.List; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpHeaders; @@ -18,9 +20,6 @@ import org.springframework.web.cors.CorsConfigurationSource; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import java.util.Arrays; -import java.util.List; - @EnableWebSecurity @Configuration public class SecurityConfig { diff --git a/skill-tree/src/main/java/com/RDS/skilltree/models/Skill.java b/skill-tree/src/main/java/com/RDS/skilltree/models/Skill.java index 0ecfdfc..19e04ff 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/models/Skill.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/models/Skill.java @@ -25,16 +25,16 @@ public class Skill extends TrackedProperties { @Enumerated(value = EnumType.STRING) private SkillTypeEnum type = SkillTypeEnum.ATOMIC; -// @ManyToOne -// @JoinColumn(name = "created_by", nullable = false) -// private RdsUserViewModel createdBy; + // @ManyToOne + // @JoinColumn(name = "created_by", nullable = false) + // private RdsUserViewModel createdBy; @Column(name = "created_by", nullable = false) private String createdBy; -// @ManyToOne -// @JoinColumn(name = "updated_by") -// private RdsUserViewModel updatedBy; + // @ManyToOne + // @JoinColumn(name = "updated_by") + // private RdsUserViewModel updatedBy; @Column(name = "updated_by") private String updateBy; diff --git a/skill-tree/src/main/java/com/RDS/skilltree/repositories/UserSkillRepository.java b/skill-tree/src/main/java/com/RDS/skilltree/repositories/UserSkillRepository.java index 9f55c09..5dd821e 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/repositories/UserSkillRepository.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/repositories/UserSkillRepository.java @@ -2,9 +2,8 @@ import com.RDS.skilltree.enums.UserSkillStatusEnum; import com.RDS.skilltree.models.UserSkills; -import org.springframework.data.jpa.repository.JpaRepository; - import java.util.List; +import org.springframework.data.jpa.repository.JpaRepository; public interface UserSkillRepository extends JpaRepository { List findByStatus(UserSkillStatusEnum status); diff --git a/skill-tree/src/main/java/com/RDS/skilltree/services/EndorsementServiceImplementation.java b/skill-tree/src/main/java/com/RDS/skilltree/services/EndorsementServiceImplementation.java index 3c7d02a..f3456ef 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/services/EndorsementServiceImplementation.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/services/EndorsementServiceImplementation.java @@ -13,14 +13,13 @@ import com.RDS.skilltree.repositories.UserSkillRepository; import com.RDS.skilltree.services.external.RdsService; import com.RDS.skilltree.viewmodels.*; +import java.util.*; import lombok.RequiredArgsConstructor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; -import java.util.*; - @Service @RequiredArgsConstructor public class EndorsementServiceImplementation implements EndorsementService { @@ -32,39 +31,43 @@ public class EndorsementServiceImplementation implements EndorsementService { @Override public List getAllEndorsementsBySkillId(Integer skillId) { -// endorsements.forEach(endorsement -> { -// RdsGetUserDetailsResDto userDetails = rdsService.getUserDetails(endorsement.) -// }); + // endorsements.forEach(endorsement -> { + // RdsGetUserDetailsResDto userDetails = rdsService.getUserDetails(endorsement.) + // }); List endorsements = endorsementRepository.findBySkillId(skillId); // store all users data that are a part of this request Map userDetails = new HashMap<>(); - return endorsements.stream().map(endorsement -> { - String endorseId = endorsement.getEndorseId(); - String endorserId = endorsement.getEndorserId(); - - if (!userDetails.containsKey(endorseId)) { - RdsGetUserDetailsResDto endorseDetails = rdsService.getUserDetails(endorsement.getEndorseId()); - userDetails.put(endorseId, UserViewModel.toViewModel(endorseDetails.getUser())); - } - - if (!userDetails.containsKey(endorserId)) { - RdsGetUserDetailsResDto endorserDetails = rdsService.getUserDetails(endorserId); - userDetails.put(endorserId, UserViewModel.toViewModel(endorserDetails.getUser())); - } - - UserViewModel endorseDetails = userDetails.get(endorseId); - UserViewModel endorserDetails = userDetails.get(endorserId); - - return new EndorsementViewModel( - endorsement.getId(), - SkillViewModel.toViewModel(endorsement.getSkill()), - endorseDetails, endorserDetails, - endorsement.getMessage() - ); - }).toList(); + return endorsements.stream() + .map( + endorsement -> { + String endorseId = endorsement.getEndorseId(); + String endorserId = endorsement.getEndorserId(); + + if (!userDetails.containsKey(endorseId)) { + RdsGetUserDetailsResDto endorseDetails = + rdsService.getUserDetails(endorsement.getEndorseId()); + userDetails.put(endorseId, UserViewModel.toViewModel(endorseDetails.getUser())); + } + + if (!userDetails.containsKey(endorserId)) { + RdsGetUserDetailsResDto endorserDetails = rdsService.getUserDetails(endorserId); + userDetails.put(endorserId, UserViewModel.toViewModel(endorserDetails.getUser())); + } + + UserViewModel endorseDetails = userDetails.get(endorseId); + UserViewModel endorserDetails = userDetails.get(endorserId); + + return new EndorsementViewModel( + endorsement.getId(), + SkillViewModel.toViewModel(endorsement.getSkill()), + endorseDetails, + endorserDetails, + endorsement.getMessage()); + }) + .toList(); } @Override @@ -79,9 +82,9 @@ public EndorsementViewModel create(CreateEndorsementViewModel endorsementViewMod String endorserId = jwtDetails.getRdsUserId(); - if (Objects.equals(endorseId, endorserId)) { - log.error("Self endorsement nto allowed, endorseId: {}, endorserId: {}", endorseId, endorserId); + log.error( + "Self endorsement nto allowed, endorseId: {}, endorserId: {}", endorseId, endorserId); throw new SelfEndorsementNotAllowedException("Self endorsement not allowed"); } @@ -99,20 +102,19 @@ public EndorsementViewModel create(CreateEndorsementViewModel endorsementViewMod List userSkillEntry = userSkillRepository.findByUserIdAndSkillId(endorseId, skillId); - Endorsement endorsement = Endorsement.builder() - .skill(skillDetails.get()) - .message(message) - .endorseId(endorseId) - .endorserId(endorserId) - .build(); + Endorsement endorsement = + Endorsement.builder() + .skill(skillDetails.get()) + .message(message) + .endorseId(endorseId) + .endorserId(endorserId) + .build(); // If a skill request is not created then create one // This is because there is no specific api to create a skill request at the time of writing if (userSkillEntry.isEmpty()) { - UserSkills userSkills = UserSkills.builder() - .userId(endorseId) - .skill(skillDetails.get()) - .build(); + UserSkills userSkills = + UserSkills.builder().userId(endorseId).skill(skillDetails.get()).build(); userSkillRepository.save(userSkills); } @@ -122,8 +124,7 @@ public EndorsementViewModel create(CreateEndorsementViewModel endorsementViewMod return EndorsementViewModel.toViewModel( newEndorsement, UserViewModel.toViewModel(endorseDetails.getUser()), - UserViewModel.toViewModel(endorserDetails.getUser()) - ); + UserViewModel.toViewModel(endorserDetails.getUser())); } @Override @@ -143,13 +144,14 @@ public EndorsementViewModel update(Integer endorsementId, UpdateEndorsementViewM } Endorsement savedEndorsementDetails = endorsementRepository.save(endorsement); - RdsGetUserDetailsResDto endorseDetails = rdsService.getUserDetails(savedEndorsementDetails.getEndorseId()); - RdsGetUserDetailsResDto endorserDetails = rdsService.getUserDetails(savedEndorsementDetails.getEndorserId()); + RdsGetUserDetailsResDto endorseDetails = + rdsService.getUserDetails(savedEndorsementDetails.getEndorseId()); + RdsGetUserDetailsResDto endorserDetails = + rdsService.getUserDetails(savedEndorsementDetails.getEndorserId()); return EndorsementViewModel.toViewModel( savedEndorsementDetails, UserViewModel.toViewModel(endorseDetails.getUser()), - UserViewModel.toViewModel(endorserDetails.getUser()) - ); + UserViewModel.toViewModel(endorserDetails.getUser())); } } diff --git a/skill-tree/src/main/java/com/RDS/skilltree/services/SkillServiceImplementation.java b/skill-tree/src/main/java/com/RDS/skilltree/services/SkillServiceImplementation.java index 4b263ef..439f612 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/services/SkillServiceImplementation.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/services/SkillServiceImplementation.java @@ -16,15 +16,14 @@ import com.RDS.skilltree.viewmodels.SkillRequestViewModel; import com.RDS.skilltree.viewmodels.SkillViewModel; import com.RDS.skilltree.viewmodels.UserViewModel; -import lombok.RequiredArgsConstructor; -import org.springframework.beans.BeanUtils; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Service; - import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.BeanUtils; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Service; @Service @RequiredArgsConstructor @@ -43,8 +42,7 @@ public List getAll() { @Override public SkillRequestsDto getAllRequests() { - List pendingSkills = - userSkillRepository.findByStatus(UserSkillStatusEnum.PENDING); + List pendingSkills = userSkillRepository.findByStatus(UserSkillStatusEnum.PENDING); // store all users data that are a part of this request Map userDetails = new HashMap<>(); @@ -72,8 +70,10 @@ public SkillRequestsDto getAllRequests() { endorsements.forEach( endorsement -> { -// String endorserId = endorsement.getEndorser().getId(); -// String endorserRdsUserId = endorsement.getEndorser().getId(); + // String endorserId = + // endorsement.getEndorser().getId(); + // String endorserRdsUserId = + // endorsement.getEndorser().getId(); String endorserId = endorsement.getEndorserId(); @@ -93,12 +93,13 @@ public SkillRequestsDto getAllRequests() { return SkillRequestsDto.toDto(skillRequests, userDetails.values().stream().toList()); } - private static UserViewModel getUserModalFromRdsDetails(String id, RdsGetUserDetailsResDto rdsDetails) { + private static UserViewModel getUserModalFromRdsDetails( + String id, RdsGetUserDetailsResDto rdsDetails) { String firstName = rdsDetails.getUser().getFirst_name() != null ? rdsDetails.getUser().getFirst_name() : ""; String lastName = rdsDetails.getUser().getLast_name() != null ? rdsDetails.getUser().getLast_name() : ""; - + return UserViewModel.builder().id(id).name(firstName + ' ' + lastName).build(); } diff --git a/skill-tree/src/main/java/com/RDS/skilltree/viewmodels/EndorsementViewModel.java b/skill-tree/src/main/java/com/RDS/skilltree/viewmodels/EndorsementViewModel.java index d9b050a..35eabe8 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/viewmodels/EndorsementViewModel.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/viewmodels/EndorsementViewModel.java @@ -15,20 +15,20 @@ public class EndorsementViewModel { private UserViewModel endorser; private String message; - public static EndorsementViewModel toViewModel(Endorsement endorsement, UserViewModel endorse, UserViewModel endorser) { -// EndorsementViewModel viewModel = new EndorsementViewModel(); -// BeanUtils.copyProperties(endorsement, viewModel); + public static EndorsementViewModel toViewModel( + Endorsement endorsement, UserViewModel endorse, UserViewModel endorser) { + // EndorsementViewModel viewModel = new EndorsementViewModel(); + // BeanUtils.copyProperties(endorsement, viewModel); -// viewModel.setSkill(SkillViewModel.toViewModel(endorsement.getSkill())); -// viewModel.setEndorse(endorse); -// viewModel.setEndorser(endorser); + // viewModel.setSkill(SkillViewModel.toViewModel(endorsement.getSkill())); + // viewModel.setEndorse(endorse); + // viewModel.setEndorser(endorser); return new EndorsementViewModel( endorsement.getId(), SkillViewModel.toViewModel(endorsement.getSkill()), endorse, endorser, - endorsement.getMessage() - ); + endorsement.getMessage()); } } diff --git a/skill-tree/src/main/java/com/RDS/skilltree/viewmodels/MinimalEndorsementViewModel.java b/skill-tree/src/main/java/com/RDS/skilltree/viewmodels/MinimalEndorsementViewModel.java index 5cda1cd..000b1ab 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/viewmodels/MinimalEndorsementViewModel.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/viewmodels/MinimalEndorsementViewModel.java @@ -13,12 +13,12 @@ public class MinimalEndorsementViewModel { private String message; public static MinimalEndorsementViewModel toViewModel(Endorsement endorsement) { -// MinimalEndorsementViewModel endorsementViewModel = new MinimalEndorsementViewModel(); + // MinimalEndorsementViewModel endorsementViewModel = new MinimalEndorsementViewModel(); -// endorsementViewModel.setId(endorsement.getId()); -// endorsementViewModel.setMessage(endorsement.getMessage()); -// endorsementViewModel.setEndorsementDate(endorsement.getCreatedAt().toString()); -// endorsementViewModel.setEndorserId(endorsement.getEndorserId()); + // endorsementViewModel.setId(endorsement.getId()); + // endorsementViewModel.setMessage(endorsement.getMessage()); + // endorsementViewModel.setEndorsementDate(endorsement.getCreatedAt().toString()); + // endorsementViewModel.setEndorserId(endorsement.getEndorserId()); return MinimalEndorsementViewModel.builder() .id(endorsement.getId()) diff --git a/skill-tree/src/main/java/com/RDS/skilltree/viewmodels/RdsUserViewModel.java b/skill-tree/src/main/java/com/RDS/skilltree/viewmodels/RdsUserViewModel.java index 851e607..bc8f2b1 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/viewmodels/RdsUserViewModel.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/viewmodels/RdsUserViewModel.java @@ -31,7 +31,6 @@ public class RdsUserViewModel { private long updated_at; private long created_at; - @Getter @Setter public static class Roles { diff --git a/skill-tree/src/main/java/com/RDS/skilltree/viewmodels/SkillRequestViewModel.java b/skill-tree/src/main/java/com/RDS/skilltree/viewmodels/SkillRequestViewModel.java index 2d496b3..87695b9 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/viewmodels/SkillRequestViewModel.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/viewmodels/SkillRequestViewModel.java @@ -3,10 +3,9 @@ import com.RDS.skilltree.models.Endorsement; import com.RDS.skilltree.models.Skill; import com.RDS.skilltree.models.UserSkills; -import lombok.Data; - import java.util.List; import java.util.stream.Collectors; +import lombok.Data; @Data public class SkillRequestViewModel {