diff --git a/src/main/java/umc_haekathon_4/demo/domain/Image.java b/src/main/java/umc_haekathon_4/demo/domain/Image.java index 55a3db7..15976eb 100644 --- a/src/main/java/umc_haekathon_4/demo/domain/Image.java +++ b/src/main/java/umc_haekathon_4/demo/domain/Image.java @@ -28,4 +28,6 @@ public class Image extends BaseEntity { @JoinColumn(name = "memory_id") private Memory memory; + private String body; + } diff --git a/src/main/java/umc_haekathon_4/demo/domain/Memory.java b/src/main/java/umc_haekathon_4/demo/domain/Memory.java index 24c2e02..3637431 100644 --- a/src/main/java/umc_haekathon_4/demo/domain/Memory.java +++ b/src/main/java/umc_haekathon_4/demo/domain/Memory.java @@ -1,9 +1,11 @@ package umc_haekathon_4.demo.domain; import jakarta.persistence.*; + import lombok.*; import umc_haekathon_4.demo.domain.common.BaseEntity; + import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/umc_haekathon_4/demo/domain/TreasureBox.java b/src/main/java/umc_haekathon_4/demo/domain/TreasureBox.java index f8ccd19..6d6305f 100644 --- a/src/main/java/umc_haekathon_4/demo/domain/TreasureBox.java +++ b/src/main/java/umc_haekathon_4/demo/domain/TreasureBox.java @@ -36,4 +36,5 @@ public class TreasureBox extends BaseEntity { private String status; private String title; private String location; + private String body; } diff --git a/src/main/java/umc_haekathon_4/demo/service/MemoryService.java b/src/main/java/umc_haekathon_4/demo/service/MemoryService.java new file mode 100644 index 0000000..9c9428b --- /dev/null +++ b/src/main/java/umc_haekathon_4/demo/service/MemoryService.java @@ -0,0 +1,34 @@ +package umc_haekathon_4.demo.service; + +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import umc_haekathon_4.demo.converter.MemoryConverter; +import umc_haekathon_4.demo.domain.Image; +import umc_haekathon_4.demo.domain.Memory; +import umc_haekathon_4.demo.domain.TreasureBox; +import umc_haekathon_4.demo.repository.ImageRepository; +import umc_haekathon_4.demo.repository.MemoryRepository; +import umc_haekathon_4.demo.repository.TreasureBoxRepository; +import umc_haekathon_4.demo.web.dto.MemoryRequestDTO; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class MemoryService { + + private final MemoryRepository memoryRepository; + private final TreasureBoxRepository treasureBoxRepository; + private final ImageRepository imageRepository; + + + public Memory createMemory(MemoryRequestDTO.CreateMemoryDto request) { + + TreasureBox treasureBox=treasureBoxRepository.findById(request.getTreasureBoxId(); + + List images=imageRepository.findAllById(request.getImageIds()); + + Memory memory = MemoryConverter.convertToEntity(request,images,treasureBox); + return memoryRepository.save(memory); + } +} diff --git a/src/main/java/umc_haekathon_4/demo/web/controller/MemoryController.java b/src/main/java/umc_haekathon_4/demo/web/controller/MemoryController.java new file mode 100644 index 0000000..255110a --- /dev/null +++ b/src/main/java/umc_haekathon_4/demo/web/controller/MemoryController.java @@ -0,0 +1,47 @@ +package umc_haekathon_4.demo.web.controller; + +import jakarta.validation.Valid; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import umc_haekathon_4.demo.apiPayload.ApiResponse; +import umc_haekathon_4.demo.domain.Memory; +import umc_haekathon_4.demo.service.MemoryService; +import umc_haekathon_4.demo.web.dto.MemoryRequestDTO; +import umc_haekathon_4.demo.web.dto.MemoryResponseDTO; + +import java.util.List; + +@Controller +@RequiredArgsConstructor +@RequestMapping("/") +public class MemoryController { + + private final MemoryService memoryService; + + //추억 등록 + @PostMapping("/memory/upload") + public ApiResponse create(@RequestBody @Valid MemoryRequestDTO.CreateMemoryDto request) { + Memory memory = memoryService.createMemory(title, memo, treasureBoxId, imageIds); + return null; + } + + //추억 제목 + @PostMapping("/memory/upload/title") + + //추억 내용 작성 + @PostMapping("/memory/upload/write") + + //추억 사진 올리기 + @PostMapping("/memory/upload/{image_id}") + + //추억 조회 + @GetMapping("/memory") + + //추억 미리보기 + @GetMapping("/memory-preview") + + +} diff --git a/src/main/java/umc_haekathon_4/demo/web/dto/ImageRequestDTO.java b/src/main/java/umc_haekathon_4/demo/web/dto/ImageRequestDTO.java index 2f44c26..4e00519 100644 --- a/src/main/java/umc_haekathon_4/demo/web/dto/ImageRequestDTO.java +++ b/src/main/java/umc_haekathon_4/demo/web/dto/ImageRequestDTO.java @@ -18,4 +18,4 @@ public static class createImageDTO{ private Long memoryId; } -} +} \ No newline at end of file