Skip to content

Commit

Permalink
[Feat] 당일 외박 여부 응답 필드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
nahyeon99 committed Aug 19, 2023
1 parent 747e761 commit eb3268f
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -141,7 +143,7 @@ public ResponseEntity<DefaultResponseDto<Object>> 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",
Expand All @@ -155,26 +157,29 @@ public ResponseEntity<DefaultResponseDto<Object>> 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<Member> 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<TeamMemberFindResponseDto> childResponses = members.stream()
.map(m -> new TeamMemberFindResponseDto(m)).collect(Collectors.toList());
List<Long> sleepoverMembers = teamCalendarService.findSleepoverYnByTeam(team);

responses = new TeamMemberFindManyResponseDto(team.getId(),
List<TeamMemberFullResponseDto> childResponses = members.stream()
.map(m -> new TeamMemberFullResponseDto(m, sleepoverMembers.contains(m.getId())))
.collect(Collectors.toList());

responses = new TeamMemberManyFullResponseDto(team.getId(),
false,
childResponses);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -22,11 +23,12 @@ public class TeamMemberFindManyResponseDto {
private Boolean isNeedToConfirmDeleted;

@ApiModelProperty(position = 3, required = true, value= "팀 회원들")
private List<TeamMemberFindResponseDto> members = new ArrayList<>();
private List<TeamMemberFullResponseDto> members = new ArrayList<>();

public TeamMemberFindManyResponseDto(Long teamId,
@Builder
public TeamMemberManyFullResponseDto(Long teamId,
Boolean isNeedToConfirmDeleted,
List<TeamMemberFindResponseDto> members) {
List<TeamMemberFullResponseDto> members) {
this.teamId = teamId;
this.isNeedToConfirmDeleted = isNeedToConfirmDeleted;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@ public interface TeamCalendarRepository extends JpaRepository<TeamCalendar, Long
"AND :endDate <= str_to_date(c.end_date, '%Y-%m-%d'))) ", nativeQuery = true
)
List<TeamCalendar> 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<TeamCalendar> findTodaySleepoverMembersByTeam(Long teamId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -164,6 +163,23 @@ public TeamCalendar findById(Long teamCalendarId) {
});
}

/**
* 팀으로 당일 외박 일정 여부 조회 |
* 500(SERVER_ERROR)
*/
public List<Long> findSleepoverYnByTeam(Team team) {
try {
List<TeamCalendar> todaySleepoverTeamCalendars =
teamCalendarRepository.findTodaySleepoverMembersByTeam(team.getId());

List<Long> members = new ArrayList<>();
todaySleepoverTeamCalendars.forEach(teamCalendar -> members.add(teamCalendar.getTargets().get(0)));

return members;
} catch (RuntimeException e) {
throw new CustomException(e, SERVER_ERROR);
}
}

/**
* 팀일정 대상자의 팀 존재 여부 검증 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit eb3268f

Please sign in to comment.