From e8926f4f09b5728c0e7e3a66c8b501b237a15cbc Mon Sep 17 00:00:00 2001 From: taehyeon Date: Fri, 27 Dec 2024 18:57:38 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9C=A8=20[Feature]=20=EA=B0=9C=EC=9D=B8?= =?UTF-8?q?=EC=9D=BC=EC=A0=95=20=EC=88=98=EC=A0=95=20API=20DTO=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20#1057?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/PrivateScheduleCreateReqDto.java | 14 ++--- .../request/PrivateScheduleUpdateReqDto.java | 55 +++++++++++++++++++ .../response/PrivateScheduleUpdateResDto.java | 31 +++++++++++ .../service/PrivateScheduleService.java | 5 ++ .../PrivateScheduleControllerTest.java | 4 -- 5 files changed, 96 insertions(+), 13 deletions(-) diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/request/PrivateScheduleCreateReqDto.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/request/PrivateScheduleCreateReqDto.java index 4d58624d8..090680c5c 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/request/PrivateScheduleCreateReqDto.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/request/PrivateScheduleCreateReqDto.java @@ -21,9 +21,6 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) public class PrivateScheduleCreateReqDto { - @NotNull - private DetailClassification classification; - private EventTag eventTag; private JobTag jobTag; @@ -54,11 +51,9 @@ public class PrivateScheduleCreateReqDto { private Long groupId; @Builder - private PrivateScheduleCreateReqDto(DetailClassification classification, EventTag eventTag, JobTag jobTag, - TechTag techTag, String title, String content, String link, - LocalDateTime startTime, LocalDateTime endTime, boolean alarm, Long groupId, + private PrivateScheduleCreateReqDto(EventTag eventTag, JobTag jobTag, TechTag techTag, String title, String content, + String link, LocalDateTime startTime, LocalDateTime endTime, boolean alarm, Long groupId, ScheduleStatus status) { - this.classification = classification; this.eventTag = eventTag; this.jobTag = jobTag; this.techTag = techTag; @@ -74,11 +69,12 @@ private PrivateScheduleCreateReqDto(DetailClassification classification, EventTa public static PublicSchedule toEntity(String intraId, PrivateScheduleCreateReqDto privateScheduleCreateReqDto) { return PublicSchedule.builder() - .classification(privateScheduleCreateReqDto.classification) + .classification(DetailClassification.PRIVATE_SCHEDULE) .eventTag(privateScheduleCreateReqDto.eventTag) .jobTag(privateScheduleCreateReqDto.jobTag) .techTag(privateScheduleCreateReqDto.techTag) - .author(intraId).title(privateScheduleCreateReqDto.title) + .author(intraId) + .title(privateScheduleCreateReqDto.title) .content(privateScheduleCreateReqDto.content) .link(privateScheduleCreateReqDto.link) .startTime(privateScheduleCreateReqDto.startTime) diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/request/PrivateScheduleUpdateReqDto.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/request/PrivateScheduleUpdateReqDto.java index 48d9adf22..89f5bcc6c 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/request/PrivateScheduleUpdateReqDto.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/request/PrivateScheduleUpdateReqDto.java @@ -1,10 +1,65 @@ package gg.calendar.api.user.schedule.privateschedule.controller.request; +import java.time.LocalDateTime; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; + +import gg.data.calendar.type.EventTag; +import gg.data.calendar.type.JobTag; +import gg.data.calendar.type.ScheduleStatus; +import gg.data.calendar.type.TechTag; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Getter @NoArgsConstructor public class PrivateScheduleUpdateReqDto { + private EventTag eventTag; + + private JobTag jobTag; + + private TechTag techTag; + + @NotBlank + @Size(max = 50) + private String title; + + @Size(max = 2000) + private String content; + + private String link; + + private ScheduleStatus status; + + @NotNull + private LocalDateTime startTime; + + @NotNull + private LocalDateTime endTime; + + @NotNull + private boolean alarm; + + @NotNull + private Long groupId; + @Builder + public PrivateScheduleUpdateReqDto(EventTag eventTag, JobTag jobTag, TechTag techTag, String title, String content, + String link, ScheduleStatus status, LocalDateTime startTime, LocalDateTime endTime, boolean alarm, + Long groupId) { + this.eventTag = eventTag; + this.jobTag = jobTag; + this.techTag = techTag; + this.title = title; + this.content = content; + this.link = link; + this.status = status; + this.startTime = startTime; + this.endTime = endTime; + this.alarm = alarm; + this.groupId = groupId; + } } diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/response/PrivateScheduleUpdateResDto.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/response/PrivateScheduleUpdateResDto.java index a16b07671..988e52a5c 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/response/PrivateScheduleUpdateResDto.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/response/PrivateScheduleUpdateResDto.java @@ -1,5 +1,12 @@ package gg.calendar.api.user.schedule.privateschedule.controller.response; +import java.time.LocalDateTime; + +import gg.data.calendar.type.DetailClassification; +import gg.data.calendar.type.EventTag; +import gg.data.calendar.type.JobTag; +import gg.data.calendar.type.ScheduleStatus; +import gg.data.calendar.type.TechTag; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -7,5 +14,29 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class PrivateScheduleUpdateResDto { + private Long id; + + private DetailClassification classification; + + private EventTag eventTag; + + private JobTag jobTag; + + private TechTag techTag; + + private String title; + + private String content; + + private String link; + + private ScheduleStatus status; + + private LocalDateTime startTime; + + private LocalDateTime endTime; + + private boolean alarm; + private Long groupId; } diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.java index f02ab8e0b..fa6ce2d91 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.java @@ -43,6 +43,11 @@ public void createPrivateSchedule(UserDto userDto, PrivateScheduleCreateReqDto p privateScheduleRepository.save(privateSchedule); } + @Transactional + public void updatePrivateSchedule() { + + } + public void validateTimeRange(LocalDateTime startTime, LocalDateTime endTime) { if (endTime.isBefore(startTime)) { throw new InvalidParameterException(ErrorCode.CALENDAR_BEFORE_DATE); diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleControllerTest.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleControllerTest.java index fc8861105..ebbad4d6d 100644 --- a/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleControllerTest.java +++ b/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleControllerTest.java @@ -22,7 +22,6 @@ import gg.calendar.api.user.schedule.privateschedule.controller.request.PrivateScheduleCreateReqDto; import gg.data.calendar.PrivateSchedule; import gg.data.calendar.ScheduleGroup; -import gg.data.calendar.type.DetailClassification; import gg.data.calendar.type.EventTag; import gg.data.calendar.type.ScheduleStatus; import gg.data.user.User; @@ -67,7 +66,6 @@ void success() throws Exception { //given ScheduleGroup scheduleGroup = privateScheduleMockData.createScheduleGroup(user); PrivateScheduleCreateReqDto reqDto = PrivateScheduleCreateReqDto.builder() - .classification(DetailClassification.PRIVATE_SCHEDULE) .eventTag(EventTag.ETC) .jobTag(null) .techTag(null) @@ -97,7 +95,6 @@ void success() throws Exception { void noGroup() throws Exception { //given PrivateScheduleCreateReqDto reqDto = PrivateScheduleCreateReqDto.builder() - .classification(DetailClassification.PRIVATE_SCHEDULE) .eventTag(EventTag.ETC) .jobTag(null) .techTag(null) @@ -123,7 +120,6 @@ void noGroup() throws Exception { void endTimeBeforeStartTime() throws Exception { //given PrivateScheduleCreateReqDto reqDto = PrivateScheduleCreateReqDto.builder() - .classification(DetailClassification.PRIVATE_SCHEDULE) .eventTag(EventTag.ETC) .jobTag(null) .techTag(null) From f117591e2d51f9fee728cf1c0d7d6a652853b9f8 Mon Sep 17 00:00:00 2001 From: taehyeon Date: Mon, 30 Dec 2024 15:42:42 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=E2=9C=A8=20[Feature]=20=EA=B0=9C=EC=9D=B8?= =?UTF-8?q?=EC=9D=BC=EC=A0=95=20=EC=88=98=EC=A0=95=20API=20PrivateSchedule?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20#1057?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/PrivateScheduleCreateReqDto.java | 1 + .../request/PrivateScheduleUpdateReqDto.java | 1 + .../response/PrivateScheduleUpdateResDto.java | 44 +++++++++++++++++++ .../service/PrivateScheduleService.java | 19 +++++++- .../gg/data/calendar/PrivateSchedule.java | 14 ++++++ .../java/gg/data/calendar/PublicSchedule.java | 15 +++++++ .../java/gg/utils/dto/PageResponseDto.java | 1 - 7 files changed, 92 insertions(+), 3 deletions(-) diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/request/PrivateScheduleCreateReqDto.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/request/PrivateScheduleCreateReqDto.java index 090680c5c..e655c59a6 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/request/PrivateScheduleCreateReqDto.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/request/PrivateScheduleCreateReqDto.java @@ -36,6 +36,7 @@ public class PrivateScheduleCreateReqDto { private String link; + @NotNull private ScheduleStatus status; @NotNull diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/request/PrivateScheduleUpdateReqDto.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/request/PrivateScheduleUpdateReqDto.java index 89f5bcc6c..fb0622e95 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/request/PrivateScheduleUpdateReqDto.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/request/PrivateScheduleUpdateReqDto.java @@ -32,6 +32,7 @@ public class PrivateScheduleUpdateReqDto { private String link; + @NotNull private ScheduleStatus status; @NotNull diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/response/PrivateScheduleUpdateResDto.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/response/PrivateScheduleUpdateResDto.java index 988e52a5c..1966d7a8a 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/response/PrivateScheduleUpdateResDto.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/response/PrivateScheduleUpdateResDto.java @@ -2,12 +2,14 @@ import java.time.LocalDateTime; +import gg.data.calendar.PrivateSchedule; import gg.data.calendar.type.DetailClassification; import gg.data.calendar.type.EventTag; import gg.data.calendar.type.JobTag; import gg.data.calendar.type.ScheduleStatus; import gg.data.calendar.type.TechTag; import lombok.AccessLevel; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -24,6 +26,8 @@ public class PrivateScheduleUpdateResDto { private TechTag techTag; + private String author; + private String title; private String content; @@ -39,4 +43,44 @@ public class PrivateScheduleUpdateResDto { private boolean alarm; private Long groupId; + + @Builder + private PrivateScheduleUpdateResDto(Long id, DetailClassification classification, EventTag eventTag, JobTag jobTag, + TechTag techTag, String author, String title, String content, String link, ScheduleStatus status, + LocalDateTime startTime, + LocalDateTime endTime, boolean alarm, Long groupId) { + this.id = id; + this.classification = classification; + this.eventTag = eventTag; + this.jobTag = jobTag; + this.techTag = techTag; + this.author = author; + this.title = title; + this.content = content; + this.link = link; + this.status = status; + this.startTime = startTime; + this.endTime = endTime; + this.alarm = alarm; + this.groupId = groupId; + } + + public static PrivateScheduleUpdateResDto toDto(PrivateSchedule privateSchedule) { + return PrivateScheduleUpdateResDto.builder() + .id(privateSchedule.getId()) + .classification(privateSchedule.getPublicSchedule().getClassification()) + .eventTag(privateSchedule.getPublicSchedule().getEventTag()) + .jobTag(privateSchedule.getPublicSchedule().getJobTag()) + .techTag(privateSchedule.getPublicSchedule().getTechTag()) + .author(privateSchedule.getPublicSchedule().getAuthor()) + .title(privateSchedule.getPublicSchedule().getTitle()) + .content(privateSchedule.getPublicSchedule().getContent()) + .link(privateSchedule.getPublicSchedule().getLink()) + .status(privateSchedule.getStatus()) + .startTime(privateSchedule.getPublicSchedule().getStartTime()) + .endTime(privateSchedule.getPublicSchedule().getEndTime()) + .alarm(privateSchedule.isAlarm()) + .groupId(privateSchedule.getGroupId()) + .build(); + } } diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.java index fa6ce2d91..a31b7a1c6 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.java @@ -7,6 +7,8 @@ import gg.auth.UserDto; import gg.calendar.api.user.schedule.privateschedule.controller.request.PrivateScheduleCreateReqDto; +import gg.calendar.api.user.schedule.privateschedule.controller.request.PrivateScheduleUpdateReqDto; +import gg.calendar.api.user.schedule.privateschedule.controller.response.PrivateScheduleUpdateResDto; import gg.data.calendar.PrivateSchedule; import gg.data.calendar.PublicSchedule; import gg.data.calendar.ScheduleGroup; @@ -44,8 +46,21 @@ public void createPrivateSchedule(UserDto userDto, PrivateScheduleCreateReqDto p } @Transactional - public void updatePrivateSchedule() { - + public PrivateScheduleUpdateResDto updatePrivateSchedule(UserDto userDto, + PrivateScheduleUpdateReqDto privateScheduleUpdateReqDto, Long privateScheduleId) { + validateTimeRange(privateScheduleUpdateReqDto.getStartTime(), privateScheduleUpdateReqDto.getEndTime()); + User user = userRepository.getById(userDto.getId()); + PrivateSchedule privateSchedule = privateScheduleRepository.findById(privateScheduleId) + .orElseThrow(() -> new NotExistException(ErrorCode.PRIVATE_SCHEDULE_NOT_FOUND)); + scheduleGroupRepository.findById(privateScheduleUpdateReqDto.getGroupId()) + .orElseThrow(() -> new NotExistException(ErrorCode.SCHEDULE_GROUP_NOT_FOUND)); + privateSchedule.update(privateScheduleUpdateReqDto.getEventTag(), privateScheduleUpdateReqDto.getJobTag(), + privateScheduleUpdateReqDto.getTechTag(), privateScheduleUpdateReqDto.getTitle(), + privateScheduleUpdateReqDto.getContent(), privateScheduleUpdateReqDto.getLink(), + privateScheduleUpdateReqDto.getStatus(), privateScheduleUpdateReqDto.getStartTime(), + privateScheduleUpdateReqDto.getEndTime(), privateScheduleUpdateReqDto.isAlarm(), + privateScheduleUpdateReqDto.getGroupId()); + return PrivateScheduleUpdateResDto.toDto(privateSchedule); } public void validateTimeRange(LocalDateTime startTime, LocalDateTime endTime) { diff --git a/gg-data/src/main/java/gg/data/calendar/PrivateSchedule.java b/gg-data/src/main/java/gg/data/calendar/PrivateSchedule.java index 20661c8db..630077b8e 100644 --- a/gg-data/src/main/java/gg/data/calendar/PrivateSchedule.java +++ b/gg-data/src/main/java/gg/data/calendar/PrivateSchedule.java @@ -1,5 +1,7 @@ package gg.data.calendar; +import java.time.LocalDateTime; + import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EnumType; @@ -12,7 +14,10 @@ import javax.persistence.ManyToOne; import gg.data.BaseTimeEntity; +import gg.data.calendar.type.EventTag; +import gg.data.calendar.type.JobTag; import gg.data.calendar.type.ScheduleStatus; +import gg.data.calendar.type.TechTag; import gg.data.user.User; import lombok.AccessLevel; import lombok.Getter; @@ -51,4 +56,13 @@ public PrivateSchedule(User user, PublicSchedule publicSchedule, boolean alarm, this.groupId = groupId; this.status = ScheduleStatus.ACTIVATE; } + + public void update(EventTag eventTag, JobTag jobTag, TechTag techTag, String title, String content, + String link, ScheduleStatus status, LocalDateTime startTime, LocalDateTime endTime, boolean alarm, + Long groupId) { + this.alarm = alarm; + this.groupId = groupId; + this.publicSchedule.update(publicSchedule.getClassification(), eventTag, jobTag, techTag, title, content, link, + startTime, endTime, status); + } } diff --git a/gg-data/src/main/java/gg/data/calendar/PublicSchedule.java b/gg-data/src/main/java/gg/data/calendar/PublicSchedule.java index 68e40c944..c9c2e20f5 100644 --- a/gg-data/src/main/java/gg/data/calendar/PublicSchedule.java +++ b/gg-data/src/main/java/gg/data/calendar/PublicSchedule.java @@ -85,4 +85,19 @@ private PublicSchedule(DetailClassification classification, EventTag eventTag, J this.startTime = startTime; this.endTime = endTime; } + + public void update(DetailClassification classification, EventTag eventTag, JobTag jobTag, TechTag techTag, + String title, String content, String link, LocalDateTime startTime, LocalDateTime endTime, + ScheduleStatus status) { + this.classification = classification; + this.eventTag = eventTag; + this.jobTag = jobTag; + this.techTag = techTag; + this.title = title; + this.content = content; + this.link = link; + this.startTime = startTime; + this.endTime = endTime; + this.status = status; + } } diff --git a/gg-utils/src/main/java/gg/utils/dto/PageResponseDto.java b/gg-utils/src/main/java/gg/utils/dto/PageResponseDto.java index c8395b339..82972a750 100644 --- a/gg-utils/src/main/java/gg/utils/dto/PageResponseDto.java +++ b/gg-utils/src/main/java/gg/utils/dto/PageResponseDto.java @@ -1,7 +1,6 @@ package gg.utils.dto; import java.util.List; -import java.util.stream.Collectors; import lombok.AccessLevel; import lombok.Builder; From d754767a9067de791c6741ff280d59ba92a53b5b Mon Sep 17 00:00:00 2001 From: taehyeon Date: Mon, 30 Dec 2024 16:21:52 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=E2=9C=A8=20[Feature]=20=EA=B0=9C=EC=9D=B8?= =?UTF-8?q?=EC=9D=BC=EC=A0=95=20=EC=88=98=EC=A0=95=20API=20author=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?#1057?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../privateschedule/service/PrivateScheduleService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.java index a31b7a1c6..ac08e3809 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.java @@ -49,9 +49,9 @@ public void createPrivateSchedule(UserDto userDto, PrivateScheduleCreateReqDto p public PrivateScheduleUpdateResDto updatePrivateSchedule(UserDto userDto, PrivateScheduleUpdateReqDto privateScheduleUpdateReqDto, Long privateScheduleId) { validateTimeRange(privateScheduleUpdateReqDto.getStartTime(), privateScheduleUpdateReqDto.getEndTime()); - User user = userRepository.getById(userDto.getId()); PrivateSchedule privateSchedule = privateScheduleRepository.findById(privateScheduleId) .orElseThrow(() -> new NotExistException(ErrorCode.PRIVATE_SCHEDULE_NOT_FOUND)); + validateAuthor(userDto.getIntraId(), privateSchedule.getPublicSchedule().getAuthor()); scheduleGroupRepository.findById(privateScheduleUpdateReqDto.getGroupId()) .orElseThrow(() -> new NotExistException(ErrorCode.SCHEDULE_GROUP_NOT_FOUND)); privateSchedule.update(privateScheduleUpdateReqDto.getEventTag(), privateScheduleUpdateReqDto.getJobTag(), @@ -68,4 +68,10 @@ public void validateTimeRange(LocalDateTime startTime, LocalDateTime endTime) { throw new InvalidParameterException(ErrorCode.CALENDAR_BEFORE_DATE); } } + + public void validateAuthor(String intraId, String author) { + if (intraId.equals(author)) { + throw new InvalidParameterException(ErrorCode.CALENDAR_AUTHOR_NOT_MATCH); + } + } } From 9351a15f1b084300d448141ebcc096968a140b47 Mon Sep 17 00:00:00 2001 From: taehyeon Date: Mon, 30 Dec 2024 16:27:37 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=E2=9C=A8=20[Feature]=20=EA=B0=9C=EC=9D=B8?= =?UTF-8?q?=EC=9D=BC=EC=A0=95=20=EC=88=98=EC=A0=95=20API=20Controller=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20#1057?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PrivateScheduleController.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleController.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleController.java index 4da3bd1a8..99db490f2 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleController.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleController.java @@ -5,13 +5,17 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import gg.auth.UserDto; import gg.auth.argumentresolver.Login; import gg.calendar.api.user.schedule.privateschedule.controller.request.PrivateScheduleCreateReqDto; +import gg.calendar.api.user.schedule.privateschedule.controller.request.PrivateScheduleUpdateReqDto; +import gg.calendar.api.user.schedule.privateschedule.controller.response.PrivateScheduleUpdateResDto; import gg.calendar.api.user.schedule.privateschedule.service.PrivateScheduleService; import io.swagger.v3.oas.annotations.Parameter; import lombok.RequiredArgsConstructor; @@ -28,4 +32,14 @@ public ResponseEntity privateScheduleCreate(@Login @Parameter(hidden = tru privateScheduleService.createPrivateSchedule(userDto, privateScheduleCreateReqDto); return ResponseEntity.status(HttpStatus.CREATED).build(); } + + @PutMapping("/{id}") + public ResponseEntity privateScheduleUpdate( + @Login @Parameter(hidden = true) UserDto userDto, + @Valid @RequestBody PrivateScheduleUpdateReqDto privateScheduleUpdateReqDto, + @RequestParam Long id) { + PrivateScheduleUpdateResDto privateScheduleUpdateResDto = privateScheduleService.updatePrivateSchedule(userDto, + privateScheduleUpdateReqDto, id); + return ResponseEntity.status(HttpStatus.OK).body(privateScheduleUpdateResDto); + } } From 167e383a881d9ee5ae544cf19139cd84228e7814 Mon Sep 17 00:00:00 2001 From: taehyeon Date: Mon, 30 Dec 2024 18:51:05 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=A7=AA=20[Test]=20=EA=B0=9C=EC=9D=B8?= =?UTF-8?q?=EC=9D=BC=EC=A0=95=20=EC=88=98=EC=A0=95=20API=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80=20#1057?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/PrivateScheduleController.java | 4 +- .../response/PrivateScheduleUpdateResDto.java | 3 +- .../service/PrivateScheduleService.java | 6 +- .../PrivateScheduleMockData.java | 13 +- .../PrivateScheduleControllerTest.java | 147 +++++++++++++++++- .../java/gg/utils/exception/ErrorCode.java | 2 +- 6 files changed, 163 insertions(+), 12 deletions(-) diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleController.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleController.java index 99db490f2..d09da761b 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleController.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleController.java @@ -4,11 +4,11 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import gg.auth.UserDto; @@ -37,7 +37,7 @@ public ResponseEntity privateScheduleCreate(@Login @Parameter(hidden = tru public ResponseEntity privateScheduleUpdate( @Login @Parameter(hidden = true) UserDto userDto, @Valid @RequestBody PrivateScheduleUpdateReqDto privateScheduleUpdateReqDto, - @RequestParam Long id) { + @PathVariable Long id) { PrivateScheduleUpdateResDto privateScheduleUpdateResDto = privateScheduleService.updatePrivateSchedule(userDto, privateScheduleUpdateReqDto, id); return ResponseEntity.status(HttpStatus.OK).body(privateScheduleUpdateResDto); diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/response/PrivateScheduleUpdateResDto.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/response/PrivateScheduleUpdateResDto.java index 1966d7a8a..482ced24a 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/response/PrivateScheduleUpdateResDto.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/controller/response/PrivateScheduleUpdateResDto.java @@ -47,8 +47,7 @@ public class PrivateScheduleUpdateResDto { @Builder private PrivateScheduleUpdateResDto(Long id, DetailClassification classification, EventTag eventTag, JobTag jobTag, TechTag techTag, String author, String title, String content, String link, ScheduleStatus status, - LocalDateTime startTime, - LocalDateTime endTime, boolean alarm, Long groupId) { + LocalDateTime startTime, LocalDateTime endTime, boolean alarm, Long groupId) { this.id = id; this.classification = classification; this.eventTag = eventTag; diff --git a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.java b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.java index ac08e3809..f514ccbbe 100644 --- a/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.java +++ b/gg-calendar-api/src/main/java/gg/calendar/api/user/schedule/privateschedule/service/PrivateScheduleService.java @@ -18,6 +18,7 @@ import gg.repo.calendar.ScheduleGroupRepository; import gg.repo.user.UserRepository; import gg.utils.exception.ErrorCode; +import gg.utils.exception.custom.ForbiddenException; import gg.utils.exception.custom.InvalidParameterException; import gg.utils.exception.custom.NotExistException; import lombok.RequiredArgsConstructor; @@ -54,6 +55,7 @@ public PrivateScheduleUpdateResDto updatePrivateSchedule(UserDto userDto, validateAuthor(userDto.getIntraId(), privateSchedule.getPublicSchedule().getAuthor()); scheduleGroupRepository.findById(privateScheduleUpdateReqDto.getGroupId()) .orElseThrow(() -> new NotExistException(ErrorCode.SCHEDULE_GROUP_NOT_FOUND)); + privateSchedule.update(privateScheduleUpdateReqDto.getEventTag(), privateScheduleUpdateReqDto.getJobTag(), privateScheduleUpdateReqDto.getTechTag(), privateScheduleUpdateReqDto.getTitle(), privateScheduleUpdateReqDto.getContent(), privateScheduleUpdateReqDto.getLink(), @@ -70,8 +72,8 @@ public void validateTimeRange(LocalDateTime startTime, LocalDateTime endTime) { } public void validateAuthor(String intraId, String author) { - if (intraId.equals(author)) { - throw new InvalidParameterException(ErrorCode.CALENDAR_AUTHOR_NOT_MATCH); + if (!intraId.equals(author)) { + throw new ForbiddenException(ErrorCode.CALENDAR_AUTHOR_NOT_MATCH); } } } diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/privateschedule/PrivateScheduleMockData.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/privateschedule/PrivateScheduleMockData.java index 54d34817c..7d95b56e9 100644 --- a/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/privateschedule/PrivateScheduleMockData.java +++ b/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/privateschedule/PrivateScheduleMockData.java @@ -4,11 +4,13 @@ import org.springframework.stereotype.Component; +import gg.data.calendar.PrivateSchedule; import gg.data.calendar.PublicSchedule; import gg.data.calendar.ScheduleGroup; import gg.data.calendar.type.DetailClassification; import gg.data.calendar.type.ScheduleStatus; import gg.data.user.User; +import gg.repo.calendar.PrivateScheduleRepository; import gg.repo.calendar.PublicScheduleRepository; import gg.repo.calendar.ScheduleGroupRepository; import lombok.RequiredArgsConstructor; @@ -18,15 +20,16 @@ public class PrivateScheduleMockData { private final PublicScheduleRepository publicScheduleRepository; private final ScheduleGroupRepository scheduleGroupRepository; + private final PrivateScheduleRepository privateScheduleRepository; - public PublicSchedule createPublicSchedule() { + public PublicSchedule createPublicSchedule(String author) { PublicSchedule publicSchedule = PublicSchedule.builder() .classification(DetailClassification.EVENT) .eventTag(null) .jobTag(null) .techTag(null) .title("Test Schedule") - .author("author") + .author(author) .content("Test Content") .link("http://test.com") .status(ScheduleStatus.ACTIVATE) @@ -44,4 +47,10 @@ public ScheduleGroup createScheduleGroup(User user) { .build(); return scheduleGroupRepository.save(scheduleGroup); } + + public PrivateSchedule createPrivateSchedule(PublicSchedule publicSchedule, ScheduleGroup scheduleGroup) { + PrivateSchedule privateSchedule = new PrivateSchedule(scheduleGroup.getUser(), publicSchedule, false, + scheduleGroup.getId()); + return privateScheduleRepository.save(privateSchedule); + } } diff --git a/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleControllerTest.java b/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleControllerTest.java index ebbad4d6d..5e8513be6 100644 --- a/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleControllerTest.java +++ b/gg-calendar-api/src/test/java/gg/calendar/api/user/schedule/privateschedule/controller/PrivateScheduleControllerTest.java @@ -1,9 +1,11 @@ package gg.calendar.api.user.schedule.privateschedule.controller; +import static org.assertj.core.api.AssertionsForClassTypes.*; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import java.time.LocalDateTime; +import java.util.List; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -20,7 +22,9 @@ import gg.calendar.api.user.schedule.privateschedule.PrivateScheduleMockData; import gg.calendar.api.user.schedule.privateschedule.controller.request.PrivateScheduleCreateReqDto; +import gg.calendar.api.user.schedule.privateschedule.controller.request.PrivateScheduleUpdateReqDto; import gg.data.calendar.PrivateSchedule; +import gg.data.calendar.PublicSchedule; import gg.data.calendar.ScheduleGroup; import gg.data.calendar.type.EventTag; import gg.data.calendar.type.ScheduleStatus; @@ -28,8 +32,9 @@ import gg.repo.calendar.PrivateScheduleRepository; import gg.utils.TestDataUtils; import gg.utils.annotation.IntegrationTest; +import lombok.extern.slf4j.Slf4j; -@Transactional +@Slf4j @IntegrationTest @AutoConfigureMockMvc public class PrivateScheduleControllerTest { @@ -61,6 +66,7 @@ void setUp() { @DisplayName("PrivateSchedule 생성하기") class CreatePrivateSchedule { @Test + @Transactional @DisplayName("성공") void success() throws Exception { //given @@ -75,7 +81,7 @@ void success() throws Exception { .startTime(LocalDateTime.now()) .endTime(LocalDateTime.now().plusDays(1)) .alarm(true) - .groupId(1L) + .groupId(scheduleGroup.getId()) .status(ScheduleStatus.ACTIVATE) .build(); //when @@ -85,12 +91,16 @@ void success() throws Exception { .content(objectMapper.writeValueAsString(reqDto))) .andExpect(status().isCreated()); //then - PrivateSchedule privateSchedule = privateScheduleRepository.findById(1L).orElseThrow(); + + List schedules = privateScheduleRepository.findAll(); + assertThat(schedules.size()).isEqualTo(1); + PrivateSchedule privateSchedule = schedules.get(0); Assertions.assertThat(privateSchedule.getGroupId()).isEqualTo(scheduleGroup.getId()); Assertions.assertThat(privateSchedule.isAlarm()).isEqualTo(reqDto.isAlarm()); } @Test + @Transactional @DisplayName("일정 그룹이 없는 경우 404") void noGroup() throws Exception { //given @@ -116,6 +126,7 @@ void noGroup() throws Exception { } @Test + @Transactional @DisplayName("시작 날짜보다 끝나는 날짜가 빠른 경우 400") void endTimeBeforeStartTime() throws Exception { //given @@ -140,4 +151,134 @@ void endTimeBeforeStartTime() throws Exception { .andExpect(status().isBadRequest()); } } + + @Nested + @DisplayName("PrivateSchedule 수정하기") + class UpdatePrivateSchedule { + @Test + @Transactional + @DisplayName("성공") + void success() throws Exception { + //given + ScheduleGroup scheduleGroup = privateScheduleMockData.createScheduleGroup(user); + PublicSchedule publicSchedule = privateScheduleMockData.createPublicSchedule(user.getIntraId()); + PrivateSchedule privateSchedule = privateScheduleMockData.createPrivateSchedule(publicSchedule, + scheduleGroup); + PrivateScheduleUpdateReqDto reqDto = PrivateScheduleUpdateReqDto.builder() + .eventTag(null) + .techTag(null) + .jobTag(null) + .alarm(false) + .title("123") + .content("") + .link(null) + .status(ScheduleStatus.ACTIVATE) + .startTime(LocalDateTime.now()) + .endTime(LocalDateTime.now().plusDays(1)) + .groupId(scheduleGroup.getId()) + .build(); + //when + mockMvc.perform(put("/calendar/private/" + privateSchedule.getId()) + .header("Authorization", "Bearer " + accessToken) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(reqDto))) + .andExpect(status().isOk()); + //then + PrivateSchedule updated = privateScheduleRepository.findById(privateSchedule.getId()).orElseThrow(); + Assertions.assertThat(privateSchedule.getGroupId()).isEqualTo(updated.getGroupId()); + Assertions.assertThat(privateSchedule.isAlarm()).isEqualTo(updated.isAlarm()); + Assertions.assertThat(privateSchedule.getGroupId()).isEqualTo(updated.getGroupId()); + Assertions.assertThat(privateSchedule.getPublicSchedule()).isEqualTo(updated.getPublicSchedule()); + } + + @Test + @Transactional + @DisplayName("종료 날짜가 시작 날짜보다 빠른 경우 400") + void endTimeBeforeStartTime() throws Exception { + //given + ScheduleGroup scheduleGroup = privateScheduleMockData.createScheduleGroup(user); + PublicSchedule publicSchedule = privateScheduleMockData.createPublicSchedule(user.getIntraId()); + PrivateSchedule privateSchedule = privateScheduleMockData.createPrivateSchedule(publicSchedule, + scheduleGroup); + PrivateScheduleUpdateReqDto reqDto = PrivateScheduleUpdateReqDto.builder() + .eventTag(null) + .techTag(null) + .jobTag(null) + .alarm(false) + .title("123") + .content("") + .link(null) + .status(ScheduleStatus.ACTIVATE) + .startTime(LocalDateTime.now().plusDays(1)) + .endTime(LocalDateTime.now()) + .groupId(scheduleGroup.getId()) + .build(); + //when&then + mockMvc.perform(put("/calendar/private/" + privateSchedule.getId()) + .header("Authorization", "Bearer " + accessToken) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(reqDto))) + .andExpect(status().isBadRequest()); + } + + @Test + @Transactional + @DisplayName("작성자가 아닌 사람이 일정을 수정 하려는 경우 403") + void notMatchAuthor() throws Exception { + //given + ScheduleGroup scheduleGroup = privateScheduleMockData.createScheduleGroup(user); + PublicSchedule publicSchedule = privateScheduleMockData.createPublicSchedule("notMatchAuthor"); + PrivateSchedule privateSchedule = privateScheduleMockData.createPrivateSchedule(publicSchedule, + scheduleGroup); + PrivateScheduleUpdateReqDto reqDto = PrivateScheduleUpdateReqDto.builder() + .eventTag(null) + .techTag(null) + .jobTag(null) + .alarm(false) + .title("123") + .content("") + .link(null) + .status(ScheduleStatus.ACTIVATE) + .startTime(LocalDateTime.now()) + .endTime(LocalDateTime.now().plusDays(1)) + .groupId(scheduleGroup.getId()) + .build(); + //when + mockMvc.perform(put("/calendar/private/" + privateSchedule.getId()) + .header("Authorization", "Bearer " + accessToken) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(reqDto))) + .andExpect(status().isForbidden()); + } + + @Test + @Transactional + @DisplayName("일정이 없는 경우 404") + void noSchedule() throws Exception { + //given + ScheduleGroup scheduleGroup = privateScheduleMockData.createScheduleGroup(user); + PublicSchedule publicSchedule = privateScheduleMockData.createPublicSchedule("notMatchAuthor"); + PrivateSchedule privateSchedule = privateScheduleMockData.createPrivateSchedule(publicSchedule, + scheduleGroup); + PrivateScheduleUpdateReqDto reqDto = PrivateScheduleUpdateReqDto.builder() + .eventTag(null) + .techTag(null) + .jobTag(null) + .alarm(false) + .title("123") + .content("") + .link(null) + .status(ScheduleStatus.ACTIVATE) + .startTime(LocalDateTime.now()) + .endTime(LocalDateTime.now().plusDays(1)) + .groupId(scheduleGroup.getId()) + .build(); + //when + mockMvc.perform(put("/calendar/private/" + privateSchedule.getId() + 123411243) + .header("Authorization", "Bearer " + accessToken) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(reqDto))) + .andExpect(status().isNotFound()); + } + } } diff --git a/gg-utils/src/main/java/gg/utils/exception/ErrorCode.java b/gg-utils/src/main/java/gg/utils/exception/ErrorCode.java index 8fa62caca..d1302e1c8 100644 --- a/gg-utils/src/main/java/gg/utils/exception/ErrorCode.java +++ b/gg-utils/src/main/java/gg/utils/exception/ErrorCode.java @@ -240,7 +240,7 @@ public enum ErrorCode { CALENDAR_BEFORE_DATE(400, "CA201", "종료 시간이 시작 시간보다 빠를 수 없습니다."), CALENDAR_AFTER_DATE(400, "CA202", "시작 시간이 종료 시간보다 늦을 수 없습니다."), CALENDAR_EQUAL_DATE(400, "CA203", "시작 시간과 종료 시간이 같을 수 없습니다."), - CALENDAR_AUTHOR_NOT_MATCH(400, "CA205", "전제하지 않는 사용자입니다."), + CALENDAR_AUTHOR_NOT_MATCH(403, "CA205", "전제하지 않는 사용자입니다."), PRIVATE_SCHEDULE_NOT_FOUND(404, "CA101", "개인 일정을 찾을 수 없습니다."), PUBLIC_SCHEDULE_NOT_FOUND(404, "CA102", "공유 일정을 찾을 수 없습니다."), SCHEDULE_GROUP_NOT_FOUND(404, "CA103", "스캐줄 그룹을 찾을 수 없습니다.");