Skip to content

Commit

Permalink
Merge pull request #190 from Genti2024/feat/pgres-for-frontend
Browse files Browse the repository at this point in the history
Fix: #187 프론트엔드 개발자가 사용할 사진생성응답처리 api 추가(완료)
  • Loading branch information
LeeJae-H authored Oct 31, 2024
2 parents 7ae1b6c + 8eee765 commit 136ecc1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@ public class PGREQSaveRequestDto {
@Schema(description = "프롬프트", example = "벚꽃길에서 벤치에 앉아있는 사진이요")
String prompt;

@Schema(description = "포즈 사진")
CommonPictureKeyUpdateRequestDto posePicture;

@NotNull
@Size(max = 3, min = 1, message = "사용자의 얼굴 사진 개수는 최소 1개, 최대 3개입니다.")
@Schema(description = "얼굴 사진 리스트")
List<@NotNull CommonPictureKeyUpdateRequestDto> facePictureList;

@Schema(description = "카메라 앵글")
CameraAngle cameraAngle;

@Schema(description = "프레임")
ShotCoverage shotCoverage;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public interface FrontendPGRESApi {
@EnumResponse(ResponseCode.OK)
})
ResponseEntity<GentiResponse.ApiResult<Boolean>> finishPGRESByFrontend(
@AuthUser Long userId,
@RequestParam(name = "pictureRatio") @NotNull PictureRatio pictureRatio);
@AuthUser Long userId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Profile("staging")
@Profile({"staging", "local"})
@RestController
@RequestMapping("/api/v1/frontend/picture-generate-responses")
@RequiredArgsConstructor
Expand All @@ -23,10 +23,9 @@ public class FrontendPGRESController {

@PostMapping
ResponseEntity<GentiResponse.ApiResult<Boolean>> finishPGRESByFrontend(
@AuthUser Long userId,
@RequestParam(name = "pictureRatio") @NotNull PictureRatio pictureRatio
@AuthUser Long userId
){
return GentiResponse.success(pictureGenerateWorkService.finishPGRESByFrontend(userId, pictureRatio));
return GentiResponse.success(pictureGenerateWorkService.finishPGRESByFrontend(userId));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Optional;

import com.gt.genti.picture.PictureRatio;
import com.gt.genti.picture.completed.repository.PictureCompletedRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -52,6 +53,7 @@ public class PictureGenerateWorkService {
private final CreatorRepository creatorRepository;
private final PictureGenerateResponseRepository pictureGenerateResponseRepository;
private final PictureGenerateRequestRepository pictureGenerateRequestRepository;
private final PictureCompletedRepository pictureCompletedRepository;
private final SettlementRepository settlementRepository;
private final DepositRepository depositRepository;
private final RequestMatchService requestMatchService;
Expand Down Expand Up @@ -299,8 +301,35 @@ public void expire(PictureGenerateResponse pictureGenerateResponse) {

}

public Boolean finishPGRESByFrontend(Long userId, PictureRatio pictureRatio){
return true;
public Boolean finishPGRESByFrontend(Long userId){
User foundUser = findUserById(userId);
Optional<PictureGenerateRequest> pgreq = pictureGenerateRequestRepository.findTop1ByRequesterOrderByIdDesc(foundUser);
if (pgreq.isPresent()){
PictureGenerateRequest foundpgreq = pgreq.get();
if(foundpgreq.getPictureGenerateRequestStatus().equals(PictureGenerateRequestStatus.MATCH_TO_ADMIN)){
Optional<PictureGenerateResponse> pgres = pictureGenerateResponseRepository.findByRequest(pgreq.get());
if(pgres.isPresent()) {
PictureGenerateResponse foundpgres = pgres.get();
String key = switch (foundpgreq.getPictureRatio()) {
case PictureRatio.RATIO_GARO -> "DEV/ADMIN_UPLOADED_IMAGE/3.png";
case PictureRatio.RATIO_SERO -> "DEV/ADMIN_UPLOADED_IMAGE/1.png";
default -> "";
};
PictureCompleted pictureCompleted = PictureCompleted.builder()
.key(key)
.pictureGenerateResponse(foundpgres)
.uploadedBy(foundUser)
.requester(foundUser)
.pictureRatio(foundpgreq.getPictureRatio())
.build();
pictureCompletedRepository.save(pictureCompleted);
foundpgres.userVerified();
foundpgreq.userVerified();
return true;
}
}
}
return false;
}

private User findUserById(Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public interface PictureGenerateRequestRepository

List<PictureGenerateRequest> findAllByRequester(User requester);

Optional<PictureGenerateRequest> findTop1ByRequesterOrderByIdDesc(User requester);

Page<PictureGenerateRequest> findAllByRequester(User requester, Pageable pageable);

@Query("select pgr from PictureGenerateRequest pgr "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

import com.gt.genti.picturegeneraterequest.model.PictureGenerateRequest;
import org.springframework.data.jpa.repository.JpaRepository;

import com.gt.genti.picturegenerateresponse.model.PictureGenerateResponse;
import com.gt.genti.picturegenerateresponse.model.PictureGenerateResponseStatus;

public interface PictureGenerateResponseRepository extends JpaRepository<PictureGenerateResponse, Long> {
List<PictureGenerateResponse> findAllByCreatedAtBeforeAndStatusIs(LocalDateTime expireThreshold, PictureGenerateResponseStatus status);
Optional<PictureGenerateResponse> findByRequest(PictureGenerateRequest pictureGenerateRequest);
}

0 comments on commit 136ecc1

Please sign in to comment.