Skip to content

Commit

Permalink
Temp: 사진 저장, 찾기 관련 기능 수정중
Browse files Browse the repository at this point in the history
  • Loading branch information
BYEONGRYEOL committed May 13, 2024
1 parent 7404bc8 commit ef91d47
Show file tree
Hide file tree
Showing 28 changed files with 389 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.gt.genti.adapter.in.web;

import static com.gt.genti.other.util.ApiUtils.*;

import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gt.genti.command.CreatePictureCompletedCommand;
import com.gt.genti.domain.PictureGenerateResponse;
import com.gt.genti.dto.UpdatePictureUrlRequestDto;
import com.gt.genti.error.ErrorCode;
import com.gt.genti.error.ExpectedException;
import com.gt.genti.other.auth.UserDetailsImpl;
import com.gt.genti.repository.PictureGenerateResponseRepository;
import com.gt.genti.service.PictureService;

import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping("/api/admin/picture-generate-responses")
@RequiredArgsConstructor
public class AdminPictureController {
private final PictureService pictureService;
private final PictureGenerateResponseRepository pictureGenerateResponseRepository;

@PostMapping("/{responseId}")
public ResponseEntity<ApiResult<Boolean>> updatePicture(
@AuthenticationPrincipal UserDetailsImpl userDetails,
UpdatePictureUrlRequestDto requestDto,
@PathVariable Long responseId) {
PictureGenerateResponse foundPictureGenerateResponse = pictureGenerateResponseRepository.findById(responseId)
.orElseThrow(() -> new ExpectedException(
ErrorCode.PictureGenerateResponseNotFound));

CreatePictureCompletedCommand command = CreatePictureCompletedCommand.builder()
.pictureGenerateResponse(foundPictureGenerateResponse)
.url(requestDto.getUrl())
.uploadedBy(userDetails.getId()).build();
pictureService.uploadPicture(command);
return success(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@RequestMapping("/api/admin/reports")
@RequiredArgsConstructor
public class AdminReportController {
ReportService reportService;
private final ReportService reportService;
@GetMapping("")
public ResponseEntity<ApiResult<List<ReportResponseDto>>> getAllReports(){
return success(reportService.getAllReports());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand Down Expand Up @@ -49,11 +50,12 @@ public ResponseEntity<ApiResult<List<PictureGenerateRequestDetailResponseDto>>>

@PostMapping("/picture-generate-responses/{pictureGenerateResponseId}")
public ResponseEntity<ApiResult<Boolean>> updatePictureUrl(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@PathVariable Long pictureGenerateResponseId,
@RequestBody List<UpdatePictureUrlRequestDto> updatePictureUrlRequestDtoList
) {
return success(
pictureGenerateWorkService.updatePictureUrls(pictureGenerateResponseId, updatePictureUrlRequestDtoList));
pictureGenerateWorkService.updatePictureUrls(pictureGenerateResponseId, updatePictureUrlRequestDtoList, userDetails.getId()));
}

@PostMapping("/picture-generate-responses/{pictureGenerateResponseId}/submit")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@

import com.gt.genti.application.port.in.PicturePosePort;
import com.gt.genti.domain.PicturePose;
import com.gt.genti.repository.PosePictureRepository;
import com.gt.genti.repository.PicturePoseRepository;

import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
public class PicturePosePersistenceAdapter implements PicturePosePort {
private final PosePictureRepository posePictureRepository;
private final PicturePoseRepository picturePoseRepository;

@Override
public Optional<PicturePose> findByUrl(String url) {
return posePictureRepository.findByUrl(url);
return picturePoseRepository.findByUrl(url);
}

@Override
public PicturePose save(PicturePose picturePose) {
return posePictureRepository.save(picturePose);
return picturePoseRepository.save(picturePose);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import com.gt.genti.adapter.usecase.PictureGenerateRequestUseCase;
import com.gt.genti.application.port.in.PictureGenerateRequestPort;
import com.gt.genti.application.port.in.PicturePosePort;
import com.gt.genti.application.port.in.PictureUserFacePort;
import com.gt.genti.command.CreatePicturePoseCommand;
import com.gt.genti.domain.Creator;
import com.gt.genti.domain.PictureGenerateRequest;
import com.gt.genti.domain.PicturePose;
Expand All @@ -29,6 +29,7 @@
import com.gt.genti.other.util.RandomUtils;
import com.gt.genti.repository.CreatorRepository;
import com.gt.genti.repository.UserRepository;
import com.gt.genti.service.PictureService;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -38,11 +39,11 @@
@RequiredArgsConstructor
public class PictureGenerateRequestService implements PictureGenerateRequestUseCase {
private final PictureGenerateRequestPort pictureGenerateRequestPort;
private final PicturePosePort picturePosePort;
private final CreatorRepository creatorRepository;
private final UserRepository userRepository;
private final PictureUserFacePort pictureUserFacePort;
private final OpenAIService openAIService;
private final PictureService pictureService;

@Override
public List<PictureGenerateRequestDetailResponseDto> getPictureGenerateRequest(Long userId,
Expand Down Expand Up @@ -95,12 +96,19 @@ public Boolean createPictureGenerateRequest(Long requesterId,
.orElseThrow(() -> new ExpectedException(ErrorCode.UserNotFound));

String posePictureUrl = pictureGenerateRequestRequestDto.getPosePictureUrl();
PicturePose foundPicturePose = picturePosePort.findByUrl(posePictureUrl)
.or(() -> Optional.of(picturePosePort.save(new PicturePose(posePictureUrl)))).get();
Optional<PicturePose> optionalPicturePose = pictureService.findByUrlPicturePose(posePictureUrl);
PicturePose foundPicturePose;
if (optionalPicturePose.isEmpty()) {
foundPicturePose = pictureService.uploadPicture(
CreatePicturePoseCommand.builder().url(posePictureUrl).uploadedBy(requesterId).build());
} else {
foundPicturePose = optionalPicturePose.get();
}

List<String> facePictureUrl = pictureGenerateRequestRequestDto.getFacePictureUrlList();

String promptAdvanced = openAIService.getAdvancedPrompt(new PromptAdvancementRequestDto(pictureGenerateRequestRequestDto.getPrompt()));
String promptAdvanced = openAIService.getAdvancedPrompt(
new PromptAdvancementRequestDto(pictureGenerateRequestRequestDto.getPrompt()));
log.info(promptAdvanced);

Set<PictureUserFace> foundFacePictureSet = new HashSet<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ public Boolean submit(Long pictureGenerateResponseId) {

@Transactional
public Boolean updatePictureUrls(Long pictureGenerateResponseId,
List<UpdatePictureUrlRequestDto> updatePictureUrlRequestDtoList) {
List<UpdatePictureUrlRequestDto> updatePictureUrlRequestDtoList, Long uploaderId) {
PictureGenerateResponse foundPictureGenerateResponse = pictureGenerateResponseRepository.findById(
pictureGenerateResponseId)
.orElseThrow(() -> new ExpectedException(ErrorCode.PictureGenerateResponseNotFound));

List<PictureCreatedByCreator> newUploadPictures = updatePictureUrlRequestDtoList.stream()
.map(d -> new PictureCreatedByCreator(d.getUrl(), foundPictureGenerateResponse))
.map(d -> new PictureCreatedByCreator(d.getUrl(), foundPictureGenerateResponse, uploaderId))
.toList();

pictureCreatedByCreatorRepository.saveAll(newUploadPictures);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.gt.genti.command;

import com.gt.genti.domain.PictureGenerateResponse;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class CreatePictureCompletedCommand {
String url;
PictureGenerateResponse pictureGenerateResponse;
Long uploadedBy;

@Builder
public CreatePictureCompletedCommand(String url, PictureGenerateResponse pictureGenerateResponse, Long uploadedBy) {
this.url = url;
this.pictureGenerateResponse = pictureGenerateResponse;
this.uploadedBy = uploadedBy;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.gt.genti.command;

import com.gt.genti.domain.PictureGenerateResponse;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class CreatePictureCreatedByCreatorCommand {
String url;
PictureGenerateResponse pictureGenerateResponse;
Long uploadedBy;
}
19 changes: 19 additions & 0 deletions src/main/java/com/gt/genti/command/CreatePicturePoseCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.gt.genti.command;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class CreatePicturePoseCommand {
String url;
Long uploadedBy;

@Builder
public CreatePicturePoseCommand(String url, Long uploadedBy) {
this.url = url;
this.uploadedBy = uploadedBy;
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/gt/genti/command/CreatePicturePostCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.gt.genti.command;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class CreatePicturePostCommand {
String url;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.gt.genti.command;

import com.gt.genti.domain.User;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class CreatePictureProfileCommand {
String url;
User user;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.gt.genti.command;

import com.gt.genti.domain.User;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class CreatePictureUserFaceCommand {
String url;
User user;
}
4 changes: 2 additions & 2 deletions src/main/java/com/gt/genti/domain/PictureCompleted.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gt.genti.domain;

import com.gt.genti.domain.common.BaseTimeEntity;
import com.gt.genti.domain.common.PictureEntity;

import jakarta.persistence.Column;
Expand Down Expand Up @@ -33,10 +32,11 @@ public class PictureCompleted extends PictureEntity {
PictureGenerateResponse pictureGenerateResponse;

@Builder
public PictureCompleted(String url, PictureGenerateResponse pictureGenerateResponse) {
public PictureCompleted(String url, PictureGenerateResponse pictureGenerateResponse, Long uploadedBy) {

this.url = url;
this.pictureGenerateResponse = pictureGenerateResponse;
this.setUploadedBy(uploadedBy);
}

public void modify(String url) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gt.genti.domain;

import com.gt.genti.domain.common.BaseTimeEntity;
import com.gt.genti.domain.common.PictureEntity;

import jakarta.persistence.Column;
Expand Down Expand Up @@ -33,10 +32,11 @@ public class PictureCreatedByCreator extends PictureEntity {
PictureGenerateResponse pictureGenerateResponse;

@Builder
public PictureCreatedByCreator(String url, PictureGenerateResponse pictureGenerateResponse) {
public PictureCreatedByCreator(String url, PictureGenerateResponse pictureGenerateResponse, Long uploadedBy) {

this.url = url;
this.pictureGenerateResponse = pictureGenerateResponse;
this.setUploadedBy(uploadedBy);
}

public void modify(String url) {
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/gt/genti/domain/PicturePose.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ public class PicturePose extends PictureEntity {
@Column(name = "url", nullable = false)
String url;

@Builder
public PicturePose(Long id, String url) {
this.id = id;
public PicturePose(String url, Long uploadedBy) {
this.url = url;
this.setUploadedBy(uploadedBy);
}

public PicturePose(String url) {
this.url = url;
}

public void modify(String modifyPosePictureUrl) {
this.url = modifyPosePictureUrl;
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/gt/genti/domain/PicturePost.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gt.genti.domain;

import com.gt.genti.domain.common.BaseTimeEntity;
import com.gt.genti.domain.common.PictureEntity;

import jakarta.persistence.Column;
Expand All @@ -10,10 +9,8 @@
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -33,9 +30,8 @@ public class PicturePost extends PictureEntity {
@Column(name = "url", nullable = false)
String url;

@Builder
public PicturePost(Long id, String url) {
this.id = id;
public PicturePost(String url, Post post) {
this.url = url;
this.post = post;
}
}
9 changes: 3 additions & 6 deletions src/main/java/com/gt/genti/domain/PictureProfile.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gt.genti.domain;

import com.gt.genti.domain.common.BaseTimeEntity;
import com.gt.genti.domain.common.PictureEntity;

import jakarta.persistence.Column;
Expand All @@ -11,7 +10,6 @@
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -30,13 +28,12 @@ public class PictureProfile extends PictureEntity {
@Column(name = "url", nullable = false)
String url;

@Builder
public PictureProfile(Long id, String url) {
this.id = id;
public PictureProfile(String url, User user) {
this.url = url;
this.user = user;
}

public void modify(String url){
public void modify(String url) {
this.url = url;
}
}
Loading

0 comments on commit ef91d47

Please sign in to comment.