From 7a114645591d914161c60a49f886dd5c445707fd Mon Sep 17 00:00:00 2001 From: JeonHaeseung <414catherine@gmail.com> Date: Sun, 14 Apr 2024 18:02:09 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[feat]=20=EC=8A=A4=EC=BC=80=EC=A5=B4=20?= =?UTF-8?q?=EC=8B=9C=EA=B0=84=EB=8C=80=20=EB=B3=80=EA=B2=BD=20API=20?= =?UTF-8?q?=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/schedule/ScheduleController.java | 8 ++++++ .../domain/schedule/ScheduleRepository.java | 3 ++ .../domain/schedule/ScheduleService.java | 10 +++++-- .../dto/request/PostScheduleTimeDto.java | 28 +++++++++++++++++++ .../domain/schedule/entity/Schedule.java | 5 ++++ 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/main/java/Ness/Backend/domain/schedule/dto/request/PostScheduleTimeDto.java diff --git a/src/main/java/Ness/Backend/domain/schedule/ScheduleController.java b/src/main/java/Ness/Backend/domain/schedule/ScheduleController.java index 2a18a4f..b02712c 100644 --- a/src/main/java/Ness/Backend/domain/schedule/ScheduleController.java +++ b/src/main/java/Ness/Backend/domain/schedule/ScheduleController.java @@ -2,6 +2,7 @@ import Ness.Backend.domain.member.entity.Member; import Ness.Backend.domain.schedule.dto.request.PostScheduleDto; +import Ness.Backend.domain.schedule.dto.request.PostScheduleTimeDto; import Ness.Backend.domain.schedule.dto.response.GetOneMonthSchedulesDto; import Ness.Backend.global.auth.AuthUser; import io.swagger.v3.oas.annotations.Operation; @@ -39,6 +40,13 @@ public ResponseEntity getUserSchedule(@AuthUser Member return new ResponseEntity<>(oneUserMonthSchedules, HttpStatusCode.valueOf(200)); } + @PostMapping("/time") + @Operation(summary = "특정 스케쥴의 시간을 바꾸는 API입니다.", description = "&month=2024-01 와 같은 형식으로 데이터가 전달됩니다.") + public ResponseEntity postUserScheduleTime(@AuthUser Member member, @RequestBody PostScheduleTimeDto postScheduleTimeDto){ + scheduleService.changeScheduleTime(member.getId(), postScheduleTimeDto); + return new ResponseEntity<>(HttpStatusCode.valueOf(200)); + } + @PostMapping("/new") @Operation(summary = "새로운 스케쥴 내역", description = "새로운 스케쥴 내역 저장하는 API 입니다.") public ResponseEntity postUserSchedule(@AuthUser Member member, @RequestBody PostScheduleDto postScheduleDto){ diff --git a/src/main/java/Ness/Backend/domain/schedule/ScheduleRepository.java b/src/main/java/Ness/Backend/domain/schedule/ScheduleRepository.java index 99acc84..2493289 100644 --- a/src/main/java/Ness/Backend/domain/schedule/ScheduleRepository.java +++ b/src/main/java/Ness/Backend/domain/schedule/ScheduleRepository.java @@ -22,4 +22,7 @@ List findOneMonthSchedulesByMember_Id( @Param("memberId") Long memberId, @Param("year") int year, @Param("month") int month); + + //스케쥴 ID로 특정 스케쥴 찾아주기 + Schedule findScheduleById(Long scheduleId); } diff --git a/src/main/java/Ness/Backend/domain/schedule/ScheduleService.java b/src/main/java/Ness/Backend/domain/schedule/ScheduleService.java index d60c5f1..c8d73f8 100644 --- a/src/main/java/Ness/Backend/domain/schedule/ScheduleService.java +++ b/src/main/java/Ness/Backend/domain/schedule/ScheduleService.java @@ -4,6 +4,7 @@ import Ness.Backend.domain.member.entity.Member; import Ness.Backend.domain.schedule.dto.request.PostFastApiScheduleDto; import Ness.Backend.domain.schedule.dto.request.PostScheduleDto; +import Ness.Backend.domain.schedule.dto.request.PostScheduleTimeDto; import Ness.Backend.domain.schedule.dto.response.GetOneMonthSchedulesDto; import Ness.Backend.domain.schedule.dto.response.GetScheduleDetailDto; import Ness.Backend.domain.schedule.dto.response.GetScheduleDto; @@ -24,12 +25,13 @@ @Service @RequiredArgsConstructor @Slf4j -@Transactional(readOnly = true) +@Transactional public class ScheduleService { private final ScheduleRepository scheduleRepository; private final MemberRepository memberRepository; private final FastApiScheduleApi fastApiScheduleApi; + @Transactional(readOnly = true) public GetOneMonthSchedulesDto getOneMonthUserSchedule(Long id, String date){ log.info("getOneMonthUserSchedule called by "+ id); // 년도, 월, 일 추출 @@ -57,7 +59,11 @@ public GetOneMonthSchedulesDto getOneMonthUserSchedule(Long id, String date){ return new GetOneMonthSchedulesDto(getScheduleDtos); } - @Transactional + public void changeScheduleTime(Long id, PostScheduleTimeDto postScheduleTimeDto){ + Schedule schedule = scheduleRepository.findScheduleById(postScheduleTimeDto.getId()); + schedule.changeTime(postScheduleTimeDto.getStartTime(), postScheduleTimeDto.getEndTime()); + } + public Long postNewUserSchedule(Long id, PostScheduleDto postScheduleDto){ log.info("postNewUserSchedule called by "+ id); Member memberEntity = memberRepository.findMemberById(id); diff --git a/src/main/java/Ness/Backend/domain/schedule/dto/request/PostScheduleTimeDto.java b/src/main/java/Ness/Backend/domain/schedule/dto/request/PostScheduleTimeDto.java new file mode 100644 index 0000000..673c21a --- /dev/null +++ b/src/main/java/Ness/Backend/domain/schedule/dto/request/PostScheduleTimeDto.java @@ -0,0 +1,28 @@ +package Ness.Backend.domain.schedule.dto.request; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.ZonedDateTime; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class PostScheduleTimeDto { + @Schema(description = "스케쥴의 DB 기본키", example = "1") + @JsonProperty("id") + private Long id; + + @Schema(description = "스케쥴 시작 시간", example = "2024-03-08T15:07:27.056103+09:00") + @JsonProperty("start") + private ZonedDateTime startTime; + + @Schema(description = "스케쥴 끝 시간", example = "2024-03-08T15:07:27.056103+09:00") + @JsonProperty("end") + private ZonedDateTime endTime; +} diff --git a/src/main/java/Ness/Backend/domain/schedule/entity/Schedule.java b/src/main/java/Ness/Backend/domain/schedule/entity/Schedule.java index 84fa287..4b244c8 100644 --- a/src/main/java/Ness/Backend/domain/schedule/entity/Schedule.java +++ b/src/main/java/Ness/Backend/domain/schedule/entity/Schedule.java @@ -54,4 +54,9 @@ public Schedule(Long id, String info, String location, String person, ZonedDateT this.chat = chat; } + public void changeTime(ZonedDateTime startTime, ZonedDateTime endTime){ + this.startTime = startTime; + this.endTime = endTime; + } + } From d71d99a6925e3f6955a92190ec937822d88b36df Mon Sep 17 00:00:00 2001 From: JeonHaeseung <414catherine@gmail.com> Date: Sun, 14 Apr 2024 18:06:20 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[fix]=20=EC=8A=A4=EC=BC=80=EC=A5=B4=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=20API=20=EC=8A=A4=ED=8E=99=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD(id=EB=A5=BC=20=EC=B5=9C=EC=83=81=EB=8B=A8=EC=97=90=20?= =?UTF-8?q?=EB=B0=98=ED=99=98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ness/Backend/domain/schedule/ScheduleService.java | 2 +- .../schedule/dto/response/GetScheduleDetailDto.java | 6 +----- .../domain/schedule/dto/response/GetScheduleDto.java | 8 +++++++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/Ness/Backend/domain/schedule/ScheduleService.java b/src/main/java/Ness/Backend/domain/schedule/ScheduleService.java index c8d73f8..a8e0fe3 100644 --- a/src/main/java/Ness/Backend/domain/schedule/ScheduleService.java +++ b/src/main/java/Ness/Backend/domain/schedule/ScheduleService.java @@ -44,13 +44,13 @@ public GetOneMonthSchedulesDto getOneMonthUserSchedule(Long id, String date){ // ScheduleListResponseDto에 매핑 List getScheduleDtos = scheduleList.stream() .map(schedule -> GetScheduleDto.builder() + .id(schedule.getId()) .category(schedule.getCategory().getName()) .categoryNum(schedule.getCategory().getId()) .info(schedule.getInfo()) .startTime(schedule.getStartTime()) .endTime(schedule.getEndTime()) .details(GetScheduleDetailDto.builder() - .id(schedule.getId()) .person(schedule.getPerson()) .location(schedule.getLocation()) .build()) diff --git a/src/main/java/Ness/Backend/domain/schedule/dto/response/GetScheduleDetailDto.java b/src/main/java/Ness/Backend/domain/schedule/dto/response/GetScheduleDetailDto.java index 6614192..ddc4e17 100644 --- a/src/main/java/Ness/Backend/domain/schedule/dto/response/GetScheduleDetailDto.java +++ b/src/main/java/Ness/Backend/domain/schedule/dto/response/GetScheduleDetailDto.java @@ -9,9 +9,6 @@ @Data @NoArgsConstructor public class GetScheduleDetailDto { - @Schema(description = "스케쥴 고유 인식 넘버", example = "0") - private Long id; - @Schema(description = "스케쥴 위치", example = "이화여대 ECC") private String location; @@ -19,8 +16,7 @@ public class GetScheduleDetailDto { private String person; @Builder - public GetScheduleDetailDto(Long id, String location, String person){ - this.id = id; + public GetScheduleDetailDto(String location, String person){ this.location = location; this.person = person; } diff --git a/src/main/java/Ness/Backend/domain/schedule/dto/response/GetScheduleDto.java b/src/main/java/Ness/Backend/domain/schedule/dto/response/GetScheduleDto.java index 52719f6..8a47e29 100644 --- a/src/main/java/Ness/Backend/domain/schedule/dto/response/GetScheduleDto.java +++ b/src/main/java/Ness/Backend/domain/schedule/dto/response/GetScheduleDto.java @@ -11,6 +11,9 @@ @Data @NoArgsConstructor public class GetScheduleDto { + @Schema(description = "스케쥴 고유 인식 넘버", example = "0") + private Long id; + @Schema(description = "스케쥴 텍스트 내용", example = "AI 공부") @JsonProperty("title") private String info; @@ -36,7 +39,10 @@ public class GetScheduleDto { private GetScheduleDetailDto details; @Builder - public GetScheduleDto(String category, Long categoryNum, String info, ZonedDateTime startTime, ZonedDateTime endTime, GetScheduleDetailDto details){ + public GetScheduleDto(Long id, String category, Long categoryNum, + String info, ZonedDateTime startTime, ZonedDateTime endTime, + GetScheduleDetailDto details){ + this.id = id; this.category = category; this.categoryNum = categoryNum; this.info = info;