Skip to content

Commit

Permalink
Fix: Enum 수정으로 쿼리문 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
BYEONGRYEOL committed May 24, 2024
1 parent b7a6add commit 566d93f
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public ResponseEntity<ApiResult<PictureGenerateRequestBriefResponseDto>> getAssi
userDetails.getId(), PictureGenerateRequestStatus.ASSIGNING));
}

@GetMapping("/picture-generate-requests/in-progress")
public ResponseEntity<ApiResult<List<PictureGenerateRequestDetailResponseDto>>> getInProgressPictureGenerateRequestDetail(
@AuthenticationPrincipal UserDetailsImpl userDetails
) {
return success(pictureGenerateWorkService.getPictureGenerateRequestDetail3(userDetails.getId()));
}

@PostMapping("/picture-generate-requests/{pictureGenerateRequestId}/accept")
public ResponseEntity<ApiResult<Boolean>> acceptPictureGenerateRequest(
@AuthenticationPrincipal UserDetailsImpl userDetails,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.gt.genti.adapter.in.web;

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

import java.util.List;

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

import com.gt.genti.dto.AddPromptOnlyExampleRequestDto;
import com.gt.genti.dto.AddResponseExampleRequestDto;
import com.gt.genti.dto.PromptOnlyExampleResponseDto;
import com.gt.genti.dto.ResponseExampleResponseDto;
import com.gt.genti.other.auth.UserDetailsImpl;
import com.gt.genti.service.ResponseExampleService;

import lombok.RequiredArgsConstructor;

@RestController
@RequestMapping("/api/user/examples")
@RequiredArgsConstructor
public class UserExampleController {
private final ResponseExampleService responseExampleService;

@GetMapping("/with-picture")
public ResponseEntity<ApiResult<List<ResponseExampleResponseDto>>> getAllResponseExamples() {
return success(responseExampleService.getAllResponseExamples());
}

@GetMapping("/prompt-only")
public ResponseEntity<ApiResult<List<PromptOnlyExampleResponseDto>>> getAllPromptOnlyExamples() {
return success(responseExampleService.getAllPromptOnlyExamples());
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gt.genti.application.adapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -58,7 +59,12 @@ public PictureGenerateRequest save(PictureGenerateRequest pictureGenerateRequest
}

@Override
public Optional<PictureGenerateRequest> findByUserIdOrderByCreatedByDesc(Long userId) {
return pictureGenerateRequestRepository.findByUserIdOrderByCreatedByDesc(userId);
public Optional<PictureGenerateRequest> findByUserIdOrderByCreatedByDesc(Long requesterId) {

List<PictureGenerateRequestStatus> activeStatusList = new ArrayList<>();
activeStatusList.add(PictureGenerateRequestStatus.CREATED);
activeStatusList.add(PictureGenerateRequestStatus.ASSIGNING);
activeStatusList.add(PictureGenerateRequestStatus.IN_PROGRESS);
return pictureGenerateRequestRepository.findByUserIdAndRequestStatusIn(requesterId, activeStatusList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static com.gt.genti.other.util.TimeUtils.*;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
Expand All @@ -18,6 +19,7 @@
import com.gt.genti.domain.PictureGenerateResponse;
import com.gt.genti.domain.Settlement;
import com.gt.genti.domain.enums.PictureGenerateRequestStatus;
import com.gt.genti.domain.enums.PictureGenerateResponseStatus;
import com.gt.genti.dto.PictureGenerateRequestBriefResponseDto;
import com.gt.genti.dto.PictureGenerateRequestDetailResponseDto;
import com.gt.genti.dto.PictureGenerateResponseAdminSubmitDto;
Expand Down Expand Up @@ -80,8 +82,8 @@ public PictureGenerateRequestDetailResponseDto getPictureGenerateRequestDetail(L

}

public List<PictureGenerateRequestDetailResponseDto> getPictureGenerateRequestDetailAll(Long creatorId) {
Creator foundCreator = findCreatorByUserId(creatorId);
public List<PictureGenerateRequestDetailResponseDto> getPictureGenerateRequestDetailAll(Long userId) {
Creator foundCreator = findCreatorByUserId(userId);
List<PictureGenerateRequest> foundPGRList = pictureGenerateRequestRepository.findAllByCreatorIsOrderByCreatedAtDesc(
foundCreator);

Expand Down Expand Up @@ -228,5 +230,18 @@ public Boolean updatePictureListCreatedByAdmin(Long userId, List<UpdatePictureUr
pictureService.updatePictures(commandList);
return true;
}

public List<PictureGenerateRequestDetailResponseDto> getPictureGenerateRequestDetail3(Long userId) {
Creator foundCreator = findCreatorByUserId(userId);
List<PictureGenerateRequestStatus> activeRequestStatusList = new ArrayList<>();
activeRequestStatusList.add(PictureGenerateRequestStatus.IN_PROGRESS);

List<PictureGenerateResponseStatus> activeResponseStatusList = new ArrayList<>();
activeResponseStatusList.add(PictureGenerateResponseStatus.BEFORE_WORK);
List<PictureGenerateRequest> foundPGREQList = pictureGenerateRequestRepository.findByCreatorAndActiveStatus(
foundCreator, activeRequestStatusList, activeResponseStatusList);

return foundPGREQList.stream().map(PictureGenerateRequestDetailResponseDto::new).toList();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.gt.genti.domain.PictureGenerateRequest;
import com.gt.genti.domain.User;
import com.gt.genti.domain.enums.PictureGenerateRequestStatus;
import com.gt.genti.domain.enums.PictureGenerateResponseStatus;

@Repository
public interface PictureGenerateRequestRepository
Expand Down Expand Up @@ -57,10 +58,25 @@ Optional<PictureGenerateRequest> findByStatusOrderByCreatedAtDesc(Creator creato

@Query("select pgr from PictureGenerateRequest pgr "
+ "where pgr.requester.id = :userId "
+ "and pgr.pictureGenerateRequestStatus in ("
+ " com.gt.genti.domain.enums.PictureGenerateRequestStatus.ASSIGNING, "
+ " com.gt.genti.domain.enums.PictureGenerateRequestStatus.IN_PROGRESS) "
+ "and pgr.pictureGenerateRequestStatus in :statusList "
+ "order by pgr.createdAt desc "
+ "limit 1 ")
Optional<PictureGenerateRequest> findByUserIdOrderByCreatedByDesc(Long userId);
Optional<PictureGenerateRequest> findByUserIdAndRequestStatusIn(Long userId,
List<PictureGenerateRequestStatus> statusList);

//TODO 성능 이슈 때문에 dto를 select하도록 변경해야함
// edited at 2024-05-23
// author 서병렬

@Query("select pgreq from PictureGenerateRequest pgreq "
+ "join PictureGenerateResponse pgres "
+ "where pgres.request = pgreq "
+ "and pgres.status in :activeResponseStatusList "
+ "and pgreq.creator = :foundCreator "
+ "and pgreq.pictureGenerateRequestStatus in :activeRequestStatusList "
+ "order by pgreq.createdAt desc "
+ "limit 3 ")
List<PictureGenerateRequest> findByCreatorAndActiveStatus(Creator foundCreator,
List<PictureGenerateRequestStatus> activeRequestStatusList,
List<PictureGenerateResponseStatus> activeResponseStatusList);
}

0 comments on commit 566d93f

Please sign in to comment.