Skip to content

Commit

Permalink
[COZY-187] refacor: Role 반환 형식에 Persona 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
eple0329 authored Aug 18, 2024
1 parent 708dc4d commit d57cb71
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,9 +55,19 @@ public static RoleDetailResponseDto toRoleDetailResponseDto(Role role) {
.build();
}

public static RoleMateDetailResponseDto toRoleMateDetailResponseDto(
int persona,
List<RoleDetailResponseDto> mateRoleList) {
return RoleMateDetailResponseDto.builder()
.persona(persona)
.mateRoleList(mateRoleList)
.build();
}


public static RoleListDetailResponseDto toRoleListDetailResponseDto(
List<RoleDetailResponseDto> myRoleList,
Map<String, List<RoleDetailResponseDto>> otherRoleList) {
RoleMateDetailResponseDto myRoleList,
Map<String, RoleMateDetailResponseDto> otherRoleList) {
return RoleListDetailResponseDto.builder()
.myRoleList(myRoleList)
.otherRoleList(otherRoleList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,26 @@ public static class RoleDetailResponseDto {

}

@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor
public static class RoleMateDetailResponseDto {

private int persona;

private List<RoleDetailResponseDto> mateRoleList;
}

@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor
public static class RoleListDetailResponseDto {

private List<RoleDetailResponseDto> myRoleList;
private RoleMateDetailResponseDto myRoleList;

private Map<String, List<RoleDetailResponseDto>> otherRoleList;
private Map<String, RoleMateDetailResponseDto> otherRoleList;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,16 +34,24 @@ public RoleListDetailResponseDto getRole(Long roomId, Member member) {
.orElseThrow(() -> new GeneralException(ErrorStatus._MATE_OR_ROOM_NOT_FOUND));

List<Role> roleList = roleRepository.findAllByMateRoomId(mate.getRoom().getId());
List<RoleDetailResponseDto> myRoleListResponseDto = new ArrayList<>();
Map<String, List<RoleDetailResponseDto>> mateRoleListResponseDto = new HashMap<>();
RoleMateDetailResponseDto myRoleListResponseDto = RoleConverter.toRoleMateDetailResponseDto(
mate.getMember().getPersona(), new ArrayList<>());
Map<String, RoleMateDetailResponseDto> 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);
}
});
Expand Down

0 comments on commit d57cb71

Please sign in to comment.