Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
yesyash committed Jul 20, 2024
1 parent 7d2ef70 commit cdbf306
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Endorsement, Integer> {
List<Endorsement> findBySkillId(Integer skillId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,46 +39,59 @@ public List<SkillViewModel> getAll() {

@Override
public SkillRequestsDto getAllRequests() {
List<UserSkillsModel> pendingSkills = userSkillRepository.findByStatus(UserSkillStatusEnum.PENDING);
List<UserSkillsModel> pendingSkills =
userSkillRepository.findByStatus(UserSkillStatusEnum.PENDING);

// store all users data that are a part of this request
Map<String, UserViewModel> userDetails = new HashMap<>();

// make a list of all pending skill requests with their endorsement details
List<SkillRequestViewModel> 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<Endorsement> 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<SkillRequestViewModel> 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<Endorsement> 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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cdbf306

Please sign in to comment.