Skip to content

Commit

Permalink
fix: PageRequest의 인자 순서 바뀐 버그 수정 (#62)
Browse files Browse the repository at this point in the history
* fix: 피드 인자 순서 바뀐 것 수정

* test: 필터링 인수 테스트 작성
  • Loading branch information
donghoony committed Aug 17, 2023
1 parent 2401d3e commit 89dbd6e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.youcancook.gobong.domain.recipe.dto.feedfilterdto.FeedFilterDto;
import org.youcancook.gobong.domain.recipe.dto.feedfilterdto.ModifiedFeedFilterDto;
import org.youcancook.gobong.domain.recipe.dto.feedfilterdto.QueryType;
import org.youcancook.gobong.domain.recipe.dto.feedfilterdto.ModifiedFeedFilterDto;
import org.youcancook.gobong.domain.recipe.dto.feedfilterdto.QueryType;
import org.youcancook.gobong.domain.recipe.dto.response.GetFeedResponse;
import org.youcancook.gobong.domain.recipe.service.GetRecipeService;
import org.youcancook.gobong.global.resolver.LoginUserId;
Expand All @@ -23,7 +21,7 @@ public class FeedController {
@GetMapping("all")
public ResponseEntity<GetFeedResponse> getAllFeed(@LoginUserId Long userId,
@RequestParam(name = "last", required = false) Long lastRecipeId,
@RequestParam(name = "count", required = true) int count){
@RequestParam(name = "count") int count){
lastRecipeId = lastRecipeId == null ? Long.MAX_VALUE : lastRecipeId;
GetFeedResponse response = getRecipeService.getAllFeed(userId, lastRecipeId, count);
return ResponseEntity.ok(response);
Expand All @@ -32,7 +30,7 @@ public ResponseEntity<GetFeedResponse> getAllFeed(@LoginUserId Long userId,
@GetMapping("bookmarked")
public ResponseEntity<GetFeedResponse> getBookmarkedFeed(@LoginUserId Long userId,
@RequestParam(name = "last", required = false) Long lastRecipeId,
@RequestParam(name = "count", required = true) int count){
@RequestParam(name = "count") int count){
lastRecipeId = lastRecipeId == null ? Long.MAX_VALUE : lastRecipeId;
GetFeedResponse response = getRecipeService.getBookmarkedFeed(userId, lastRecipeId, count);
return ResponseEntity.ok(response);
Expand All @@ -41,7 +39,7 @@ public ResponseEntity<GetFeedResponse> getBookmarkedFeed(@LoginUserId Long userI
@GetMapping("following")
public ResponseEntity<GetFeedResponse> getFollowingFeed(@LoginUserId Long userId,
@RequestParam(name = "last", required = false) Long lastRecipeId,
@RequestParam(name = "count", required = true) int count){
@RequestParam(name = "count") int count){
lastRecipeId = lastRecipeId == null ? Long.MAX_VALUE : lastRecipeId;
GetFeedResponse response = getRecipeService.getFollowingFeed(userId, lastRecipeId, count);
return ResponseEntity.ok(response);
Expand All @@ -50,7 +48,7 @@ public ResponseEntity<GetFeedResponse> getFollowingFeed(@LoginUserId Long userId
@GetMapping("my")
public ResponseEntity<GetFeedResponse> getMyFeed(@LoginUserId Long userId,
@RequestParam(name = "last", required = false) Long lastRecipeId,
@RequestParam(name = "count", required = true) int count) {
@RequestParam(name = "count") int count) {
lastRecipeId = lastRecipeId == null ? Long.MAX_VALUE : lastRecipeId;
GetFeedResponse response = getRecipeService.getMyFeed(userId, lastRecipeId, count);
return ResponseEntity.ok(response);
Expand All @@ -60,21 +58,21 @@ public ResponseEntity<GetFeedResponse> getMyFeed(@LoginUserId Long userId,
public ResponseEntity<GetFeedResponse> getUserFeed(@LoginUserId Long myId,
@PathVariable Long userId,
@RequestParam(name = "last", required = false) Long lastRecipeId,
@RequestParam(name = "count", required = true) int count) {
@RequestParam(name = "count") int count) {
lastRecipeId = lastRecipeId == null ? Long.MAX_VALUE : lastRecipeId;
GetFeedResponse response = getRecipeService.getUserFeed(userId, myId, lastRecipeId, count);
return ResponseEntity.ok(response);
}

@PostMapping("filter")
public ResponseEntity<GetFeedResponse> getFilteredFeedByTitle(@LoginUserId Long userId,
@RequestParam(name = "page", required = true) int page,
@RequestParam(name = "count", required = true) int count,
@RequestParam(name = "page") int page,
@RequestParam(name = "count") int count,
@RequestBody @Valid FeedFilterDto filter){
ModifiedFeedFilterDto modifiedFilter = ModifiedFeedFilterDto.from(filter);
GetFeedResponse response = modifiedFilter.getQueryType() == QueryType.TITLE ?
getRecipeService.getFilteredFeedByName(userId, count, page, modifiedFilter) :
getRecipeService.getFilteredFeedByRecipeTitle(userId, count, page, modifiedFilter);
getRecipeService.getFilteredFeedByName(userId, page, count, modifiedFilter) :
getRecipeService.getFilteredFeedByRecipeTitle(userId, page, count, modifiedFilter);
return ResponseEntity.ok(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static ModifiedFeedFilterDto from(FeedFilterDto dto){
: List.of(Difficulty.from(dto.getDifficulty()));
modifiedDto.maxTotalCookTime = dto.getMaxTotalCookTime() == null ? Integer.MAX_VALUE : dto.getMaxTotalCookTime();
modifiedDto.minRating = dto.getMinRating() == null ? 0 : dto.getMinRating();
modifiedDto.cookwares = Cookware.namesToCookwareBit(dto.getCookwares());
modifiedDto.cookwares = dto.getCookwares() == null ? 0 : Cookware.namesToCookwareBit(dto.getCookwares());

return modifiedDto;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpStatus;
import org.youcancook.gobong.domain.recipe.dto.feedfilterdto.FeedFilterDto;
import org.youcancook.gobong.domain.recipe.dto.request.CreateRecipeRequest;
import org.youcancook.gobong.domain.recipe.dto.request.UpdateRecipeRequest;
import org.youcancook.gobong.domain.recipe.dto.response.CreateRecipeResponse;
Expand Down Expand Up @@ -229,4 +230,32 @@ public void getUserFeed() {
.statusCode(HttpStatus.OK.value())
.extract();
}

@Test
@DisplayName("필터링한 피드를 조회한다.")
public void getFilteredFeed() {
String accessToken1 = AcceptanceUtils.signUpAndGetToken("쩝쩝박사", "KAKAO", "123");
String accessToken2 = AcceptanceUtils.signUpAndGetToken("쩝쩝박사123", "KAKAO", "121233");

AcceptanceUtils.getUserIdFromToken(accessToken2);

for (int i = 1; i <= 10; i++) {
CreateRecipeRequest request = new CreateRecipeRequest("주먹밥", "레시피", List.of("밥", "김"), "쉬워요", null, List.of(
new UploadRecipeDetailRequest("소금간을 해 주세요", null, i, List.of("MICROWAVE")),
new UploadRecipeDetailRequest("주먹을 쥐어 밥을 뭉쳐주세요", null, i, List.of("PAN"))
));
AcceptanceUtils.createDummyRecipe(accessToken1, request);
}

FeedFilterDto feedFilterDto = new FeedFilterDto("주먹", "recent", "쉬워요", 13, null, null);

RestAssured.given().log().all()
.auth().oauth2(accessToken2)
.contentType(ContentType.JSON)
.body(feedFilterDto)
.when().post("/api/feed/filter?page=0&count=10")
.then().log().all()
.statusCode(HttpStatus.OK.value())
.extract();
}
}

0 comments on commit 89dbd6e

Please sign in to comment.