diff --git a/src/main/java/com/pingpong/quoteBakery/app/controller/HomeController.java b/src/main/java/com/pingpong/quoteBakery/app/controller/HomeController.java index e5105b1..441d70c 100644 --- a/src/main/java/com/pingpong/quoteBakery/app/controller/HomeController.java +++ b/src/main/java/com/pingpong/quoteBakery/app/controller/HomeController.java @@ -32,9 +32,9 @@ public class HomeController { @GetMapping("/random-quote") @Operation(summary = "홈 화면 랜덤 명언 목록 조회", description = "홈 화면 랜덤 명언 목록 조회", - responses = { @ApiResponse(responseCode = "200", description = "조회 성공", content = @Content(schema = @Schema(implementation = RandomQuoteResource.class)))} + responses = { @ApiResponse(responseCode = "200", description = "조회 성공", content = @Content(schema = @Schema(implementation = QuoteResource.class)))} ) - public ApiRes> getRandomQuoteByUserId( + public ApiRes> getRandomQuoteByUserId( @Parameter(description = "페이지 번호") @RequestParam("page") int page, @Parameter(description = "페이지 당 항목 수") @RequestParam("sizePerPage") int sizePerPage, @Parameter(description = "사용자 ID") @RequestParam("userId") Long userId @@ -50,9 +50,9 @@ public ApiRes> getRandomQuoteByUserId( @GetMapping("/bake-quote") @Operation(summary = "홈 화면 랜덤 명언 굽기", description = "홈 화면 랜덤 명언 굽기", - responses = { @ApiResponse(responseCode = "200", description = "굽기 성공", content = @Content(schema = @Schema(implementation = RandomQuoteResource.class)))} + responses = { @ApiResponse(responseCode = "200", description = "굽기 성공", content = @Content(schema = @Schema(implementation = QuoteResource.class)))} ) - public ApiRes bakeRandomQuote( + public ApiRes bakeRandomQuote( @Parameter(description = "사용자ID") @RequestParam(value="userId", required=false) Long userId, @Parameter(description = "맛") @RequestParam(value="flavor", required=false) String flavor, @Parameter(description = "출처") @RequestParam(value="source", required=false) String source, diff --git a/src/main/java/com/pingpong/quoteBakery/app/controller/SearchController.java b/src/main/java/com/pingpong/quoteBakery/app/controller/SearchController.java index 280b7ea..2dfdfe2 100644 --- a/src/main/java/com/pingpong/quoteBakery/app/controller/SearchController.java +++ b/src/main/java/com/pingpong/quoteBakery/app/controller/SearchController.java @@ -4,9 +4,11 @@ import com.pingpong.quoteBakery.app.resource.QuoteConverter; import com.pingpong.quoteBakery.app.resource.QuoteResource; import com.pingpong.quoteBakery.app.resource.QuoteSearchResource; -import com.pingpong.quoteBakery.app.resource.RandomQuoteResource; import com.pingpong.quoteBakery.app.service.QuoteService; import com.pingpong.quoteBakery.com.api.response.ApiRes; +import com.pingpong.quoteBakery.sys.dto.UserDto; +import com.pingpong.quoteBakery.sys.service.TokenService; +import com.pingpong.quoteBakery.sys.service.UserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; @@ -28,18 +30,20 @@ public class SearchController { private final QuoteService quoteService; private final QuoteConverter quoteConverter; + private final TokenService tokenService; + private final UserService userService; /** * 명언탐색 */ @PostMapping("/quote") @Operation(summary = "명언 탐색", description = "조건에 맞게 명언을 탐색한다", - responses = { @ApiResponse(responseCode = "200", description = "조회 성공", content = @Content(schema = @Schema(implementation = RandomQuoteResource.class)))} + responses = { @ApiResponse(responseCode = "200", description = "조회 성공", content = @Content(schema = @Schema(implementation = QuoteResource.class)))} ) public ApiRes> searchQuotes(@RequestBody @io.swagger.v3.oas.annotations.parameters.RequestBody QuoteSearchResource searchResource){ - + UserDto userDto = userService.findByUid(tokenService.getCurrentTokenInfo().getUid()); return ApiRes.createSuccess(quoteService.searchQuotePages(quoteConverter.convertToGeneric(searchResource, QuoteMultiSearchDto.class), searchResource.getPageInfo()) - .map(dto -> quoteConverter.convertToGeneric(dto, QuoteResource.class))); + .map(quote -> quoteConverter.convertDtoToRandomResource(quote, userDto.getId()))); } } diff --git a/src/main/java/com/pingpong/quoteBakery/app/resource/QuoteConverter.java b/src/main/java/com/pingpong/quoteBakery/app/resource/QuoteConverter.java index c11466f..df1e7a2 100644 --- a/src/main/java/com/pingpong/quoteBakery/app/resource/QuoteConverter.java +++ b/src/main/java/com/pingpong/quoteBakery/app/resource/QuoteConverter.java @@ -17,17 +17,18 @@ @Component @RequiredArgsConstructor public class QuoteConverter extends CommonConverter { - // RandomQuoteResource는 항상 사용자별로 요청됨. - public RandomQuoteResource convertDtoToRandomResource(QuoteDto quoteDto, Long userId){ + public QuoteResource convertDtoToRandomResource(QuoteDto quoteDto, Long userId){ if(quoteDto == null) return null; - RandomQuoteResource resource = convertToGeneric(quoteDto, RandomQuoteResource.class); + QuoteResource resource = convertToGeneric(quoteDto, QuoteResource.class); - // 요청한 사용자가 좋아요/보관을 했는지 여부를 판단하여 세팅 + // 요청한 사용자가 좋아요했는지 여부를 판단하여 세팅 List likes = quoteDto.getLikes(); if(likes != null){ - long cnt = likes.stream().filter(likeDto -> likeDto.getUserId().equals(userId)).count(); - if(cnt > 0) { resource.setLikeYn(Boolean.TRUE); } else { resource.setLikeYn(Boolean.FALSE); } + resource.setLikeId( + likes.stream().filter(likeDto -> likeDto.getUserId().equals(userId)) + .findAny().orElseGet(LikeDto::new).getLikeId() + ); } return resource; } diff --git a/src/main/java/com/pingpong/quoteBakery/app/resource/QuoteResource.java b/src/main/java/com/pingpong/quoteBakery/app/resource/QuoteResource.java index 718fd6c..7e44250 100644 --- a/src/main/java/com/pingpong/quoteBakery/app/resource/QuoteResource.java +++ b/src/main/java/com/pingpong/quoteBakery/app/resource/QuoteResource.java @@ -28,5 +28,8 @@ public class QuoteResource extends BaseResource { @Schema(description = "상황") private String mood; + + @Schema(description = "좋아요ID") + private Long likeId; } diff --git a/src/main/java/com/pingpong/quoteBakery/app/resource/RandomQuoteResource.java b/src/main/java/com/pingpong/quoteBakery/app/resource/RandomQuoteResource.java deleted file mode 100644 index d96b98a..0000000 --- a/src/main/java/com/pingpong/quoteBakery/app/resource/RandomQuoteResource.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.pingpong.quoteBakery.app.resource; - -import com.pingpong.quoteBakery.com.resource.BaseResource; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Getter; -import lombok.Setter; - - -@Getter -@Setter -public class RandomQuoteResource extends BaseResource { - @Schema(description = "명언ID") - private Long quoteId; - - @Schema(description = "내용") - private String content; - - @Schema(description = "말한사람/콘텐츠명") - private String author; - - @Schema(description = "맛") - private String flavor; - - - @Schema(description = "출처") - private String source; - - - @Schema(description = "상황") - private String mood; - - - @Schema(description = "좋아요여부") - private Boolean likeYn; -} -