Skip to content

Commit

Permalink
Merge pull request #67 from Genti2024/feat/admin-userview
Browse files Browse the repository at this point in the history
Fix: 사진생성요청상태확인 api, 공급자 탈퇴 로직 구현 및 12시간 미매칭 검사 로직 구현, 매칭 로직 내 각종 버그 수정 , 로그인 api cors 오류 수정
  • Loading branch information
LeeJae-H authored Jul 23, 2024
2 parents 075ec47 + 84f9caa commit b5c54b4
Show file tree
Hide file tree
Showing 68 changed files with 1,846 additions and 1,059 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import com.gt.genti.user.repository.UserRepository;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Transactional
@Service
@RequiredArgsConstructor
Expand All @@ -22,7 +24,12 @@ public User getAdminUser(){
return userRepository.findAdminUser(PageRequest.of(0,1)).get(0);
}
public Creator getAdminCreator(){
return creatorRepository.findAdminCreator(PageRequest.of(0,1)).get(0);
try{
return creatorRepository.findAdminCreator(PageRequest.of(0,1)).get(0);
} catch (Exception e){
log.error("어드민 유저가 존재하지 않습니다.");
return null;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
@RequestMapping("/api/v1/admin/match-strategy")
@RequiredArgsConstructor
public class AdminMatchStrategyController {
private final RequestMatchService requestMatchService;
@Operation(summary = "매칭전략 조회", description = "현재 시스템의 매칭전략을 조회합니다.", hidden = true)
@EnumResponses(value = {
@EnumResponse(ResponseCode.OK)
})
@GetMapping
public ResponseEntity<ApiResult<String>> getMatchStrategy() {
return success(RequestMatchService.CURRENT_STRATEGY.getStringValue());
return success(requestMatchService.getCurrentStrategy().getStringValue());
}

@Deprecated
Expand All @@ -43,7 +44,7 @@ public ResponseEntity<ApiResult<String>> getMatchStrategy() {
public ResponseEntity<ApiResult<String>> setMatchStrategy(
@RequestBody MatchingStrategyUpdateRequestDto requestDto) {
return success(
RequestMatchService.changeMatchingStrategy(requestDto.getRequestMatchStrategy()).getResponse());
requestMatchService.changeMatchingStrategy(requestDto.getRequestMatchStrategy()).getResponse());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;

import com.gt.genti.picturegeneraterequest.model.PictureGenerateRequestStatus;
import com.gt.genti.picturegenerateresponse.model.PictureGenerateResponseStatus;
import com.gt.genti.picturegeneraterequest.model.PictureGenerateRequest;
import com.gt.genti.picturegeneraterequest.port.PictureGenerateRequestPort;
import com.gt.genti.picturegeneraterequest.repository.PictureGenerateRequestRepository;
import com.gt.genti.picturegenerateresponse.model.PictureGenerateResponse;
import com.gt.genti.picturegenerateresponse.model.PictureGenerateResponseStatus;
import com.gt.genti.user.model.User;
import com.gt.genti.picturegeneraterequest.port.PictureGenerateRequestPort;

import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -42,12 +41,6 @@ public PictureGenerateRequest save(PictureGenerateRequest pictureGenerateRequest
return pictureGenerateRequestRepository.save(pictureGenerateRequest);
}

@Override
public Optional<PictureGenerateRequest> findByUserAndStatusInOrderByCreatedByDesc(User user,
List<PictureGenerateRequestStatus> statusList) {
return pictureGenerateRequestRepository.findByUserAndRequestStatusIn(user, statusList);
}

@Override
public Page<PictureGenerateRequest> findAll(Pageable pageable) {
return pictureGenerateRequestRepository.findAll(pageable);
Expand All @@ -56,12 +49,23 @@ public Page<PictureGenerateRequest> findAll(Pageable pageable) {
@Override
public Page<PictureGenerateResponse> findByPGRESStatusInAndMatchToAdminIs(
List<PictureGenerateResponseStatus> statusList, boolean matchToAdmin, Pageable pageable) {
return pictureGenerateRequestRepository.findByPictureGenerateResponseStatusInAndMatchToAdminIs(statusList, matchToAdmin, pageable);
return pictureGenerateRequestRepository.findByPictureGenerateResponseStatusInAndMatchToAdminIs(statusList,
matchToAdmin, pageable);
}

@Override
public Page<PictureGenerateRequest> findByMatchToAdminIs(boolean matchToAdmin, Pageable pageable) {
return pictureGenerateRequestRepository.findByMatchToAdminIs(matchToAdmin, pageable);

}

@Override
public Page<PictureGenerateRequest> findAllByRequester(User foundUser, Pageable pageable) {
return pictureGenerateRequestRepository.findAllByRequester(foundUser, pageable);
}

@Override
public Optional<PictureGenerateRequest> findTopByRequesterOrderByCreatedAtDesc(User foundUser) {
return pictureGenerateRequestRepository.findTopByRequesterOrderByCreatedAtDesc(foundUser);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gt.genti.picturegeneraterequest.controller;

import java.util.List;
import static com.gt.genti.response.GentiResponse.*;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand All @@ -12,24 +12,25 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gt.genti.error.ResponseCode;
import com.gt.genti.model.LogAction;
import com.gt.genti.model.LogItem;
import com.gt.genti.model.LogRequester;
import com.gt.genti.model.Logging;
import com.gt.genti.picturegenerateresponse.model.PictureGenerateResponseStatus;
import com.gt.genti.error.ResponseCode;
import com.gt.genti.picturegeneraterequest.dto.response.PGREQDetailFindByAdminResponseDto;
import com.gt.genti.picturegeneraterequest.dto.response.PGREQAdminMatchedDetailFindByAdminResponseDto;
import com.gt.genti.picturegeneraterequest.dto.response.PGREQCreatorSubmittedDetailFindByAdminResponseDto;
import com.gt.genti.picturegenerateresponse.service.mapper.PictureGenerateResponseStatusForAdmin;
import com.gt.genti.swagger.EnumResponse;
import com.gt.genti.swagger.EnumResponses;
import com.gt.genti.usecase.PictureGenerateRequestUseCase;
import com.gt.genti.response.GentiResponse;
import com.gt.genti.response.GentiResponse.ApiResult;
import com.gt.genti.validator.ValidEnum;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
Expand All @@ -41,13 +42,55 @@
public class AdminPGREQController {
private final PictureGenerateRequestUseCase pictureGenerateRequestUseCase;

@Operation(summary = "사진생성요청 전체조회", description = "사진생성요청 전체를 매칭대상(어드민,공급자), 응답의 상태를 조건으로 조회하고 페이지네이션 조회합니다.")
@Operation(summary = "어드민에게 매칭된 사진생성요청 전체조회", description = "사진생성요청 전체를 매칭대상(어드민,공급자), 응답의 상태를 조건으로 조회하고 페이지네이션 조회합니다.")
@EnumResponses(value = {
@EnumResponse(ResponseCode.OK)
})
@Logging(item = LogItem.PGREQ, action = LogAction.VIEW, requester = LogRequester.ADMIN)
@GetMapping("/admin-matched")
public ResponseEntity<ApiResult<Page<PGREQAdminMatchedDetailFindByAdminResponseDto>>> getAllAdminMatchedPGREQ(
@Parameter(description = "페이지 번호 (0-based)", example = "0", required = true)
@RequestParam(name = "page", defaultValue = "0") @NotNull @Min(0) int page,
@Parameter(description = "페이지 당 요소 개수 >=1", example = "10", required = true)
@RequestParam(name = "size", defaultValue = "10") @NotNull @Min(1) int size,
@Parameter(description = "정렬 조건 - 기본값 생성일시", example = "createdAt", schema = @Schema(allowableValues = {"id",
"createdAt"}))
@RequestParam(name = "sortBy", defaultValue = "createdAt") String sortBy,
@Parameter(description = "정렬 방향 - 기본값 내림차순", example = "desc", schema = @Schema(allowableValues = {"acs",
"desc"}))
@RequestParam(name = "direction", defaultValue = "desc") String direction,
@Parameter(description = "현재 작업(사진생성응답)의 상태로 조회한다. ALL 조회 가능, EXPIRED는 MVP상 도메인로직엔 없지만 어드민페이지의 성격 상 필요하다고 생각하여 추가했습니다.",
examples = {@ExampleObject(name = "BEFORE_WORK", description = "작업 대기", value = "BEFORE_WORK"),
@ExampleObject(name = "IN_PROGRESS", description = "작업 중", value = "IN_PROGRESS"),
@ExampleObject(name = "COMPLETED", description = "작업 완료", value = "COMPLETED"),
@ExampleObject(name = "EXPIRED", description = "만료됨 (기존의 협의된 내용은 아니지만 어드민페이지에 필요하다고 생각했습니다. 추가 부탁드립니다.)", value = "EXPIRED"),
@ExampleObject(name = "ALL", description = "전체", value = "ALL")})
@RequestParam(name = "status", defaultValue = "ALL")
@ValidEnum(value = PictureGenerateResponseStatusForAdmin.class, hasAllOption = true) String status,
@Parameter(description = "유저의 email")
@RequestParam(name = "email", required = false) @Email(message = "올바른 email 형식이 아닙니다.") String email
) {
Sort.Direction sortDirection = Sort.Direction.fromString(direction);
Pageable pageable = PageRequest.of(page, size, Sort.by(sortDirection, sortBy));
if (email != null) {
return success(
pictureGenerateRequestUseCase.getAllAdminMatchedByRequesterEmail(email, pageable));
}
if ("ALL".equalsIgnoreCase(status)) {
return success(pictureGenerateRequestUseCase.getAllAdminMatched(pageable));
} else {
return success(pictureGenerateRequestUseCase.getAllAdminMatchedByPGRESStatus(
PictureGenerateResponseStatusForAdmin.valueOf(status), pageable));
}
}

@Operation(summary = "공급자->어드민(얼굴붙여야하는 요청)", description = "사진생성요청 전체를 매칭대상(어드민,공급자), 응답의 상태를 조건으로 조회하고 페이지네이션 조회합니다.")
@EnumResponses(value = {
@EnumResponse(ResponseCode.OK)
})
@Logging(item = LogItem.PGREQ, action = LogAction.VIEW, requester = LogRequester.ADMIN)
@GetMapping("/all")
public ResponseEntity<ApiResult<Page<PGREQDetailFindByAdminResponseDto>>> getAllPictureGenerateRequest(
@GetMapping("/creator-submitted")
public ResponseEntity<ApiResult<Page<PGREQCreatorSubmittedDetailFindByAdminResponseDto>>> getAllCreatorSubmittedPGREQ(
@Parameter(description = "페이지 번호 (0-based)", example = "0", required = true)
@RequestParam(name = "page", defaultValue = "0") @NotNull @Min(0) int page,
@Parameter(description = "페이지 당 요소 개수 >=1", example = "10", required = true)
Expand All @@ -58,19 +101,27 @@ public ResponseEntity<ApiResult<Page<PGREQDetailFindByAdminResponseDto>>> getAll
@Parameter(description = "정렬 방향 - 기본값 내림차순", example = "desc", schema = @Schema(allowableValues = {"acs",
"desc"}))
@RequestParam(name = "direction", defaultValue = "desc") String direction,
@Parameter(description = "사진생성응답의 상태 ALL : 모든 상태 조회 SUBMITTED_FIRST : 공급자가 제출하여 어드민이 얼굴작업해야하는상태", example = "ADMIN_IN_PROGRESS", schema = @Schema(
allowableValues = {"SUBMITTED_FIRST", "ADMIN_IN_PROGRESS", "SUBMITTED_FINAL", "COMPLETED", "ALL"}))
@RequestParam(name = "status", defaultValue = "ALL") @ValidEnum(value = PictureGenerateResponseStatus.class, hasAllOption = true) String status,
@Parameter(description = "true : 공급자를 거치지 않고 어드민에게 매칭된 요청 조회, false : 공급자에게 매칭된 요청 조회")
@RequestParam(name = "matchToAdmin", defaultValue = "ALL") Boolean matchToAdmin
@Parameter(description = "현재 작업(사진생성응답)의 상태로 조회한다. ALL 조회 가능, EXPIRED는 MVP상 도메인로직엔 없지만 어드민페이지의 성격 상 필요하다고 생각하여 추가했습니다.",
examples = {@ExampleObject(name = "BEFORE_WORK", description = "작업 대기", value = "BEFORE_WORK"),
@ExampleObject(name = "IN_PROGRESS", description = "작업 중", value = "IN_PROGRESS"),
@ExampleObject(name = "COMPLETED", description = "작업 완료", value = "COMPLETED"),
@ExampleObject(name = "EXPIRED", description = "만료됨 (기존의 협의된 내용은 아니지만 어드민페이지에 필요하다고 생각했습니다. 추가 부탁드립니다.)", value = "EXPIRED"),
@ExampleObject(name = "ALL", description = "전체", value = "ALL")})
@RequestParam(name = "status", defaultValue = "ALL") @ValidEnum(value = PictureGenerateResponseStatusForAdmin.class, hasAllOption = true) String status,
@Parameter(description = "유저의 email")
@RequestParam(name = "email", required = false) @Email(message = "올바른 email 형식이 아닙니다.") String email
) {
Sort.Direction sortDirection = Sort.Direction.fromString(direction);
Pageable pageable = PageRequest.of(page, size, Sort.by(sortDirection, sortBy));
if (email != null) {
return success(
pictureGenerateRequestUseCase.getAllCreatorSubmittedByRequesterEmail(email, pageable));
}
if ("ALL".equalsIgnoreCase(status)) {
return GentiResponse.success(pictureGenerateRequestUseCase.getAllByMatchToAdminIs(matchToAdmin, pageable));
return success(pictureGenerateRequestUseCase.getAllCreatorSubmitted(pageable));
} else {
return GentiResponse.success(pictureGenerateRequestUseCase.getAllByPGRESStatusInAndMatchToAdminIs(
List.of(PictureGenerateResponseStatus.valueOf(status)), matchToAdmin, pageable));
return success(pictureGenerateRequestUseCase.getAllCreatorSubmittedByPGRESStatus(
PictureGenerateResponseStatusForAdmin.valueOf(status), pageable));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.gt.genti.picturegeneraterequest.controller;

import static com.gt.genti.response.GentiResponse.*;

import java.util.List;

import org.springframework.http.ResponseEntity;
Expand All @@ -15,11 +17,8 @@
import com.gt.genti.model.LogRequester;
import com.gt.genti.model.Logging;
import com.gt.genti.picturegeneraterequest.dto.response.PGREQBriefFindByCreatorResponseDto;
import com.gt.genti.picturegeneraterequest.dto.response.PGREQDetailFindByAdminResponseDto;
import com.gt.genti.picturegeneraterequest.model.PictureGenerateRequestStatus;
import com.gt.genti.picturegenerateresponse.service.PictureGenerateWorkService;
import com.gt.genti.response.GentiResponse;
import com.gt.genti.response.GentiResponse.ApiResult;
import com.gt.genti.swagger.EnumResponse;
import com.gt.genti.swagger.EnumResponses;
import com.gt.genti.user.model.AuthUser;
Expand Down Expand Up @@ -47,7 +46,7 @@ public class CreatorPGREQController {
public ResponseEntity<ApiResult<PGREQBriefFindByCreatorResponseDto>> getAssignedPictureGenerateRequestBrief(
@AuthUser Long userId
) {
return GentiResponse.success(pictureGenerateWorkService.getPictureGenerateRequestBrief(
return success(pictureGenerateWorkService.getPictureGenerateRequestBrief(
userId, PictureGenerateRequestStatus.ASSIGNING));
}

Expand All @@ -64,7 +63,7 @@ public ResponseEntity<ApiResult<Boolean>> acceptPictureGenerateRequest(
@AuthUser Long userId,
@Parameter(description = "수락할 사진생성요청의 id", example = "1")
@PathVariable(value = "pictureGenerateRequestId") Long pictureGenerateRequestId) {
return GentiResponse.success(
return success(
pictureGenerateWorkService.acceptPictureGenerateRequest(userId, pictureGenerateRequestId));
}

Expand All @@ -81,7 +80,7 @@ public ResponseEntity<ApiResult<Boolean>> rejectPictureGenerateRequest(
@AuthUser Long userId,
@Parameter(description = "거절할 사진생성요청의 id", example = "1")
@PathVariable(value = "pictureGenerateRequestId") Long pictureGenerateRequestId) {
return GentiResponse.success(
return success(
pictureGenerateWorkService.rejectPictureGenerateRequest(userId, pictureGenerateRequestId));
}

Expand All @@ -92,10 +91,10 @@ public ResponseEntity<ApiResult<Boolean>> rejectPictureGenerateRequest(
})
@Logging(item = LogItem.PGREQ_INPROGESS, action = LogAction.SEARCH, requester = LogRequester.CREATOR)
@GetMapping("/in-progress")
public ResponseEntity<ApiResult<List<PGREQDetailFindByAdminResponseDto>>> getInProgressPictureGenerateRequestDetail(
public ResponseEntity<ApiResult<List<PGREQBriefFindByCreatorResponseDto>>> getInProgressPictureGenerateRequestDetail(
@AuthUser Long userId
) {
return GentiResponse.success(pictureGenerateWorkService.getPictureGenerateRequestDetail3(userId));
return success(pictureGenerateWorkService.getPictureGenerateRequestDetail3(userId));
}

@Deprecated
Expand All @@ -105,9 +104,9 @@ public ResponseEntity<ApiResult<List<PGREQDetailFindByAdminResponseDto>>> getInP
})
@Logging(item = LogItem.PGREQ, action = LogAction.VIEW, requester = LogRequester.CREATOR)
@GetMapping("/all")
public ResponseEntity<ApiResult<List<PGREQDetailFindByAdminResponseDto>>> getAssignedPictureGenerateRequestsAll(
public ResponseEntity<ApiResult<List<PGREQBriefFindByCreatorResponseDto>>> getAssignedPictureGenerateRequestsAll(
@AuthUser Long userId) {
return GentiResponse.success(pictureGenerateWorkService.getPictureGenerateRequestDetailAll(
return success(pictureGenerateWorkService.getPictureGenerateRequestDetailAll(
userId));
}

Expand All @@ -118,11 +117,11 @@ public ResponseEntity<ApiResult<List<PGREQDetailFindByAdminResponseDto>>> getAss
})
@Logging(item = LogItem.PGREQ, action = LogAction.SEARCH, requester = LogRequester.CREATOR)
@GetMapping("/{pictureGenerateRequestId}")
public ResponseEntity<ApiResult<PGREQDetailFindByAdminResponseDto>> getPictureGenerateRequestDetail(
public ResponseEntity<ApiResult<PGREQBriefFindByCreatorResponseDto>> getPictureGenerateRequestDetail(
@AuthUser Long userId,
@Parameter(description = "조회할 사진생성요청의 id", example = "1")
@PathVariable(value = "pictureGenerateRequestId") Long pictureGenerateRequestId) {
return GentiResponse.success(pictureGenerateWorkService.getPictureGenerateRequestDetail(
return success(pictureGenerateWorkService.getPictureGenerateRequestDetail(
userId, pictureGenerateRequestId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ResponseEntity<ApiResult<List<PGREQBriefFindByUserResponseDto>>> getAllUs
@Operation(summary = "현재 진행중인 사진생성요청의 상태 조회", description = "작업이 진행중인 사진 생성요청이 있다면 해당 상태를 조회한다.")
@EnumResponses(value = {
@EnumResponse(ResponseCode.OK),
@EnumResponse(ResponseCode.PictureGenerateRequestNotFound)
@EnumResponse(ResponseCode.UserNotFound)
})
@Logging(item = LogItem.PGREQ_INPROGESS, action = LogAction.SEARCH, requester = LogRequester.USER)
@GetMapping("/pending")
Expand All @@ -67,6 +67,23 @@ public ResponseEntity<ApiResult<PGREQStatusResponseDto>> getPendingPGRESStatus(
pictureGenerateRequestUseCase.getPendingPGREQStatusIfExists(userId));
}

@Operation(summary = "취소된 사진생성요청 확인(폐기)처리", description = "사진생성요청이 오류로 인해 취소된 경우 실행하여 초기화한 후 새로운 요청을 할 수 있도록 변경")
@EnumResponses(value = {
@EnumResponse(ResponseCode.OK),
@EnumResponse(ResponseCode.UserNotFound)
})
@Logging(item = LogItem.PGREQ_CANCEL_VERIFY, action = LogAction.UPDATE, requester = LogRequester.USER)
@GetMapping("/{pictureGenerateRequestId}/confirm-cancel-status")
public ResponseEntity<ApiResult<Boolean>> confirmCanceledPGREQ(
@AuthUser Long userId,
@PathVariable(value = "pictureGenerateRequestId")
@Schema(description = "사진생성요청id", example = "1")
Long pictureGenerateRequestId
) {
return GentiResponse.success(
pictureGenerateRequestUseCase.confirmCanceledPGREQ(userId, pictureGenerateRequestId));
}

@Operation(summary = "사진생성요청하기", description = "사진생성요청을 생성한다.")
@EnumResponses(value = {
@EnumResponse(ResponseCode.OK)
Expand Down
Loading

0 comments on commit b5c54b4

Please sign in to comment.