Skip to content

Commit

Permalink
apply spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
yesyash committed Jul 13, 2024
1 parent 6e33319 commit 93211a8
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import com.RDS.skilltree.models.Skill;
import com.fasterxml.jackson.annotation.JsonBackReference;
import jakarta.persistence.*;
import lombok.*;

import java.util.UUID;
import lombok.*;

@Entity
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,7 +41,8 @@ public ResponseEntity<SkillViewModel> create(@Valid @RequestBody CreateSkillView
}

@GetMapping("/{id}/endorsements")
public ResponseEntity<List<EndorsementViewModel>> getEndorsementsBySkillId(@PathVariable(value = "id") Integer skillID) {
public ResponseEntity<List<EndorsementViewModel>> getEndorsementsBySkillId(
@PathVariable(value = "id") Integer skillID) {
return ResponseEntity.ok(endorsementService.getAllEndorsementsBySkillId(skillID));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

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 {
private List<SkillRequestViewModel> data;
private List<UserViewModel> users;

public static SkillRequestsDto toDto(List<SkillRequestViewModel> skillRequests, List<UserViewModel> users) {
public static SkillRequestsDto toDto(
List<SkillRequestViewModel> skillRequests, List<UserViewModel> users) {
SkillRequestsDto skillRequestsDto = new SkillRequestsDto();
skillRequestsDto.setData(skillRequests);
skillRequestsDto.setUsers(users);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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);

// Page<Endorsement> findBySkillIdPaginated(Integer skillId, Pageable pageable);
// Page<Endorsement> findBySkillIdPaginated(Integer skillId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import com.RDS.skilltree.User.UserSkillStatusEnum;
import com.RDS.skilltree.User.UserSkillsModel;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserSkillRepository extends JpaRepository<UserSkillsModel, Integer> {
List<UserSkillsModel> findByStatus(UserSkillStatusEnum status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.RDS.skilltree.viewmodels.CreateEndorsementViewModel;
import com.RDS.skilltree.viewmodels.EndorsementViewModel;
import com.RDS.skilltree.viewmodels.UpdateEndorsementViewModel;

import java.util.List;

public interface EndorsementService {
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 Expand Up @@ -67,7 +66,8 @@ public EndorsementViewModel create(CreateEndorsementViewModel endorsementViewMod
throw new SkillNotFoundException(String.format("Skill id: %s not found", skillId));
}

List<UserSkillsModel> userSkillEntry = userSkillRepository.findByUserIdAndSkillId(endorseId, skillId);
List<UserSkillsModel> userSkillEntry =
userSkillRepository.findByUserIdAndSkillId(endorseId, skillId);
Endorsement endorsement = new Endorsement();

endorsement.setMessage(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.RDS.skilltree.dtos.SkillRequestsDto;
import com.RDS.skilltree.viewmodels.CreateSkillViewModel;
import com.RDS.skilltree.viewmodels.SkillViewModel;

import java.util.List;

public interface SkillService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
import com.RDS.skilltree.viewmodels.SkillRequestViewModel;
import com.RDS.skilltree.viewmodels.SkillViewModel;
import com.RDS.skilltree.viewmodels.UserViewModel;
import java.util.*;
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;

import java.util.*;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class SkillServiceImplementation implements SkillService {
Expand All @@ -38,25 +37,32 @@ public List<SkillViewModel> getAll() {

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

List<SkillRequestViewModel> skillRequests = pendingSkills.stream().map(pendingSkill -> {
List<Endorsement> endorsements = endorsementRepository.findBySkillId(pendingSkill.getSkill().getId());

uniqueUsers.add(
// TODO : call rds backend to get user details
UserViewModel.toViewModel(new UserModel(pendingSkill.getUser().getId(), ""))
);

endorsements.forEach(endorsement -> {
UserModel endorser = endorsement.getEndorser();
// TODO : call rds backend to get user details
uniqueUsers.add(UserViewModel.toViewModel(new UserModel(endorser.getId(), "")));
});

return SkillRequestViewModel.toViewModel(pendingSkill, endorsements);
}).toList();
List<SkillRequestViewModel> skillRequests =
pendingSkills.stream()
.map(
pendingSkill -> {
List<Endorsement> endorsements =
endorsementRepository.findBySkillId(pendingSkill.getSkill().getId());

uniqueUsers.add(
// TODO : call rds backend to get user details
UserViewModel.toViewModel(new UserModel(pendingSkill.getUser().getId(), "")));

endorsements.forEach(
endorsement -> {
UserModel endorser = endorsement.getEndorser();
// TODO : call rds backend to get user details
uniqueUsers.add(
UserViewModel.toViewModel(new UserModel(endorser.getId(), "")));
});

return SkillRequestViewModel.toViewModel(pendingSkill, endorsements);
})
.toList();

return SkillRequestsDto.toDto(skillRequests, new ArrayList<>(uniqueUsers));
}
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 All @@ -18,17 +17,20 @@ public class SkillRequestViewModel {
private String endorseId;
private List<MinimalEndorsementViewModel> endorsements;

public static SkillRequestViewModel toViewModel(UserSkillsModel userSkillsModel, List<Endorsement> endorsements) {
public static SkillRequestViewModel toViewModel(
UserSkillsModel userSkillsModel, List<Endorsement> endorsements) {
SkillRequestViewModel skillRequestViewModel = new SkillRequestViewModel();

Skill skill = userSkillsModel.getSkill();
UserModel user = userSkillsModel.getUser();


skillRequestViewModel.setId(skill.getId());
skillRequestViewModel.setName(skill.getName());
skillRequestViewModel.setEndorseId(user.getId());
skillRequestViewModel.setEndorsements(endorsements.stream().map(MinimalEndorsementViewModel::toViewModel).collect(Collectors.toList()));
skillRequestViewModel.setEndorsements(
endorsements.stream()
.map(MinimalEndorsementViewModel::toViewModel)
.collect(Collectors.toList()));

return skillRequestViewModel;
}
Expand Down

0 comments on commit 93211a8

Please sign in to comment.