diff --git a/.gitignore b/.gitignore index a229e9a..a0547c9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -application.yml +!**/src/main/resources/application.yml HELP.md .gradle diff --git a/src/main/java/aws/teamthreefive/diecast/controller/DiecastController.java b/src/main/java/aws/teamthreefive/diecast/controller/DiecastController.java index b325cb3..e171d63 100644 --- a/src/main/java/aws/teamthreefive/diecast/controller/DiecastController.java +++ b/src/main/java/aws/teamthreefive/diecast/controller/DiecastController.java @@ -4,18 +4,24 @@ import aws.teamthreefive.diecast.dto.request.DiecastRequestDTO; import aws.teamthreefive.diecast.dto.response.DiecastResponseDTO; import aws.teamthreefive.diecast.service.DiecastCommandService; +import aws.teamthreefive.diecast.service.DiecastQueryService; import aws.teamthreefive.photo.entity.Photo; import io.swagger.v3.oas.annotations.Operation; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; +import java.util.List; + @CrossOrigin @RestController @RequiredArgsConstructor @RequestMapping("/diecast") public class DiecastController { + // POST private final DiecastCommandService diecastCommandService; + // GET + private final DiecastQueryService diecastQueryService; @PostMapping(value = "/{diecastUuid}", consumes = "multipart/form-data") @Operation(summary = "사진 저장 API", description = "업로드된 사진 저장") @@ -29,5 +35,17 @@ public DiecastResponseDTO.SavePhotoResultDTO savePhoto( return DiecastConverter.toSavePhotoResultDTO(photo); } + @GetMapping(value = "/{diecastUuid}/photo/list") + @Operation(summary = "객체별 사진 5개 API", description = "객체별 사진 5개 리스트") + public DiecastResponseDTO.PhotoListDTO getPhotoList(@PathVariable(name = "diecastUuid") Long diecastUuid) { + + List photoList = diecastQueryService.getPhotoList(diecastUuid); + + return DiecastConverter.photoListDTO(photoList); + + } + + + } diff --git a/src/main/java/aws/teamthreefive/diecast/converter/DiecastConverter.java b/src/main/java/aws/teamthreefive/diecast/converter/DiecastConverter.java index a952d6c..b38921b 100644 --- a/src/main/java/aws/teamthreefive/diecast/converter/DiecastConverter.java +++ b/src/main/java/aws/teamthreefive/diecast/converter/DiecastConverter.java @@ -4,14 +4,20 @@ import aws.teamthreefive.diecast.dto.response.DiecastResponseDTO; import aws.teamthreefive.photo.entity.Photo; +import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; + public class DiecastConverter { - public static Photo toPhoto(DiecastRequestDTO.PhotoDTO request) { + public static Photo toPhoto(DiecastRequestDTO.PhotoDTO request, String photoUrl) { return Photo.builder() + .photoUrl(photoUrl) .photoPosition(request.getPhotoPosition()) .photoNgtype(request.getPhotoNgtype()) .photoCroplt(request.getPhotoCroplt()) .photoCroprb(request.getPhotoCroprb()) + .createdAt(LocalDateTime.now()) .build(); } @@ -24,7 +30,32 @@ public static DiecastResponseDTO.SavePhotoResultDTO toSavePhotoResultDTO(Photo p .photoCroplt(photo.getPhotoCroplt()) .photoCroprb(photo.getPhotoCroprb()) .diecastUuid(photo.getDiecast().getDiecastUuid()) + .createdAt(photo.getCreatedAt()) .build(); } + public static DiecastResponseDTO.PhotoDTO photoDTO(Photo photo) { + return DiecastResponseDTO.PhotoDTO.builder() + .photoUuid(photo.getPhotoUuid()) + .photoUrl(photo.getPhotoUrl()) + .photoPosition(photo.getPhotoPosition()) + .photoNgtype(photo.getPhotoNgtype()) + .photoCroplt(photo.getPhotoCroplt()) + .photoCroprb(photo.getPhotoCroprb()) + .diecastUuid(photo.getDiecast().getDiecastUuid()) + .createdAt(photo.getCreatedAt()) + .build(); + } + + public static DiecastResponseDTO.PhotoListDTO photoListDTO(List photoList) { + + List photoDTOList = photoList.stream() + .map(DiecastConverter::photoDTO).collect(Collectors.toList()); + + return DiecastResponseDTO.PhotoListDTO.builder() + .photoList(photoDTOList) + .build(); + + } + } 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 87892f7..c22a07e 100644 --- a/src/main/java/aws/teamthreefive/diecast/dto/request/DiecastRequestDTO.java +++ b/src/main/java/aws/teamthreefive/diecast/dto/request/DiecastRequestDTO.java @@ -13,8 +13,8 @@ public class DiecastRequestDTO { public static class PhotoDTO { int photoPosition; int photoNgtype; - BigDecimal photoCroplt; - BigDecimal photoCroprb; + Float photoCroplt; + Float photoCroprb; MultipartFile photoFile; } 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 4aa8e54..60b4777 100644 --- a/src/main/java/aws/teamthreefive/diecast/dto/response/DiecastResponseDTO.java +++ b/src/main/java/aws/teamthreefive/diecast/dto/response/DiecastResponseDTO.java @@ -6,6 +6,8 @@ import lombok.NoArgsConstructor; import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.List; public class DiecastResponseDTO { @@ -18,9 +20,33 @@ public static class SavePhotoResultDTO { String photoUrl; int photoPosition; int photoNgtype; - BigDecimal photoCroplt; - BigDecimal photoCroprb; + Float photoCroplt; + Float photoCroprb; Long diecastUuid; + LocalDateTime createdAt; + } + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class PhotoListDTO { + List photoList; + } + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class PhotoDTO { + Long photoUuid; + String photoUrl; + int photoPosition; + int photoNgtype; + Float photoCroplt; + Float photoCroprb; + Long diecastUuid; + LocalDateTime createdAt; } } diff --git a/src/main/java/aws/teamthreefive/diecast/entity/Diecast.java b/src/main/java/aws/teamthreefive/diecast/entity/Diecast.java index 9c67c18..561899a 100644 --- a/src/main/java/aws/teamthreefive/diecast/entity/Diecast.java +++ b/src/main/java/aws/teamthreefive/diecast/entity/Diecast.java @@ -7,7 +7,9 @@ import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; +import org.springframework.data.annotation.CreatedDate; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -30,6 +32,10 @@ public class Diecast { @ColumnDefault("0") private int diecastOkng; + @CreatedDate + @Column(name = "created_at", nullable = false, columnDefinition = "dateTime") + private LocalDateTime createdAt; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "diecastvideo_uuid") private Diecastvideo diecastvideo; diff --git a/src/main/java/aws/teamthreefive/diecast/service/DiecastCommandService.java b/src/main/java/aws/teamthreefive/diecast/service/DiecastCommandService.java index a7aaa92..88dafaa 100644 --- a/src/main/java/aws/teamthreefive/diecast/service/DiecastCommandService.java +++ b/src/main/java/aws/teamthreefive/diecast/service/DiecastCommandService.java @@ -29,7 +29,7 @@ public class DiecastCommandService { public Photo savePhoto(Long diecastUuid, DiecastRequestDTO.PhotoDTO request) { - Photo photo = DiecastConverter.toPhoto(request); + //Photo photo = DiecastConverter.toPhoto(request); String uuid = UUID.randomUUID().toString(); Uuid savedUuid = uuidRepository.save( @@ -38,13 +38,21 @@ public Photo savePhoto(Long diecastUuid, DiecastRequestDTO.PhotoDTO request) { .build() ); - String fileUrl = s3Manager.uploadFile(s3Manager.generatePhotoKeyName(savedUuid), request.getPhotoFile()); + String photoUrl = s3Manager.uploadFile(s3Manager.generatePhotoKeyName(savedUuid), request.getPhotoFile()); + + Photo photo = DiecastConverter.toPhoto(request, photoUrl); photo.setDiecast(diecastRepository.findById(diecastUuid).get()); - photo.setPhotoUrl(fileUrl); + +// photo = PhotoConverter.toPhoto(fileUrl); + + /// + //photo.setPhotoUrl(fileUrl); + /// return photoRepository.save(photo); -// return photoRepository.save(PhotoConverter.toPhoto(fileUrl, photo)); +// return photoRepository.save(PhotoConverter.toPhoto(photoUrl, photo)); +// return photoRepository.save(PhotoConverter.toPhoto(fileUrl)); } diff --git a/src/main/java/aws/teamthreefive/diecast/service/DiecastQueryService.java b/src/main/java/aws/teamthreefive/diecast/service/DiecastQueryService.java new file mode 100644 index 0000000..6577df6 --- /dev/null +++ b/src/main/java/aws/teamthreefive/diecast/service/DiecastQueryService.java @@ -0,0 +1,31 @@ +package aws.teamthreefive.diecast.service; + +import aws.teamthreefive.diecast.entity.Diecast; +import aws.teamthreefive.diecast.repository.DiecastRepository; +import aws.teamthreefive.photo.entity.Photo; +import aws.teamthreefive.photo.repository.PhotoRepository; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +@Transactional +public class DiecastQueryService { + + private final DiecastRepository diecastRepository; + private final PhotoRepository photoRepository; + + public List getPhotoList(Long diecastUuid) { + + Diecast diecast = diecastRepository.findById(diecastUuid).get(); + + List photoList = photoRepository.findAllByDiecast(diecast); + + return photoList; + + } + +} diff --git a/src/main/java/aws/teamthreefive/diecastvideo/converter/DiecastvideoConverter.java b/src/main/java/aws/teamthreefive/diecastvideo/converter/DiecastvideoConverter.java index cf1502f..c470892 100644 --- a/src/main/java/aws/teamthreefive/diecastvideo/converter/DiecastvideoConverter.java +++ b/src/main/java/aws/teamthreefive/diecastvideo/converter/DiecastvideoConverter.java @@ -4,17 +4,22 @@ import aws.teamthreefive.diecastvideo.dto.DiecastvideoResponseDTO; import aws.teamthreefive.diecastvideo.entity.Diecastvideo; +import java.time.LocalDateTime; + public class DiecastvideoConverter { public static Diecastvideo toDiecastvideo(String diecastvideoUrl) { return Diecastvideo.builder() .diecastvideoUrl(diecastvideoUrl) + .createdAt(LocalDateTime.now()) .build(); } public static DiecastvideoResponseDTO.SaveDiecastvideoResultDTO toSaveDiecastvideoResultDTO(Diecastvideo diecastvideo) { return DiecastvideoResponseDTO.SaveDiecastvideoResultDTO.builder() + .diecastvideoUuid(diecastvideo.getDiecastvideoUuid()) .diecastvideoUrl(diecastvideo.getDiecastvideoUrl()) + .createdAt(diecastvideo.getCreatedAt()) .build(); } diff --git a/src/main/java/aws/teamthreefive/diecastvideo/dto/DiecastvideoResponseDTO.java b/src/main/java/aws/teamthreefive/diecastvideo/dto/DiecastvideoResponseDTO.java index 1109b60..3582636 100644 --- a/src/main/java/aws/teamthreefive/diecastvideo/dto/DiecastvideoResponseDTO.java +++ b/src/main/java/aws/teamthreefive/diecastvideo/dto/DiecastvideoResponseDTO.java @@ -5,6 +5,8 @@ import lombok.Getter; import lombok.NoArgsConstructor; +import java.time.LocalDateTime; + public class DiecastvideoResponseDTO { @Builder @@ -12,7 +14,9 @@ public class DiecastvideoResponseDTO { @NoArgsConstructor @AllArgsConstructor public static class SaveDiecastvideoResultDTO { + Long diecastvideoUuid; String diecastvideoUrl; + LocalDateTime createdAt; } } diff --git a/src/main/java/aws/teamthreefive/diecastvideo/entity/Diecastvideo.java b/src/main/java/aws/teamthreefive/diecastvideo/entity/Diecastvideo.java index 4f1d5ed..8492568 100644 --- a/src/main/java/aws/teamthreefive/diecastvideo/entity/Diecastvideo.java +++ b/src/main/java/aws/teamthreefive/diecastvideo/entity/Diecastvideo.java @@ -3,7 +3,9 @@ import aws.teamthreefive.diecast.entity.Diecast; import jakarta.persistence.*; import lombok.*; +import org.springframework.data.annotation.CreatedDate; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -22,6 +24,10 @@ public class Diecastvideo { @Column(name = "diecastvideo_url", nullable = false, columnDefinition = "varchar(500)") private String diecastvideoUrl; + @CreatedDate + @Column(name = "created_at", nullable = false, columnDefinition = "dateTime") + private LocalDateTime createdAt; + @OneToMany(mappedBy = "diecastvideo", cascade = CascadeType.ALL) diff --git a/src/main/java/aws/teamthreefive/photo/converter/PhotoConverter.java b/src/main/java/aws/teamthreefive/photo/converter/PhotoConverter.java index 531292e..82ad4cd 100644 --- a/src/main/java/aws/teamthreefive/photo/converter/PhotoConverter.java +++ b/src/main/java/aws/teamthreefive/photo/converter/PhotoConverter.java @@ -2,8 +2,11 @@ import aws.teamthreefive.photo.entity.Photo; +import java.time.LocalDateTime; + public class PhotoConverter { + /* public static Photo toPhoto(String photoUrl, Photo photo) { return Photo.builder() .photoUrl(photoUrl) @@ -11,7 +14,17 @@ public static Photo toPhoto(String photoUrl, Photo photo) { .photoNgtype(photo.getPhotoNgtype()) .photoCroplt(photo.getPhotoCroplt()) .photoCroprb(photo.getPhotoCroprb()) + .createdAt(LocalDateTime.now()) + .diecast(photo.getDiecast()) .build(); } + */ + +// public static Photo toPhoto(String photoUrl) { +// return Photo.builder() +// .photoUrl(photoUrl) +// .createdAt(LocalDateTime.now()) +// .build(); +// } } diff --git a/src/main/java/aws/teamthreefive/photo/entity/Photo.java b/src/main/java/aws/teamthreefive/photo/entity/Photo.java index 0ba7082..44360a8 100644 --- a/src/main/java/aws/teamthreefive/photo/entity/Photo.java +++ b/src/main/java/aws/teamthreefive/photo/entity/Photo.java @@ -6,8 +6,10 @@ import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; +import org.springframework.data.annotation.CreatedDate; import java.math.BigDecimal; +import java.time.LocalDateTime; @Entity @Getter @@ -34,11 +36,15 @@ public class Photo { @ColumnDefault("0") private int photoNgtype; - @Column(name = "photo_croplt", nullable = true, columnDefinition = "decimal") - private BigDecimal photoCroplt; + @Column(name = "photo_croplt", nullable = true, columnDefinition = "float") + private Float photoCroplt; - @Column(name = "photo_croprb", nullable = true, columnDefinition = "decimal") - private BigDecimal photoCroprb; + @Column(name = "photo_croprb", nullable = true, columnDefinition = "float") + private Float photoCroprb; + + @CreatedDate + @Column(name = "created_at", nullable = false, columnDefinition = "dateTime") + private LocalDateTime createdAt; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "diecast_uuid") diff --git a/src/main/java/aws/teamthreefive/photo/repository/PhotoRepository.java b/src/main/java/aws/teamthreefive/photo/repository/PhotoRepository.java index 0631233..aa8dae4 100644 --- a/src/main/java/aws/teamthreefive/photo/repository/PhotoRepository.java +++ b/src/main/java/aws/teamthreefive/photo/repository/PhotoRepository.java @@ -1,8 +1,13 @@ package aws.teamthreefive.photo.repository; +import aws.teamthreefive.diecast.entity.Diecast; import aws.teamthreefive.photo.entity.Photo; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface PhotoRepository extends JpaRepository { + List findAllByDiecast(Diecast diecast); + } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 391a5ab..bf385f2 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -16,7 +16,7 @@ spring: init: mode: never jpa: -# open-in-view: false + # open-in-view: false properties: hibernate: dialect: org.hibernate.dialect.MySQLDialect