Skip to content

Commit

Permalink
[Feat] 외박일정 수정 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
nahyeon99 committed Jul 15, 2023
1 parent 2f63882 commit e69a003
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class TeamCalendarController {
private final TeamService teamService;
private final CalendarService calendarService;

@ApiOperation(value = "[팀] 일정 생성")
@ApiOperation(value = "[팀] 일정 생성", notes = "- targets 필드는 회원 식별자 배열을 주세요")
@ApiResponses(value = {
@ApiResponse(
responseCode = "201",
Expand Down Expand Up @@ -99,14 +99,14 @@ public ResponseEntity<DefaultResponseDto<Object>> createTeamCalender(
);
}

@ApiOperation(value = "[외박] 일정 생성")
@ApiOperation(value = "[외박] 일정 생성", notes = "- 외박일정은 본인의 것만 생성 가능합니다.")
@ApiResponses(value = {
@ApiResponse(
responseCode = "201",
description = "SLEEPOVER_CALENDAR_CREATED",
content = @Content(schema = @Schema(implementation = TeamCalendarDefaultResponseDto.class))),
@ApiResponse(responseCode = "400",
description = "ILLEGAL_STATEMENT_EXPLODEDTEAM"),
description = "ILLEGAL_STATEMENT_EXPLODEDTEAM / DATE_SET_INVALID / DATE_SET_REQUIRED"),
@ApiResponse(responseCode = "404",
description = "MEMBER_NOT_FOUND / TEAM_NOT_FOUND"),
@ApiResponse(responseCode = "500",
Expand All @@ -124,6 +124,7 @@ public ResponseEntity<DefaultResponseDto<Object>> createSleepoverCalender(
Team team = teamService.findByMember(member);

teamService.validateIsDeletedTeam(team);
calendarService.validateStartAndEndDate(request.getStartDate(), request.getEndDate());

TeamCalendar teamCalendar = teamCalendarService.save(request.toEntity(team, member.getId()));

Expand All @@ -143,7 +144,56 @@ public ResponseEntity<DefaultResponseDto<Object>> createSleepoverCalender(
);
}

@ApiOperation(value = "[팀] 일정 수정", notes = "- 외박 일정은 수정이 불가합니다.")
@ApiOperation(value = "[외박] 일정 수정", notes = "- 본인의 외박일정만 수정 가능합니다.")
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "SLEEPOVER_CALENDAR_UPDATED",
content = @Content(schema = @Schema(implementation = TeamCalendarDefaultResponseDto.class))),
@ApiResponse(responseCode = "400",
description = "ILLEGAL_STATEMENT_EXPLODEDTEAM / TEAMCALENDARID_FIELD_REQUIRED / " +
"TEAMCALENDARID_NEGATIVEORZERO_INVALID / DATE_SET_INVALID / DATE_SET_REQUIRED"),
@ApiResponse(responseCode = "403",
description = "FORBIDDEN_SLEEPOVERCALENDAR_AUTHORIZATION"),
@ApiResponse(responseCode = "404",
description = "MEMBER_NOT_FOUND / TEAM_NOT_FOUND / TEAMCALENDAR_NOT_FOUND"),
@ApiResponse(responseCode = "500",
description = "SERVER_ERROR")
})
@PutMapping("/api/v1/member/team/calendar/sleepover")
public ResponseEntity<DefaultResponseDto<Object>> updateSleepoverCalender(
HttpServletRequest servletRequest,
@RequestBody @Valid SleepoverCalendarUpdateRequestDto request
) {

long memberId = Long.parseLong(jwtTokenProvider.getUsername(servletRequest.getHeader("X-AUTH-TOKEN")));
Member member = memberService.findById(memberId);
Team team = teamService.findByMember(member);

teamService.validateIsDeletedTeam(team);
calendarService.validateStartAndEndDate(request.getStartDate(), request.getEndDate());
TeamCalendar teamCalendar = teamCalendarService.findById(request.getTeamCalendarId());
teamCalendarService.validateSleepoverCalendarAuthorization(teamCalendar, member);

teamCalendarService.updateDates(teamCalendar, request);

TeamMemberFindResponseDto childResponse = new TeamMemberFindResponseDto(member);

TeamCalendarDefaultResponseDto response = TeamCalendarDefaultResponseDto.builder()
.teamCalendar(teamCalendar)
.targets(new ArrayList<>(Arrays.asList(childResponse)))
.build();

return ResponseEntity.status(200)
.body(DefaultResponseDto.builder()
.responseCode("SLEEPOVER_CALENDAR_UPDATED")
.responseMessage("외박 일정 수정 완료")
.data(response)
.build()
);
}

@ApiOperation(value = "[팀] 일정 수정", notes = "- targets 필드는 회원 식별자 배열을 주세요")
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
Expand Down Expand Up @@ -200,7 +250,8 @@ public ResponseEntity<DefaultResponseDto<Object>> updateTeamCalender(
);
}

@ApiOperation(value = "[팀 / 외박] 일정 삭제")
@ApiOperation(value = "[팀 / 외박] 일정 삭제", notes = "- 팀일정은 팀에 소속된 회원이라면 누구나 삭제 가능합니다.\n" +
"- 외박 일정은 본인의 것만 삭제 가능합니다.")
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package idorm.idormServer.calendar.domain;

import idorm.idormServer.calendar.dto.TeamCalendar.SleepoverCalendarUpdateRequestDto;
import idorm.idormServer.calendar.dto.TeamCalendar.TeamCalendarUpdateRequestDto;
import idorm.idormServer.common.BaseEntity;
import lombok.AccessLevel;
Expand Down Expand Up @@ -81,6 +82,11 @@ public void updateContents(TeamCalendarUpdateRequestDto request, List<Long> targ
this.updateTargets(targets);
}

public void updateDates(SleepoverCalendarUpdateRequestDto request) {
this.startDate = request.getStartDate();
this.endDate = request.getEndDate();
}

private void updateTargets(List<Long> newTargets) {
this.targets.clear();
for (Long target : newTargets)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package idorm.idormServer.calendar.dto.TeamCalendar;

import com.fasterxml.jackson.annotation.JsonFormat;
import idorm.idormServer.common.ValidationSequence;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.validation.GroupSequence;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Positive;
import java.time.LocalDate;

@Getter
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@GroupSequence({
SleepoverCalendarUpdateRequestDto.class,
ValidationSequence.NotNull.class
})
@ApiModel(value = "외박일정 수정 요청")
public class SleepoverCalendarUpdateRequestDto {

@ApiModelProperty(position = 1, required = true, value= "팀 일정 식별자", example = "1")
@NotNull(message = "내용을 입력해 주세요.", groups = ValidationSequence.NotNull.class)
@Positive(message = "수정할 팀 일정 식별자는 양수만 가능합니다.")
private Long teamCalendarId;

@ApiModelProperty(position = 2, notes = "string", value = "시작일자", example = "2023-04-27")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private LocalDate startDate;

@ApiModelProperty(position = 3, notes = "string", value = "종료일자", example = "2023-04-28")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private LocalDate endDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import idorm.idormServer.calendar.domain.Team;
import idorm.idormServer.calendar.domain.TeamCalendar;
import idorm.idormServer.calendar.dto.TeamCalendar.SleepoverCalendarUpdateRequestDto;
import idorm.idormServer.calendar.dto.TeamCalendar.TeamCalendarUpdateRequestDto;
import idorm.idormServer.calendar.repository.TeamCalendarRepository;
import idorm.idormServer.exception.CustomException;
Expand Down Expand Up @@ -42,6 +43,7 @@ public TeamCalendar save(TeamCalendar teamCalendar) {

/**
* 팀일정 수정 |
* 500(SERVER_ERROR)
*/
@Transactional
public void update(TeamCalendar teamCalendar,
Expand All @@ -54,6 +56,19 @@ public void update(TeamCalendar teamCalendar,
}
}

/**
* 외박일정 수정 |
* 500(SERVER_ERROR)
*/
@Transactional
public void updateDates(TeamCalendar teamCalendar, SleepoverCalendarUpdateRequestDto request) {
try {
teamCalendar.updateDates(request);
} catch (RuntimeException e) {
throw new CustomException(e, SERVER_ERROR);
}
}

/**
* 팀일정 삭제 |
* 500(SERVER_ERROR)
Expand Down Expand Up @@ -215,7 +230,7 @@ public void validateSleepoverCalendar(TeamCalendar teamCalendar) {
}

/**
* 외박일정 삭제 권한 검증 |
* 외박일정 수정/삭제 권한 검증 |
* 403(FORBIDDEN_SLEEPOVERCALENDAR_AUTHORIZATION)
*/
public void validateSleepoverCalendarAuthorization(TeamCalendar teamCalendar, Member member) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public enum ExceptionCode {

ILLEGAL_ARGUMENT_ADMIN(BAD_REQUEST, "관리자는 해당 요청의 설정 대상이 될 수 없습니다."),
ILLEGAL_ARGUMENT_SELF(BAD_REQUEST, "본인은 해당 요청의 설정 대상이 될 수 없습니다."),
ILLEGAL_ARGUMENT_SLEEPOVERCALENDAR(BAD_REQUEST, "외박 일정은 수정할 수 없습니다."),
ILLEGAL_ARGUMENT_SLEEPOVERCALENDAR(BAD_REQUEST, "해당 요청으로 외박 일정은 수정할 수 없습니다."),

ILLEGAL_STATEMENT_MATCHINGINFO_NON_PUBLIC(BAD_REQUEST, "매칭정보가 비공개 입니다."),
ILLEGAL_STATEMENT_EXPLODEDTEAM(CONFLICT, "폭발한 팀은 요청 대상이 될 수 없습니다."),
Expand Down

0 comments on commit e69a003

Please sign in to comment.