diff --git a/src/main/java/aws/teamthreefive/diecast/controller/DiecastController.java b/src/main/java/aws/teamthreefive/diecast/controller/DiecastController.java index 0cd3b49..102bee2 100644 --- a/src/main/java/aws/teamthreefive/diecast/controller/DiecastController.java +++ b/src/main/java/aws/teamthreefive/diecast/controller/DiecastController.java @@ -24,6 +24,19 @@ public class DiecastController { // GET private final DiecastQueryService diecastQueryService; + @PostMapping(value = "/save/{diecastvideoUuid}") + @Operation(summary = "객체 오브젝트 정보 저장 API", description = "객체 오브젝트 저장") + public DiecastResponseDTO.SaveDiecastResultDTO saveDiecast( + @RequestBody DiecastRequestDTO.DiecastDTO request, + @PathVariable(name = "diecastvideoUuid") Long diecastvideoUuid + ) { + + Diecast diecast = diecastCommandService.saveDiecast(diecastvideoUuid, request); + + return DiecastConverter.toSaveDiecastResultDTO(diecast); + + } + @PostMapping(value = "/{diecastUuid}", consumes = "multipart/form-data") @Operation(summary = "사진 저장 API", description = "업로드된 사진 저장") public DiecastResponseDTO.SavePhotoResultDTO savePhoto( diff --git a/src/main/java/aws/teamthreefive/diecast/converter/DiecastConverter.java b/src/main/java/aws/teamthreefive/diecast/converter/DiecastConverter.java index 709327d..a476dae 100644 --- a/src/main/java/aws/teamthreefive/diecast/converter/DiecastConverter.java +++ b/src/main/java/aws/teamthreefive/diecast/converter/DiecastConverter.java @@ -11,6 +11,22 @@ public class DiecastConverter { + public static Diecast toDiecast(DiecastRequestDTO.DiecastDTO request) { + return Diecast.builder() + .diecastOkng(request.getDiecastOkng()) + .createdAt(LocalDateTime.now()) + .build(); + } + + public static DiecastResponseDTO.SaveDiecastResultDTO toSaveDiecastResultDTO(Diecast diecast) { + return DiecastResponseDTO.SaveDiecastResultDTO.builder() + .diecastUuid(diecast.getDiecastUuid()) + .diecastOkng(diecast.getDiecastOkng()) + .diecastvideoUuid(diecast.getDiecastvideo().getDiecastvideoUuid()) + .createdAt(diecast.getCreatedAt()) + .build(); + } + public static Photo toPhoto(DiecastRequestDTO.PhotoDTO request, String photoUrl) { return Photo.builder() .photoUrl(photoUrl) diff --git a/src/main/java/aws/teamthreefive/diecast/dto/request/DiecastRequestDTO.java b/src/main/java/aws/teamthreefive/diecast/dto/request/DiecastRequestDTO.java index c22a07e..4756585 100644 --- a/src/main/java/aws/teamthreefive/diecast/dto/request/DiecastRequestDTO.java +++ b/src/main/java/aws/teamthreefive/diecast/dto/request/DiecastRequestDTO.java @@ -4,10 +4,15 @@ import lombok.Setter; import org.springframework.web.multipart.MultipartFile; -import java.math.BigDecimal; public class DiecastRequestDTO { + @Getter + @Setter + public static class DiecastDTO { + int diecastOkng; + } + @Getter @Setter public static class PhotoDTO { diff --git a/src/main/java/aws/teamthreefive/diecast/dto/response/DiecastResponseDTO.java b/src/main/java/aws/teamthreefive/diecast/dto/response/DiecastResponseDTO.java index 6fe3f6e..c95ed94 100644 --- a/src/main/java/aws/teamthreefive/diecast/dto/response/DiecastResponseDTO.java +++ b/src/main/java/aws/teamthreefive/diecast/dto/response/DiecastResponseDTO.java @@ -5,12 +5,22 @@ import lombok.Getter; import lombok.NoArgsConstructor; -import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.List; public class DiecastResponseDTO { + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class SaveDiecastResultDTO { + Long diecastUuid; + int diecastOkng; + LocalDateTime createdAt; + Long diecastvideoUuid; + } + @Builder @Getter @NoArgsConstructor diff --git a/src/main/java/aws/teamthreefive/diecast/service/DiecastCommandService.java b/src/main/java/aws/teamthreefive/diecast/service/DiecastCommandService.java index 88dafaa..ae9905c 100644 --- a/src/main/java/aws/teamthreefive/diecast/service/DiecastCommandService.java +++ b/src/main/java/aws/teamthreefive/diecast/service/DiecastCommandService.java @@ -3,8 +3,9 @@ import aws.teamthreefive.aws.s3.AmazonS3Manager; import aws.teamthreefive.diecast.converter.DiecastConverter; import aws.teamthreefive.diecast.dto.request.DiecastRequestDTO; +import aws.teamthreefive.diecast.entity.Diecast; import aws.teamthreefive.diecast.repository.DiecastRepository; -import aws.teamthreefive.photo.converter.PhotoConverter; +import aws.teamthreefive.diecastvideo.repository.DiecastvideoRepository; import aws.teamthreefive.photo.entity.Photo; import aws.teamthreefive.photo.repository.PhotoRepository; import aws.teamthreefive.uuid.entity.Uuid; @@ -13,9 +14,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; -import java.util.List; import java.util.UUID; -import java.util.stream.Collectors; @Service @Transactional @@ -23,10 +22,21 @@ public class DiecastCommandService { private final DiecastRepository diecastRepository; + private final DiecastvideoRepository diecastvideoRepository; private final UuidRepository uuidRepository; private final PhotoRepository photoRepository; private final AmazonS3Manager s3Manager; + public Diecast saveDiecast(Long diecastvideoUuid, DiecastRequestDTO.DiecastDTO request) { + + Diecast diecast = DiecastConverter.toDiecast(request); + + diecast.setDiecastvideo(diecastvideoRepository.findById(diecastvideoUuid).get()); + + return diecastRepository.save(diecast); + + } + public Photo savePhoto(Long diecastUuid, DiecastRequestDTO.PhotoDTO request) { //Photo photo = DiecastConverter.toPhoto(request); diff --git a/src/main/java/aws/teamthreefive/photo/entity/Photo.java b/src/main/java/aws/teamthreefive/photo/entity/Photo.java index 44360a8..8fc556e 100644 --- a/src/main/java/aws/teamthreefive/photo/entity/Photo.java +++ b/src/main/java/aws/teamthreefive/photo/entity/Photo.java @@ -13,7 +13,7 @@ @Entity @Getter -@Setter +//@Setter @DynamicUpdate @DynamicInsert @Builder