From eb3268fb27f9e2ea05dc68a70737157aa818cce9 Mon Sep 17 00:00:00 2001 From: nahyeon99 Date: Sat, 19 Aug 2023 15:46:50 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20=EB=8B=B9=EC=9D=BC=20=EC=99=B8?= =?UTF-8?q?=EB=B0=95=20=EC=97=AC=EB=B6=80=20=EC=9D=91=EB=8B=B5=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calendar/controller/TeamController.java | 27 +++++++------ .../dto/Team/TeamMemberFullResponseDto.java | 39 +++++++++++++++++++ ...ava => TeamMemberManyFullResponseDto.java} | 12 +++--- .../repository/TeamCalendarRepository.java | 10 +++++ .../calendar/service/TeamCalendarService.java | 18 ++++++++- .../config/SwaggerConfiguration.java | 6 +-- 6 files changed, 92 insertions(+), 20 deletions(-) create mode 100644 src/main/java/idorm/idormServer/calendar/dto/Team/TeamMemberFullResponseDto.java rename src/main/java/idorm/idormServer/calendar/dto/Team/{TeamMemberFindManyResponseDto.java => TeamMemberManyFullResponseDto.java} (74%) diff --git a/src/main/java/idorm/idormServer/calendar/controller/TeamController.java b/src/main/java/idorm/idormServer/calendar/controller/TeamController.java index ccbc683e..3f5809f5 100644 --- a/src/main/java/idorm/idormServer/calendar/controller/TeamController.java +++ b/src/main/java/idorm/idormServer/calendar/controller/TeamController.java @@ -2,9 +2,10 @@ import idorm.idormServer.auth.JwtTokenProvider; import idorm.idormServer.calendar.domain.Team; -import idorm.idormServer.calendar.dto.Team.TeamMemberFindManyResponseDto; -import idorm.idormServer.calendar.dto.Team.TeamMemberFindResponseDto; +import idorm.idormServer.calendar.dto.Team.TeamMemberFullResponseDto; +import idorm.idormServer.calendar.dto.Team.TeamMemberManyFullResponseDto; import idorm.idormServer.calendar.service.CalendarServiceFacade; +import idorm.idormServer.calendar.service.TeamCalendarService; import idorm.idormServer.calendar.service.TeamService; import idorm.idormServer.common.DefaultResponseDto; import idorm.idormServer.member.domain.Member; @@ -41,6 +42,7 @@ public class TeamController { private final MemberService memberService; private final TeamService teamService; private final CalendarServiceFacade calendarServiceFacade; + private final TeamCalendarService teamCalendarService; @ApiOperation(value = "룸메이트 초대 수락", notes = "- 초대를 보낼 때가 아닌, 초대를 수락할 때 요청을 보내주세요.") @ApiResponses(value = { @@ -141,7 +143,7 @@ public ResponseEntity> deleteTeamMember( @ApiResponse( responseCode = "200", description = "TEAM_MEMBERS_FOUND", - content = @Content(schema = @Schema(implementation = TeamMemberFindManyResponseDto.class))), + content = @Content(schema = @Schema(implementation = TeamMemberManyFullResponseDto.class))), @ApiResponse(responseCode = "404", description = "MEMBER_NOT_FOUND"), @ApiResponse(responseCode = "500", @@ -155,26 +157,29 @@ public ResponseEntity> findTeamMembers( Member member = memberService.findById(memberId); Team team = teamService.findByMemberOptional(member); - TeamMemberFindManyResponseDto responses = null; + TeamMemberManyFullResponseDto responses = null; if (team == null) { - responses = new TeamMemberFindManyResponseDto(-999L, + responses = new TeamMemberManyFullResponseDto(-999L, false, - new ArrayList<>(Arrays.asList(new TeamMemberFindResponseDto(member)))); + new ArrayList<>(Arrays.asList(new TeamMemberFullResponseDto(member, null)))); } else { List members = teamService.findTeamMembers(team); if (members.size() < 2) { teamService.updateIsNeedToConfirmDeleted(team); - responses = new TeamMemberFindManyResponseDto(team.getId(), + responses = new TeamMemberManyFullResponseDto(team.getId(), true, - new ArrayList<>(Arrays.asList(new TeamMemberFindResponseDto(member)))); + new ArrayList<>(Arrays.asList(new TeamMemberFullResponseDto(member, null)))); } else { - List childResponses = members.stream() - .map(m -> new TeamMemberFindResponseDto(m)).collect(Collectors.toList()); + List sleepoverMembers = teamCalendarService.findSleepoverYnByTeam(team); - responses = new TeamMemberFindManyResponseDto(team.getId(), + List childResponses = members.stream() + .map(m -> new TeamMemberFullResponseDto(m, sleepoverMembers.contains(m.getId()))) + .collect(Collectors.toList()); + + responses = new TeamMemberManyFullResponseDto(team.getId(), false, childResponses); } diff --git a/src/main/java/idorm/idormServer/calendar/dto/Team/TeamMemberFullResponseDto.java b/src/main/java/idorm/idormServer/calendar/dto/Team/TeamMemberFullResponseDto.java new file mode 100644 index 00000000..ee7fcf1b --- /dev/null +++ b/src/main/java/idorm/idormServer/calendar/dto/Team/TeamMemberFullResponseDto.java @@ -0,0 +1,39 @@ +package idorm.idormServer.calendar.dto.Team; + +import idorm.idormServer.member.domain.Member; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.*; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@ApiModel(value = "팀 회원 조회 응답 - 당일 외박 여부 포함") +public class TeamMemberFullResponseDto { + + @ApiModelProperty(position = 1, required = true, value= "회원 등록 순서", example = "1") + private int order; + + @ApiModelProperty(position = 2, required = true, value= "회원 식별자", example = "10") + private Long memberId; + + @ApiModelProperty(position = 3, required = true, value = "닉네임", example = "도미") + private String nickname; + + @ApiModelProperty(position = 4, value = "프로필사진 주소", example = "사진 url") + private String profilePhotoUrl; + + @ApiModelProperty(position = 5, value = "당일 외박 여부", example = "false") + private Boolean sleepoverYn; + + @Builder + public TeamMemberFullResponseDto(Member member, Boolean sleepoverYn) { + this.order = member.getTeamOrder(); + this.memberId = member.getId(); + this.nickname = member.getNickname(); + this.sleepoverYn = sleepoverYn; + + if (member.getMemberPhoto() != null) + this.profilePhotoUrl = member.getMemberPhoto().getPhotoUrl(); + } +} diff --git a/src/main/java/idorm/idormServer/calendar/dto/Team/TeamMemberFindManyResponseDto.java b/src/main/java/idorm/idormServer/calendar/dto/Team/TeamMemberManyFullResponseDto.java similarity index 74% rename from src/main/java/idorm/idormServer/calendar/dto/Team/TeamMemberFindManyResponseDto.java rename to src/main/java/idorm/idormServer/calendar/dto/Team/TeamMemberManyFullResponseDto.java index be1bb670..bbfee9a5 100644 --- a/src/main/java/idorm/idormServer/calendar/dto/Team/TeamMemberFindManyResponseDto.java +++ b/src/main/java/idorm/idormServer/calendar/dto/Team/TeamMemberManyFullResponseDto.java @@ -3,6 +3,7 @@ import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -12,8 +13,8 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -@ApiModel(value = "팀 회원 다건 조회 응답") -public class TeamMemberFindManyResponseDto { +@ApiModel(value = "팀 회원 다건 조회 응답 - 당일 외박 여부 포함") +public class TeamMemberManyFullResponseDto { @ApiModelProperty(position = 1, required = true, value= "팀 식별자", example = "1") private Long teamId; @@ -22,11 +23,12 @@ public class TeamMemberFindManyResponseDto { private Boolean isNeedToConfirmDeleted; @ApiModelProperty(position = 3, required = true, value= "팀 회원들") - private List members = new ArrayList<>(); + private List members = new ArrayList<>(); - public TeamMemberFindManyResponseDto(Long teamId, + @Builder + public TeamMemberManyFullResponseDto(Long teamId, Boolean isNeedToConfirmDeleted, - List members) { + List members) { this.teamId = teamId; this.isNeedToConfirmDeleted = isNeedToConfirmDeleted; diff --git a/src/main/java/idorm/idormServer/calendar/repository/TeamCalendarRepository.java b/src/main/java/idorm/idormServer/calendar/repository/TeamCalendarRepository.java index 1e8a9938..bca9e5b7 100644 --- a/src/main/java/idorm/idormServer/calendar/repository/TeamCalendarRepository.java +++ b/src/main/java/idorm/idormServer/calendar/repository/TeamCalendarRepository.java @@ -32,4 +32,14 @@ public interface TeamCalendarRepository extends JpaRepository findTeamCalendarsByDate(Long teamId, String startDate, String endDate); + + @Query(value = "SELECT * " + + "FROM team_calendar c " + + "WHERE c.is_deleted = 0 " + + "AND c.team_id = :teamId " + + "AND c.is_sleepover = 1 " + + "AND (str_to_date(c.start_date, '%Y-%m-%d') <= str_to_date(DATE_ADD(NOW(), INTERVAL 9 HOUR), '%Y-%m-%d') " + + "AND str_to_date(DATE_ADD(NOW(), INTERVAL 9 HOUR), '%Y-%m-%d') <= str_to_date(c.end_date, '%Y-%m-%d'));" + , nativeQuery = true) + List findTodaySleepoverMembersByTeam(Long teamId); } diff --git a/src/main/java/idorm/idormServer/calendar/service/TeamCalendarService.java b/src/main/java/idorm/idormServer/calendar/service/TeamCalendarService.java index 45c73374..124aea06 100644 --- a/src/main/java/idorm/idormServer/calendar/service/TeamCalendarService.java +++ b/src/main/java/idorm/idormServer/calendar/service/TeamCalendarService.java @@ -13,7 +13,6 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; -import java.time.Month; import java.time.YearMonth; import java.time.format.DateTimeFormatter; import java.util.ArrayList; @@ -164,6 +163,23 @@ public TeamCalendar findById(Long teamCalendarId) { }); } + /** + * 팀으로 당일 외박 일정 여부 조회 | + * 500(SERVER_ERROR) + */ + public List findSleepoverYnByTeam(Team team) { + try { + List todaySleepoverTeamCalendars = + teamCalendarRepository.findTodaySleepoverMembersByTeam(team.getId()); + + List members = new ArrayList<>(); + todaySleepoverTeamCalendars.forEach(teamCalendar -> members.add(teamCalendar.getTargets().get(0))); + + return members; + } catch (RuntimeException e) { + throw new CustomException(e, SERVER_ERROR); + } + } /** * 팀일정 대상자의 팀 존재 여부 검증 | diff --git a/src/main/java/idorm/idormServer/config/SwaggerConfiguration.java b/src/main/java/idorm/idormServer/config/SwaggerConfiguration.java index 0c6cee2e..d0d8102f 100644 --- a/src/main/java/idorm/idormServer/config/SwaggerConfiguration.java +++ b/src/main/java/idorm/idormServer/config/SwaggerConfiguration.java @@ -3,8 +3,8 @@ import com.fasterxml.classmate.TypeResolver; import idorm.idormServer.calendar.dto.Calendar.CalendarAdminResponseDto; import idorm.idormServer.calendar.dto.Calendar.CalendarDefaultResponseDto; -import idorm.idormServer.calendar.dto.Team.TeamMemberFindManyResponseDto; import idorm.idormServer.calendar.dto.Team.TeamMemberFindResponseDto; +import idorm.idormServer.calendar.dto.Team.TeamMemberManyFullResponseDto; import idorm.idormServer.calendar.dto.TeamCalendar.SleepoverCalendarAbstractResponseDto; import idorm.idormServer.calendar.dto.TeamCalendar.TeamCalendarAbstractResponseDto; import idorm.idormServer.calendar.dto.TeamCalendar.TeamCalendarDefaultResponseDto; @@ -51,11 +51,11 @@ public Docket api() { typeResolver.resolve(CommentParentResponseDto.class), typeResolver.resolve(CalendarDefaultResponseDto.class), typeResolver.resolve(CalendarAdminResponseDto.class), - typeResolver.resolve(TeamMemberFindManyResponseDto.class), typeResolver.resolve(TeamMemberFindResponseDto.class), typeResolver.resolve(TeamCalendarDefaultResponseDto.class), typeResolver.resolve(TeamCalendarAbstractResponseDto.class), - typeResolver.resolve(SleepoverCalendarAbstractResponseDto.class) + typeResolver.resolve(SleepoverCalendarAbstractResponseDto.class), + typeResolver.resolve(TeamMemberManyFullResponseDto.class) ) .useDefaultResponseMessages(false) .select()