From cdbf30627bc4375afab00ffb12bc88ae7098ec2d Mon Sep 17 00:00:00 2001 From: yash raj Date: Sun, 21 Jul 2024 00:00:32 +0530 Subject: [PATCH] fix formatting --- .../RDS/skilltree/dtos/SkillRequestsDto.java | 3 +- .../repositories/EndorsementRepository.java | 3 +- .../EndorsementServiceImplementation.java | 5 +- .../services/SkillServiceImplementation.java | 82 +++++++++++-------- .../viewmodels/SkillRequestViewModel.java | 5 +- 5 files changed, 53 insertions(+), 45 deletions(-) diff --git a/skill-tree/src/main/java/com/RDS/skilltree/dtos/SkillRequestsDto.java b/skill-tree/src/main/java/com/RDS/skilltree/dtos/SkillRequestsDto.java index f2aab7a..cbb3f27 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/dtos/SkillRequestsDto.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/dtos/SkillRequestsDto.java @@ -2,11 +2,10 @@ import com.RDS.skilltree.viewmodels.SkillRequestViewModel; import com.RDS.skilltree.viewmodels.UserViewModel; +import java.util.List; import lombok.Data; import lombok.NoArgsConstructor; -import java.util.List; - @Data @NoArgsConstructor public class SkillRequestsDto { diff --git a/skill-tree/src/main/java/com/RDS/skilltree/repositories/EndorsementRepository.java b/skill-tree/src/main/java/com/RDS/skilltree/repositories/EndorsementRepository.java index ad28025..9b8d3c2 100644 --- a/skill-tree/src/main/java/com/RDS/skilltree/repositories/EndorsementRepository.java +++ b/skill-tree/src/main/java/com/RDS/skilltree/repositories/EndorsementRepository.java @@ -1,9 +1,8 @@ package com.RDS.skilltree.repositories; import com.RDS.skilltree.models.Endorsement; -import org.springframework.data.jpa.repository.JpaRepository; - import java.util.List; +import org.springframework.data.jpa.repository.JpaRepository; public interface EndorsementRepository extends JpaRepository { List findBySkillId(Integer skillId); 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 9cec220..008364c 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 @@ -16,12 +16,11 @@ import com.RDS.skilltree.viewmodels.CreateEndorsementViewModel; import com.RDS.skilltree.viewmodels.EndorsementViewModel; import com.RDS.skilltree.viewmodels.UpdateEndorsementViewModel; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - import java.util.List; import java.util.Objects; import java.util.Optional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; @Service @RequiredArgsConstructor 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 86da0c8..8b600dc 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 @@ -11,16 +11,15 @@ import com.RDS.skilltree.repositories.UserSkillRepository; import com.RDS.skilltree.services.external.RdsService; import com.RDS.skilltree.viewmodels.*; -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.Optional; 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 @@ -40,46 +39,59 @@ 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<>(); // make a list of all pending skill requests with their endorsement details - List skillRequests = pendingSkills.stream().map(skill -> { - Integer skillId = skill.getSkill().getId(); - String endorseId = skill.getUser().getId(); - String endorseRdsUserId = skill.getUser().getRdsUserId(); - - // Get all endorsement for a specific skill and user Id - List endorsements = endorsementRepository.findByEndorseIdAndSkillId(endorseId, skillId); - - if (!userDetails.containsKey(endorseId)) { - RdsUserViewModel endorseRdsDetails = rdsService.getUserDetails(endorseRdsUserId); - UserViewModel endorseDetails = getUserModalFromRdsDetails(endorseId, endorseRdsDetails); - userDetails.put(endorseId, endorseDetails); - } - - endorsements.forEach(endorsement -> { - String endorserId = endorsement.getEndorser().getId(); - String endorserRdsUserId = endorsement.getEndorser().getRdsUserId(); - - if (!userDetails.containsKey(endorserId)) { - RdsUserViewModel endorserRdsDetails = rdsService.getUserDetails(endorserRdsUserId); - UserViewModel endorserDetails = getUserModalFromRdsDetails(endorseId, endorserRdsDetails); - userDetails.put(endorserId, endorserDetails); - } - }); - - return SkillRequestViewModel.toViewModel(skill, endorsements); - }).toList(); + List skillRequests = + pendingSkills.stream() + .map( + skill -> { + Integer skillId = skill.getSkill().getId(); + String endorseId = skill.getUser().getId(); + String endorseRdsUserId = skill.getUser().getRdsUserId(); + + // Get all endorsement for a specific skill and user Id + List endorsements = + endorsementRepository.findByEndorseIdAndSkillId(endorseId, skillId); + + if (!userDetails.containsKey(endorseId)) { + RdsUserViewModel endorseRdsDetails = + rdsService.getUserDetails(endorseRdsUserId); + UserViewModel endorseDetails = + getUserModalFromRdsDetails(endorseId, endorseRdsDetails); + userDetails.put(endorseId, endorseDetails); + } + + endorsements.forEach( + endorsement -> { + String endorserId = endorsement.getEndorser().getId(); + String endorserRdsUserId = endorsement.getEndorser().getRdsUserId(); + + if (!userDetails.containsKey(endorserId)) { + RdsUserViewModel endorserRdsDetails = + rdsService.getUserDetails(endorserRdsUserId); + UserViewModel endorserDetails = + getUserModalFromRdsDetails(endorseId, endorserRdsDetails); + userDetails.put(endorserId, endorserDetails); + } + }); + + return SkillRequestViewModel.toViewModel(skill, endorsements); + }) + .toList(); return SkillRequestsDto.toDto(skillRequests, userDetails.values().stream().toList()); } private static UserViewModel getUserModalFromRdsDetails(String id, RdsUserViewModel rdsDetails) { - String firstName = rdsDetails.getUser().getFirst_name() != null ? rdsDetails.getUser().getFirst_name() : ""; - String lastName = rdsDetails.getUser().getLast_name() != null ? rdsDetails.getUser().getLast_name() : ""; + String firstName = + rdsDetails.getUser().getFirst_name() != null ? rdsDetails.getUser().getFirst_name() : ""; + String lastName = + rdsDetails.getUser().getLast_name() != null ? rdsDetails.getUser().getLast_name() : ""; String username = firstName + ' ' + lastName; 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 54f9132..e81a9ed 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 @@ -4,11 +4,10 @@ import com.RDS.skilltree.User.UserSkillsModel; import com.RDS.skilltree.models.Endorsement; import com.RDS.skilltree.models.Skill; -import lombok.Data; -import lombok.NoArgsConstructor; - import java.util.List; import java.util.stream.Collectors; +import lombok.Data; +import lombok.NoArgsConstructor; @Data @NoArgsConstructor