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/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() { 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); + } }