From 8943a8fa262c0b745105a31817f58d546add3e0c Mon Sep 17 00:00:00 2001 From: LeeJaehyung <540900@naver.com> Date: Tue, 10 Dec 2024 17:39:29 +0900 Subject: [PATCH] =?UTF-8?q?Refactr:=20#218=20genti-api=20-=20responseexamp?= =?UTF-8?q?le=20=EA=B4=80=EB=A0=A8=20API=20=EB=B0=8F=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../responseexample/api/AdminExampleApi.java | 58 --------------- .../controller/AdminExampleController.java | 73 ------------------- .../service/ResponseExampleService.java | 18 ----- 3 files changed, 149 deletions(-) delete mode 100644 genti-api/src/main/java/com/gt/genti/responseexample/api/AdminExampleApi.java delete mode 100644 genti-api/src/main/java/com/gt/genti/responseexample/controller/AdminExampleController.java diff --git a/genti-api/src/main/java/com/gt/genti/responseexample/api/AdminExampleApi.java b/genti-api/src/main/java/com/gt/genti/responseexample/api/AdminExampleApi.java deleted file mode 100644 index 8fef38c1..00000000 --- a/genti-api/src/main/java/com/gt/genti/responseexample/api/AdminExampleApi.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.gt.genti.responseexample.api; - -import java.util.List; - -import org.springframework.data.domain.Page; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; - -import com.gt.genti.error.ResponseCode; -import com.gt.genti.response.GentiResponse.ApiResult; -import com.gt.genti.responseexample.dto.request.ExampleSaveRequestDto; -import com.gt.genti.responseexample.dto.response.ExampleWithPictureFindResponseDto; -import com.gt.genti.swagger.AuthorizedAdmin; -import com.gt.genti.swagger.EnumResponse; -import com.gt.genti.swagger.EnumResponses; -import com.gt.genti.swagger.RequireImageUpload; -import com.gt.genti.user.model.AuthUser; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.validation.Valid; -import jakarta.validation.constraints.Min; -import jakarta.validation.constraints.NotNull; - -@AuthorizedAdmin -@Tag(name = "[AdminExampleController] 어드민 사진생성결과 예시 컨트롤러", description = "사진생성결과 예시를 조회, 업로드 합니다.") -public interface AdminExampleApi { - - @Operation(summary = "전체 예시 조회", description = "전체 예시 사진&프롬프트를 페이지네이션 조회합니다.") - @EnumResponses(value = { - @EnumResponse(ResponseCode.OK) - }) - ResponseEntity>> getAllResponseExamples( - @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(0) 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 - ); - - @Operation(summary = "예시 생성", description = "예시 사진&프롬프트 추가합니다.") - @RequireImageUpload - @EnumResponses(value = { - @EnumResponse(ResponseCode.OK) - }) - ResponseEntity> addResponseExample( - @RequestBody @Valid List<@Valid ExampleSaveRequestDto> requestDtoList, - @AuthUser Long userId - ); -} diff --git a/genti-api/src/main/java/com/gt/genti/responseexample/controller/AdminExampleController.java b/genti-api/src/main/java/com/gt/genti/responseexample/controller/AdminExampleController.java deleted file mode 100644 index 6acfd06a..00000000 --- a/genti-api/src/main/java/com/gt/genti/responseexample/controller/AdminExampleController.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.gt.genti.responseexample.controller; - -import static com.gt.genti.response.GentiResponse.*; - -import java.util.List; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; -import org.springframework.http.ResponseEntity; -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.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -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.responseexample.api.AdminExampleApi; -import com.gt.genti.responseexample.dto.request.ExampleSaveRequestDto; -import com.gt.genti.responseexample.dto.response.ExampleWithPictureFindResponseDto; -import com.gt.genti.responseexample.service.ResponseExampleService; -import com.gt.genti.swagger.RequireImageUpload; -import com.gt.genti.user.model.AuthUser; - -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Schema; -import jakarta.validation.Valid; -import jakarta.validation.constraints.Min; -import jakarta.validation.constraints.NotNull; -import lombok.RequiredArgsConstructor; - -@RestController -@RequestMapping("/api/v1/admin/examples") -@RequiredArgsConstructor -public class AdminExampleController implements AdminExampleApi { - private final ResponseExampleService responseExampleService; - - @Logging(item = LogItem.RESPONSE_EXAMPLE, action = LogAction.VIEW, requester = LogRequester.ADMIN) - @GetMapping("/with-picture") - public ResponseEntity>> getAllResponseExamples( - @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(0) 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 - ) { - Sort.Direction sortDirection = Sort.Direction.fromString(direction); - Pageable pageable = PageRequest.of(page, size, Sort.by(sortDirection, sortBy)); - return success(responseExampleService.getAllResponseExamplesPagination(pageable)); - } - - @Logging(item = LogItem.RESPONSE_EXAMPLE, action = LogAction.CREATE, requester = LogRequester.ADMIN) - @PostMapping("/with-picture") - public ResponseEntity> addResponseExample( - @RequestBody @Valid List<@Valid ExampleSaveRequestDto> requestDtoList, - @AuthUser Long userId - ) { - responseExampleService.addResponseExamples( - requestDtoList.stream().map(ExampleSaveRequestDto::toCommand).toList(), userId); - return success(true); - } - -} \ No newline at end of file diff --git a/genti-api/src/main/java/com/gt/genti/responseexample/service/ResponseExampleService.java b/genti-api/src/main/java/com/gt/genti/responseexample/service/ResponseExampleService.java index 97bac40b..efe0ed47 100644 --- a/genti-api/src/main/java/com/gt/genti/responseexample/service/ResponseExampleService.java +++ b/genti-api/src/main/java/com/gt/genti/responseexample/service/ResponseExampleService.java @@ -30,11 +30,6 @@ public class ResponseExampleService { private final ResponseExampleRepository responseExampleRepository; private final UserRepository userRepository; - public Page getAllResponseExamplesPagination(Pageable pageable) { - return responseExampleRepository.findAllByPromptOnlyIsFalse(pageable) - .map(ExampleWithPictureFindResponseDto::new); - } - public List getAllResponseExamples() { List examples = responseExampleRepository.findAllByPromptOnlyIsFalse() .stream() @@ -55,19 +50,6 @@ public List getAllResponseExamples() { return examples; } - public void addResponseExamples(List commandList, - Long userId) { - User foundUploader = userRepository.findById(userId).orElseThrow(() -> ExpectedException.withLogging( - ResponseCode.UserNotFound, userId)); - responseExampleRepository.saveAll( - commandList.stream().map(command -> ResponseExample.builder() - .key(command.getKey()) - .uploadedBy(foundUploader) - .pictureRatio(command.getPictureRatio()) - .prompt(command.getPrompt()) - .build()).toList()); - } - public List getAllResponseExamplesInGenerateView() { final String type = "FREE_ONE"; List examples = responseExampleRepository.findAllByType(type)