Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refac/issue #109 #110

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import com.gdsc_knu.official_homepage.dto.member.TeamInfoResponse;
import com.gdsc_knu.official_homepage.entity.Member;
import com.gdsc_knu.official_homepage.entity.MemberTeam;
import com.gdsc_knu.official_homepage.entity.enumeration.Role;
import com.gdsc_knu.official_homepage.entity.enumeration.Track;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Getter
Expand All @@ -24,8 +22,7 @@ public class AdminMemberResponse {
private String studentNumber;
private String email;
private String phoneNumber;
@Builder.Default
private List<TeamInfoResponse> teams = new ArrayList<>();
private List<TeamInfoResponse> teams;
private Role role;

public static AdminMemberResponse from(Member member) {
Expand All @@ -36,9 +33,8 @@ public static AdminMemberResponse from(Member member) {
.studentNumber(member.getStudentNumber())
.email(member.getEmail())
.phoneNumber(member.getPhoneNumber())
.teams(member.getMemberTeams().stream()
.map(MemberTeam::getTeam)
.map(TeamInfoResponse::new)
.teams(member.getTeams().stream()
.map(TeamInfoResponse::from)
.toList())
.role(member.getRole())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ public TeamInfoResponse(Team team) {
this.id = team.getId();
this.teamName = team.getTeamName();
}

public static TeamInfoResponse from(Team team) {
return TeamInfoResponse.builder()
.id(team.getId())
.teamName(team.getTeamName())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,11 @@ public void addInfo(String name, int age, String major, String studentNumber, St
this.phoneNumber = phoneNumber;
this.role = Role.ROLE_GUEST;
}

public List<Team> getTeams() {
return this.memberTeams.stream()
.map(MemberTeam::getTeam)
.filter(team -> team.getParent()!=null)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.gdsc_knu.official_homepage.dto.member.*;
import com.gdsc_knu.official_homepage.entity.Member;
import com.gdsc_knu.official_homepage.entity.MemberTeam;
import com.gdsc_knu.official_homepage.entity.Team;
import com.gdsc_knu.official_homepage.exception.CustomException;
import com.gdsc_knu.official_homepage.exception.ErrorCode;
import com.gdsc_knu.official_homepage.repository.MemberRepository;
Expand All @@ -12,7 +12,6 @@

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand All @@ -25,12 +24,11 @@ public MemberResponse getMemberInfo(Long id) {
Member member = memberRepository.findById(id)
.orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND));

List<TeamInfoResponse> teamInfos = member.getMemberTeams().stream()
.filter(memberTeam -> memberTeam.getTeam().getParent() != null)
.map(memberTeam -> new TeamInfoResponse(memberTeam.getTeam()))
.collect(Collectors.toList());
List<TeamInfoResponse> teams = member.getTeams().stream()
.map(TeamInfoResponse::from)
.toList();

return new MemberResponse(member,teamInfos);
return new MemberResponse(member,teams);
}

@Transactional
Expand All @@ -54,10 +52,9 @@ public void addMemberInfo(Long id, MemberRequest.Append request) {
public List<TeamInfoResponse> getMemberTeamInfo(Long id) {
return memberRepository.findById(id)
.orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND))
.getMemberTeams().stream()
.filter(memberTeam -> memberTeam.getTeam().getParent() != null)
.sorted(Comparator.comparing(MemberTeam::getId).reversed())
.map(memberTeam -> new TeamInfoResponse(memberTeam.getTeam()))
.collect(Collectors.toList());
.getTeams().stream()
.sorted(Comparator.comparing(Team::getId).reversed())
.map(TeamInfoResponse::from)
.toList();
}
}
Loading