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

[Feat] Save Diecast #27

Merged
merged 1 commit into from
Nov 27, 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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,20 +14,29 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

@Service
@Transactional
@RequiredArgsConstructor
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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/aws/teamthreefive/photo/entity/Photo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@Entity
@Getter
@Setter
//@Setter
@DynamicUpdate
@DynamicInsert
@Builder
Expand Down
Loading