Skip to content

Commit

Permalink
🐛[fix]: replcae likeYn to likeId
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyesooo committed Nov 4, 2023
1 parent c222d43 commit a14e192
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Page<RandomQuoteResource>> getRandomQuoteByUserId(
public ApiRes<Page<QuoteResource>> getRandomQuoteByUserId(
@Parameter(description = "페이지 번호") @RequestParam("page") int page,
@Parameter(description = "페이지 당 항목 수") @RequestParam("sizePerPage") int sizePerPage,
@Parameter(description = "사용자 ID") @RequestParam("userId") Long userId
Expand All @@ -50,9 +50,9 @@ public ApiRes<Page<RandomQuoteResource>> 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<RandomQuoteResource> bakeRandomQuote(
public ApiRes<QuoteResource> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Page<QuoteResource>> 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())));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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<LikeDto> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ public class QuoteResource extends BaseResource {

@Schema(description = "상황")
private String mood;

@Schema(description = "좋아요ID")
private Long likeId;
}

This file was deleted.

0 comments on commit a14e192

Please sign in to comment.