From d57cb71a4fcf63f3e0ab08aefe488ec3302887ea Mon Sep 17 00:00:00 2001 From: Ga Dong Sik <62535229+eple0329@users.noreply.github.com> Date: Sun, 18 Aug 2024 17:48:27 +0900 Subject: [PATCH] =?UTF-8?q?[COZY-187]=20refacor:=20Role=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20=ED=98=95=EC=8B=9D=EC=97=90=20Persona=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/role/converter/RoleConverter.java | 15 +++++++++++++-- .../domain/role/dto/RoleResponseDto.java | 15 +++++++++++++-- .../domain/role/service/RoleQueryService.java | 17 +++++++++++++---- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/cozymate/cozymate_server/domain/role/converter/RoleConverter.java b/src/main/java/com/cozymate/cozymate_server/domain/role/converter/RoleConverter.java index cf9e14fa..d5e8f57e 100644 --- a/src/main/java/com/cozymate/cozymate_server/domain/role/converter/RoleConverter.java +++ b/src/main/java/com/cozymate/cozymate_server/domain/role/converter/RoleConverter.java @@ -4,6 +4,7 @@ import com.cozymate.cozymate_server.domain.role.Role; import com.cozymate.cozymate_server.domain.role.dto.RoleResponseDto.RoleDetailResponseDto; import com.cozymate.cozymate_server.domain.role.dto.RoleResponseDto.RoleListDetailResponseDto; +import com.cozymate.cozymate_server.domain.role.dto.RoleResponseDto.RoleMateDetailResponseDto; import com.cozymate.cozymate_server.domain.role.enums.DayListBitmask; import java.util.ArrayList; import java.util.List; @@ -54,9 +55,19 @@ public static RoleDetailResponseDto toRoleDetailResponseDto(Role role) { .build(); } + public static RoleMateDetailResponseDto toRoleMateDetailResponseDto( + int persona, + List mateRoleList) { + return RoleMateDetailResponseDto.builder() + .persona(persona) + .mateRoleList(mateRoleList) + .build(); + } + + public static RoleListDetailResponseDto toRoleListDetailResponseDto( - List myRoleList, - Map> otherRoleList) { + RoleMateDetailResponseDto myRoleList, + Map otherRoleList) { return RoleListDetailResponseDto.builder() .myRoleList(myRoleList) .otherRoleList(otherRoleList) diff --git a/src/main/java/com/cozymate/cozymate_server/domain/role/dto/RoleResponseDto.java b/src/main/java/com/cozymate/cozymate_server/domain/role/dto/RoleResponseDto.java index c53ee59a..b96f690e 100644 --- a/src/main/java/com/cozymate/cozymate_server/domain/role/dto/RoleResponseDto.java +++ b/src/main/java/com/cozymate/cozymate_server/domain/role/dto/RoleResponseDto.java @@ -26,15 +26,26 @@ public static class RoleDetailResponseDto { } + @Builder + @Getter + @AllArgsConstructor + @NoArgsConstructor + public static class RoleMateDetailResponseDto { + + private int persona; + + private List mateRoleList; + } + @Builder @Getter @AllArgsConstructor @NoArgsConstructor public static class RoleListDetailResponseDto { - private List myRoleList; + private RoleMateDetailResponseDto myRoleList; - private Map> otherRoleList; + private Map otherRoleList; } } diff --git a/src/main/java/com/cozymate/cozymate_server/domain/role/service/RoleQueryService.java b/src/main/java/com/cozymate/cozymate_server/domain/role/service/RoleQueryService.java index c8374d98..6bbb9329 100644 --- a/src/main/java/com/cozymate/cozymate_server/domain/role/service/RoleQueryService.java +++ b/src/main/java/com/cozymate/cozymate_server/domain/role/service/RoleQueryService.java @@ -7,6 +7,7 @@ import com.cozymate.cozymate_server.domain.role.converter.RoleConverter; import com.cozymate.cozymate_server.domain.role.dto.RoleResponseDto.RoleDetailResponseDto; import com.cozymate.cozymate_server.domain.role.dto.RoleResponseDto.RoleListDetailResponseDto; +import com.cozymate.cozymate_server.domain.role.dto.RoleResponseDto.RoleMateDetailResponseDto; import com.cozymate.cozymate_server.domain.role.repository.RoleRepository; import com.cozymate.cozymate_server.domain.rule.converter.RuleConverter; import com.cozymate.cozymate_server.domain.rule.dto.RuleResponseDto.RuleDetailResponseDto; @@ -33,16 +34,24 @@ public RoleListDetailResponseDto getRole(Long roomId, Member member) { .orElseThrow(() -> new GeneralException(ErrorStatus._MATE_OR_ROOM_NOT_FOUND)); List roleList = roleRepository.findAllByMateRoomId(mate.getRoom().getId()); - List myRoleListResponseDto = new ArrayList<>(); - Map> mateRoleListResponseDto = new HashMap<>(); + RoleMateDetailResponseDto myRoleListResponseDto = RoleConverter.toRoleMateDetailResponseDto( + mate.getMember().getPersona(), new ArrayList<>()); + Map mateRoleListResponseDto = new HashMap<>(); roleList.forEach(role -> { if (role.getMate().getId().equals(mate.getId())) { - myRoleListResponseDto.add(RoleConverter.toRoleDetailResponseDto(role)); + myRoleListResponseDto.getMateRoleList() + .add(RoleConverter.toRoleDetailResponseDto(role)); } else { String mateName = role.getMate().getMember().getName(); RoleDetailResponseDto roleDto = RoleConverter.toRoleDetailResponseDto(role); - mateRoleListResponseDto.computeIfAbsent(mateName, k -> new ArrayList<>()) + + mateRoleListResponseDto.computeIfAbsent(mateName, k -> + RoleConverter.toRoleMateDetailResponseDto( + role.getMate().getMember().getPersona(), + new ArrayList<>() + )) + .getMateRoleList() .add(roleDto); } });