Skip to content

Commit

Permalink
Merge pull request #15 from AWS-CV-Project-3355/feat/#14-diecast-photos
Browse files Browse the repository at this point in the history
Feat/#14 diecast photos
  • Loading branch information
melitina915 authored Nov 26, 2024
2 parents ee55826 + 4feba0d commit 9cff343
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
application.yml
!**/src/main/resources/application.yml

HELP.md
.gradle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "업로드된 사진 저장")
Expand All @@ -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<Photo> photoList = diecastQueryService.getPhotoList(diecastUuid);

return DiecastConverter.photoListDTO(photoList);

}




}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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<Photo> photoList) {

List<DiecastResponseDTO.PhotoDTO> photoDTOList = photoList.stream()
.map(DiecastConverter::photoDTO).collect(Collectors.toList());

return DiecastResponseDTO.PhotoListDTO.builder()
.photoList(photoDTOList)
.build();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

public class DiecastResponseDTO {

Expand All @@ -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<PhotoDTO> 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;
}

}
6 changes: 6 additions & 0 deletions src/main/java/aws/teamthreefive/diecast/entity/Diecast.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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));

}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Photo> getPhotoList(Long diecastUuid) {

Diecast diecast = diecastRepository.findById(diecastUuid).get();

List<Photo> photoList = photoRepository.findAllByDiecast(diecast);

return photoList;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

public class DiecastvideoResponseDTO {

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class SaveDiecastvideoResultDTO {
Long diecastvideoUuid;
String diecastvideoUrl;
LocalDateTime createdAt;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,29 @@

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)
.photoPosition(photo.getPhotoPosition())
.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();
// }

}
14 changes: 10 additions & 4 deletions src/main/java/aws/teamthreefive/photo/entity/Photo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Photo, Long> {

List<Photo> findAllByDiecast(Diecast diecast);

}
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spring:
init:
mode: never
jpa:
# open-in-view: false
# open-in-view: false
properties:
hibernate:
dialect: org.hibernate.dialect.MySQLDialect
Expand Down

0 comments on commit 9cff343

Please sign in to comment.