From 7de73068ffbfac0ffbd4cc46b1d05c4c5096cd09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=97=B0?= Date: Fri, 5 Jul 2024 06:27:14 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Feat:=20=EA=BF=88=20=EC=9D=BC=EA=B8=B0=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../umc/dream/controller/DreamController.java | 13 ++++++++++--- src/main/java/com/umc/dream/domain/Dream.java | 17 +++++++++++++++++ .../com/umc/dream/service/DreamService.java | 13 +++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/umc/dream/controller/DreamController.java b/src/main/java/com/umc/dream/controller/DreamController.java index d94603e..1255e5d 100644 --- a/src/main/java/com/umc/dream/controller/DreamController.java +++ b/src/main/java/com/umc/dream/controller/DreamController.java @@ -37,19 +37,26 @@ public ApiResponse createDream(@RequestBody DreamRequestDto @Parameters({ @Parameter(name = "user_id", description = "꿈 일기 목록을 조회하고자하는 사용자의 pk"), }) - private ApiResponse> GetDream(@RequestParam Long user_id) { + private ApiResponse> GetDream(@PathVariable Long user_id) { List getDreamResponseDtos = dreamService.getDream(user_id); return ApiResponse.onSuccess(getDreamResponseDtos); } - @GetMapping("/diary/{user_id}/{diary_id}") + @GetMapping("/diary/{user_id}/{dream_id}") @Operation(summary = "내 꿈 일기 상세 조회", description = "내 꿈 일기 상세 조회 API입니다") @Parameters({ @Parameter(name = "user_id", description = "자신의 pk"), @Parameter(name = "dream_id", description = "꿈 일기의 pk") }) - private ApiResponse ViewDream(@RequestParam Long user_id, @RequestParam Long dream_id) { + private ApiResponse ViewDream(@PathVariable Long user_id, @PathVariable Long dream_id) { ViewDreamResponseDto viewDreamResponseDto = dreamService.viewDream(user_id, dream_id); return ApiResponse.onSuccess(viewDreamResponseDto); } + + @DeleteMapping("/diary/{user_id}/{dream_id}") + @Operation(summary = "꿈 일기 삭제 API", description = "꿈 일기 삭제 API입니다") + public ApiResponse deleteDream(@PathVariable Long user_id, @PathVariable Long dream_id) { + dreamService.deleteDream(user_id, dream_id); + return ApiResponse.onSuccess(null); + } } diff --git a/src/main/java/com/umc/dream/domain/Dream.java b/src/main/java/com/umc/dream/domain/Dream.java index ac1e8ff..064260a 100644 --- a/src/main/java/com/umc/dream/domain/Dream.java +++ b/src/main/java/com/umc/dream/domain/Dream.java @@ -10,6 +10,8 @@ import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; @Entity @Getter @@ -38,6 +40,21 @@ public class Dream extends BaseEntity { @Enumerated(EnumType.STRING) private DreamCategory category; + @OneToMany(mappedBy = "dream", cascade = CascadeType.ALL, orphanRemoval = true) + private List characters = new ArrayList<>(); + + @OneToMany(mappedBy = "dream", cascade = CascadeType.ALL, orphanRemoval = true) + private List places = new ArrayList<>(); + + @OneToMany(mappedBy = "dream", cascade = CascadeType.ALL, orphanRemoval = true) + private List feelings = new ArrayList<>(); + + @OneToMany(mappedBy = "dream", cascade = CascadeType.ALL, orphanRemoval = true) + private List hashtags = new ArrayList<>(); + + @OneToMany(mappedBy = "dream", cascade = CascadeType.ALL, orphanRemoval = true) + private List posts = new ArrayList<>(); + @Builder public Dream(User user, LocalDate date, LocalDateTime sleepTime, LocalDateTime wakeUpTime, String title, String content, DreamCategory category) { this.user = user; diff --git a/src/main/java/com/umc/dream/service/DreamService.java b/src/main/java/com/umc/dream/service/DreamService.java index f579270..5dd2a81 100644 --- a/src/main/java/com/umc/dream/service/DreamService.java +++ b/src/main/java/com/umc/dream/service/DreamService.java @@ -107,4 +107,17 @@ public ViewDreamResponseDto viewDream(Long user_id, Long dream_id) { } return DreamConverter.toViewDreamResponse(dream, feels, name, location, tag); } + + @Transactional + public void deleteDream(Long user_id, Long dream_id) { + Dream dream = dreamRepository.findById(dream_id) + .orElseThrow(() -> new GeneralException(ErrorStatus._BAD_REQUEST)); + + // 작성자가 아닌 경우 + if (!dream.getUser().getId().equals(user_id)) { + throw new GeneralException(ErrorStatus._FORBIDDEN); + } + + dreamRepository.delete(dream); + } } From b4663eb1d707cf991e314f999b4376c55080bcbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EC=97=B0?= Date: Fri, 5 Jul 2024 06:31:20 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Feat:=20Swagger=EC=97=90=EC=84=9C=20health?= =?UTF-8?q?=20check=20API=20=EC=88=A8=EA=B8=B0=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/umc/dream/controller/TestController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/umc/dream/controller/TestController.java b/src/main/java/com/umc/dream/controller/TestController.java index 40e1508..0db41eb 100644 --- a/src/main/java/com/umc/dream/controller/TestController.java +++ b/src/main/java/com/umc/dream/controller/TestController.java @@ -1,5 +1,6 @@ package com.umc.dream.controller; +import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.Operation; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @@ -7,6 +8,7 @@ @RestController public class TestController { + @Hidden @GetMapping("/health") @Operation(summary = "health check API",description = "인스턴스의 health check하는 API입니다") public String healthCheck() {