Skip to content

Commit

Permalink
[Refactoring] stream 사용량 줄이기 및 안쓰는 인자 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
AreSain committed Jul 22, 2024
1 parent 52bb557 commit 6e7a99f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,29 @@ public ResponseEntity<Void> leaveAgendaTeam(@Parameter(hidden = true) @Login Use

/**
* 아젠다 팀 공개 모집인 팀 목록 조회
* @param user 사용자 정보, PageRequestDto 페이지네이션 요청 정보, agendaId 아젠다 아이디
* @param pageRequest 페이지네이션 요청 정보, agendaId 아젠다 아이디
*/
@GetMapping("/open")
public ResponseEntity<List<OpenTeamResDto>> openTeamList(@Parameter(hidden = true) @Login UserDto user,
@RequestBody @Valid PageRequestDto pageRequest, @RequestParam("agenda_key") UUID agendaKey) {
public ResponseEntity<List<OpenTeamResDto>> openTeamList(@RequestBody @Valid PageRequestDto pageRequest,
@RequestParam("agenda_key") UUID agendaKey) {
int page = pageRequest.getPage();
int size = pageRequest.getSize();
Pageable pageable = PageRequest.of(page - 1, size, Sort.by("id").descending());
List<OpenTeamResDto> openTeamResDtoList = agendaTeamService.listOpenTeam(user, agendaKey, pageable);
List<OpenTeamResDto> openTeamResDtoList = agendaTeamService.listOpenTeam(agendaKey, pageable);
return ResponseEntity.ok(openTeamResDtoList);
}

/**
* 아젠다 팀 확정된 팀 목록 조회
* @param user 사용자 정보, PageRequestDto 페이지네이션 요청 정보, agendaId 아젠다 아이디
* @param pageRequest 페이지네이션 요청 정보, agendaId 아젠다 아이디
*/
@GetMapping("/confirm")
public ResponseEntity<List<ConfirmTeamResDto>> confirmTeamList(@Parameter(hidden = true) @Login UserDto user,
@RequestBody @Valid PageRequestDto pageRequest, @RequestParam("agenda_key") UUID agendaKey) {
public ResponseEntity<List<ConfirmTeamResDto>> confirmTeamList(@RequestBody @Valid PageRequestDto pageRequest,
@RequestParam("agenda_key") UUID agendaKey) {
int page = pageRequest.getPage();
int size = pageRequest.getSize();
Pageable pageable = PageRequest.of(page - 1, size, Sort.by("id").descending());
List<ConfirmTeamResDto> confirmTeamResDto = agendaTeamService.listConfirmTeam(user, agendaKey, pageable);
List<ConfirmTeamResDto> confirmTeamResDto = agendaTeamService.listConfirmTeam(agendaKey, pageable);
return ResponseEntity.ok(confirmTeamResDto);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package gg.agenda.api.user.agendateam.controller.response;

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

import gg.data.agenda.AgendaProfile;
import gg.data.agenda.AgendaTeam;
import gg.data.agenda.type.Coalition;
import lombok.Getter;
Expand All @@ -17,16 +15,14 @@ public class ConfirmTeamResDto {
private int teamMateCount;
private String teamAward;
private int awardPriority;
private Coalition[] coalition;
private List<Coalition> coalitions;

public ConfirmTeamResDto(AgendaTeam agendaTeam, List<AgendaProfile> agendaProfiles) {
public ConfirmTeamResDto(AgendaTeam agendaTeam, List<Coalition> coalitions) {
this.teamName = agendaTeam.getName();
this.teamLeaderIntraId = agendaTeam.getLeaderIntraId();
this.teamMateCount = agendaTeam.getMateCount();
this.teamAward = agendaTeam.getAward();
this.awardPriority = agendaTeam.getAwardPriority();
this.coalition = agendaProfiles.stream()
.map(AgendaProfile::getCoalition)
.collect(Collectors.toList()).toArray(new Coalition[0]);
this.coalitions = coalitions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ public List<AgendaProfile> agendaTeamProfileLeave(UserDto user, AgendaTeam agend

/**
* 아젠다 팀 공개 모집인 팀 목록 조회
* @param user 사용자 정보, PageRequestDto 페이지네이션 요청 정보, agendaId 아젠다 아이디
* @param pageable 페이지네이션 요청 정보, agendaId 아젠다 아이디
*/
public List<OpenTeamResDto> listOpenTeam(UserDto user, UUID agendaKey, Pageable pageable) {
public List<OpenTeamResDto> listOpenTeam(UUID agendaKey, Pageable pageable) {
Agenda agenda = agendaRepository.findByAgendaKey(agendaKey)
.orElseThrow(() -> new NotExistException(AGENDA_NOT_FOUND));

Expand All @@ -240,20 +240,22 @@ public List<OpenTeamResDto> listOpenTeam(UserDto user, UUID agendaKey, Pageable

/**
* 아젠다 팀 확정된 팀 목록 조회
* @param user 사용자 정보, PageRequestDto 페이지네이션 요청 정보, agendaId 아젠다 아이디
* @param pageable 페이지네이션 요청 정보, agendaId 아젠다 아이디
*/
public List<ConfirmTeamResDto> listConfirmTeam(UserDto user, UUID agendaKey, Pageable pageable) {
public List<ConfirmTeamResDto> listConfirmTeam(UUID agendaKey, Pageable pageable) {
Agenda agenda = agendaRepository.findByAgendaKey(agendaKey)
.orElseThrow(() -> new NotExistException(AGENDA_NOT_FOUND));

List<AgendaTeam> agendaTeams = agendaTeamRepository.findByAgendaAndStatus(agenda, CONFIRM, pageable)
.getContent();
return agendaTeams.stream().map(agendaTeam -> {
List<AgendaTeamProfile> agendaTeamProfiles = agendaTeamProfileRepository.findByAgendaTeamAndIsExistTrue(
agendaTeam);
return new ConfirmTeamResDto(agendaTeam, agendaTeamProfiles.stream()
.map(AgendaTeamProfile::getProfile)
.collect(Collectors.toList()));
}).collect(Collectors.toList());
return agendaTeams.stream()
.map(agendaTeam -> {
List<Coalition> coalitions = agendaTeamProfileRepository
.findByAgendaTeamAndIsExistTrue(agendaTeam).stream()
.map(agendaTeamProfile -> agendaTeamProfile.getProfile().getCoalition())
.collect(Collectors.toList());
return new ConfirmTeamResDto(agendaTeam, coalitions);
})
.collect(Collectors.toList());
}
}

0 comments on commit 6e7a99f

Please sign in to comment.