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..a8e0fe3 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); // 년도, 월, 일 추출 @@ -42,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()) @@ -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/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; 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; + } + }