Skip to content

Commit

Permalink
change EndorsementViewModel to use builder pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
yesyash committed Jul 28, 2024
1 parent a84862a commit 9812d40
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 41 deletions.
8 changes: 0 additions & 8 deletions skill-tree/src/main/java/com/RDS/skilltree/models/Skill.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,9 @@ public class Skill extends TrackedProperties {
@Enumerated(value = EnumType.STRING)
private SkillTypeEnum type = SkillTypeEnum.ATOMIC;

// @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;

@Column(name = "updated_by")
private String updateBy;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import com.RDS.skilltree.repositories.SkillRepository;
import com.RDS.skilltree.repositories.UserSkillRepository;
import com.RDS.skilltree.services.external.RdsService;
import com.RDS.skilltree.viewmodels.*;
import com.RDS.skilltree.viewmodels.CreateEndorsementViewModel;
import com.RDS.skilltree.viewmodels.EndorsementViewModel;
import com.RDS.skilltree.viewmodels.UpdateEndorsementViewModel;
import com.RDS.skilltree.viewmodels.UserViewModel;
import java.util.*;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
Expand All @@ -31,10 +34,6 @@ public class EndorsementServiceImplementation implements EndorsementService {

@Override
public List<EndorsementViewModel> getAllEndorsementsBySkillId(Integer skillId) {
// endorsements.forEach(endorsement -> {
// RdsGetUserDetailsResDto userDetails = rdsService.getUserDetails(endorsement.)
// });

List<Endorsement> endorsements = endorsementRepository.findBySkillId(skillId);

// store all users data that are a part of this request
Expand All @@ -57,15 +56,8 @@ public List<EndorsementViewModel> getAllEndorsementsBySkillId(Integer skillId) {
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());
return EndorsementViewModel.toViewModel(
endorsement, userDetails.get(endorseId), userDetails.get(endorserId));
})
.toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ public SkillRequestsDto getAllRequests() {

endorsements.forEach(
endorsement -> {
// String endorserId =
// endorsement.getEndorser().getId();
// String endorserRdsUserId =
// endorsement.getEndorser().getId();

String endorserId = endorsement.getEndorserId();

if (!userDetails.containsKey(endorserId)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.RDS.skilltree.viewmodels;

import com.RDS.skilltree.models.Endorsement;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
@Builder
public class EndorsementViewModel {
private Integer id;
private SkillViewModel skill;
Expand All @@ -17,18 +17,13 @@ public class EndorsementViewModel {

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);

return new EndorsementViewModel(
endorsement.getId(),
SkillViewModel.toViewModel(endorsement.getSkill()),
endorse,
endorser,
endorsement.getMessage());
return EndorsementViewModel.builder()
.id(endorsement.getId())
.skill(SkillViewModel.toViewModel((endorsement.getSkill())))
.endorse(endorse)
.endorser(endorser)
.message(endorsement.getMessage())
.build();
}
}

0 comments on commit 9812d40

Please sign in to comment.