Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat1: memory 서비스&컨트롤러 구현 중 #17

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/umc_haekathon_4/demo/domain/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public class Image extends BaseEntity {
@JoinColumn(name = "memory_id")
private Memory memory;

private String body;

}
2 changes: 2 additions & 0 deletions src/main/java/umc_haekathon_4/demo/domain/Memory.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/umc_haekathon_4/demo/domain/TreasureBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ public class TreasureBox extends BaseEntity {
private String status;
private String title;
private String location;
private String body;
}
34 changes: 34 additions & 0 deletions src/main/java/umc_haekathon_4/demo/service/MemoryService.java
Original file line number Diff line number Diff line change
@@ -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<Image> images=imageRepository.findAllById(request.getImageIds());

Memory memory = MemoryConverter.convertToEntity(request,images,treasureBox);
return memoryRepository.save(memory);
}
}
Original file line number Diff line number Diff line change
@@ -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<MemoryResponseDTO.MemoryResponseDTOBuilder> 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")


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ public static class createImageDTO{
private Long memoryId;
}

}
}
Loading