Skip to content

Commit

Permalink
Merge pull request #84 from zipdabang/feature/82
Browse files Browse the repository at this point in the history
Feature/82 ✨ 레시피 배너 api 추가, paging index 및 상세 레시피 응답 변경
  • Loading branch information
Hanvp authored Aug 29, 2023
2 parents 93e65bf + 04da463 commit 16115fa
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/main/java/zipdabang/server/base/Code.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public enum Code {
MEMBER_NOT_FOUND(HttpStatus.UNAUTHORIZED, 4052,"해당 사용자가 존재하지 않습니다"),
NO_CATEGORY_EXIST(HttpStatus.BAD_REQUEST, 4053, "선호하는 음료 카테고리가 잘못 되었습니다."),

UNDER_PAGE_INDEX_ERROR(HttpStatus.BAD_REQUEST, 4054, "페이지 번호는 0 이상이여야 합니다."),
UNDER_PAGE_INDEX_ERROR(HttpStatus.BAD_REQUEST, 4054, "페이지 번호는 1 이상이여야 합니다."),
OVER_PAGE_INDEX_ERROR(HttpStatus.BAD_REQUEST, 4055, "페이지 번호가 페이징 범위를 초과했습니다."),

PHONE_AUTH_NOT_FOUND(HttpStatus.BAD_REQUEST, 4056, "인증 번호 요청이 필요합니다."),
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/zipdabang/server/converter/RecipeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ public static RecipeResponseDto.RecipeStatusDto toRecipeStatusDto(Recipe recipe)
}


public static RecipeResponseDto.RecipeInfoDto toRecipeInfoDto(Recipe recipe, Boolean isOwner, Boolean isLiked, Boolean isScrapped) {
public static RecipeResponseDto.RecipeInfoDto toRecipeInfoDto(Recipe recipe, Boolean isOwner, Boolean isLiked, Boolean isScrapped, Member member) {
return RecipeResponseDto.RecipeInfoDto.builder()
.recipeInfo(toResponseRecipeDto(recipe, isLiked, isScrapped))
.recipeInfo(toResponseRecipeDto(recipe, isLiked, isScrapped, member))
.isOwner(isOwner)
.steps(toResponseStepDto(recipe))
.ingredients(toResponseIngredientDto(recipe))
Expand Down Expand Up @@ -163,12 +163,13 @@ public static List<Long> getCategoryIds(Recipe recipe){
.collect(Collectors.toList());
}

public static RecipeResponseDto.RecipeDto toResponseRecipeDto(Recipe recipe, Boolean isLiked, Boolean isScrapped){
public static RecipeResponseDto.RecipeDto toResponseRecipeDto(Recipe recipe, Boolean isLiked, Boolean isScrapped, Member member){

return RecipeResponseDto.RecipeDto.builder()
.recipeId(recipe.getId())
.categoryId(getCategoryIds(recipe))
.recipeName(recipe.getName())
.ownerImage(member.getProfileUrl())
.nickname(recipe.getMember().getNickname())
.thumbnailUrl(recipe.getThumbnailUrl())
.time(recipe.getTime())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import zipdabang.server.service.RecipeService;
import zipdabang.server.web.dto.requestDto.RecipeRequestDto;
import zipdabang.server.web.dto.responseDto.RecipeResponseDto;
import zipdabang.server.web.dto.responseDto.RootResponseDto;

import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -89,7 +90,7 @@ public ResponseDto<RecipeResponseDto.RecipeInfoDto> recipeDetail(@PathVariable(n
Boolean isLiked = recipeService.getLike(recipe, member);
Boolean isScrapped = recipeService.getScrap(recipe, member);

return ResponseDto.of(RecipeConverter.toRecipeInfoDto(recipe, isOwner, isLiked, isScrapped));
return ResponseDto.of(RecipeConverter.toRecipeInfoDto(recipe, isOwner, isLiked, isScrapped, member));
}

@Operation(summary = "🍹figma 나의 레시피 삭제_알럿, 레시피 삭제 API 🔑", description = "레시피 삭제 API입니다.")
Expand Down Expand Up @@ -119,31 +120,33 @@ public ResponseDto<RecipeResponseDto.RecipeStatusDto> deleteRecipe(@PathVariable
@ApiResponse(responseCode = "4005",description = "UNAUTHORIZED, 엑세스 토큰 만료, 리프레시 토큰 사용",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4008",description = "UNAUTHORIZED, 토큰 없음, 토큰 줘요",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4052",description = "BAD_REQUEST, 사용자가 없습니다. 이 api에서 이거 생기면 백앤드 개발자 호출",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4054",description = "BAD_REQUEST, 페이지 번호 -1 이하입니다. 0 이상으로 주세요.",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4049",description = "BAD_REQUEST, 페이지 인덱스 범위 초과함",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4054",description = "BAD_REQUEST, 페이지 번호 0 이하입니다. 1 이상으로 주세요.",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4055",description = "BAD_REQUEST, 페이지 인덱스 범위 초과함",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "5000",description = "SERVER ERROR, 백앤드 개발자에게 알려주세요",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
})
@Parameters({
@Parameter(name = "member", hidden = true),
@Parameter(name = "pageIndex", description = "query string 페이지 번호, 안주면 0으로(최초 페이지) 설정함, -1 이런거 주면 에러 뱉음"),
@Parameter(name = "pageIndex", description = "query string 페이지 번호, 안주면 1으로(최초 페이지) 설정함, 0 이런거 주면 에러 뱉음"),
@Parameter(name = "keyword", description = "query string 검색할 단어")
})
@GetMapping(value = "/members/recipes/search")
public ResponseDto<RecipeResponseDto.RecipePageListDto> searchRecipe(@RequestParam(name = "keyword", required = false) String keyword, @RequestParam(name = "pageIndex", required = false) Integer pageIndex, @AuthMember Member member){

if(pageIndex == null)
pageIndex = 0;
else if (pageIndex < 0)
pageIndex =1;
else if (pageIndex < 1)
throw new RecipeException(Code.UNDER_PAGE_INDEX_ERROR);

pageIndex -= 1;

Page<Recipe> recipes= recipeService.searchRecipe(keyword,pageIndex,member);

log.info(recipes.toString());

if(recipes.getTotalElements() == 0)
throw new RecipeException(Code.RECIPE_NOT_FOUND);
if(pageIndex >= recipes.getTotalPages())
throw new RecipeException(Code.OVER_PAGE_INDEX_ERROR);
if(recipes.getNumberOfElements() == 0)
throw new RecipeException(Code.RECIPE_NOT_FOUND);

return ResponseDto.of(RecipeConverter.toPagingRecipeDtoList(recipes, member));
}
Expand Down Expand Up @@ -270,4 +273,18 @@ public ResponseDto<RecipeResponseDto.RecipeStatusDto> recipeScrapOrCancel(@PathV
public ResponseDto<RecipeResponseDto.RecipeStatusDto> recipeLikeOrCancel(@PathVariable Long recipeId, @AuthMember Member member){
return null;
}

@Operation(summary = "레시피 배너 이미지 API 🔑", description = "레시피 화면의 배너 이미지를 가져옵니다. order는 배너 순서를 의미합니다.")
@ApiResponses({
@ApiResponse(responseCode = "2000",description = "OK 성공"),
@ApiResponse(responseCode = "4003",description = "UNAUTHORIZED, 토큰 모양이 이상함, 토큰 제대로 주세요",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4005",description = "UNAUTHORIZED, 엑세스 토큰 만료, 리프레시 토큰 사용",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4008",description = "UNAUTHORIZED, 토큰 없음, 토큰 줘요",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4052",description = "BAD_REQUEST, 사용자가 없습니다. 이 api에서 이거 생기면 백앤드 개발자 호출",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "5000",description = "SERVER ERROR, 백앤드 개발자에게 알려주세요",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
})
@GetMapping("/members/recipes/banners")
public ResponseDto<RecipeResponseDto.RecipeBannerImageDto> showBanners() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ public ResponseDto<RootResponseDto.BeverageCategoryListDto> showCategoryList(){
return ResponseDto.of(RootConverter.toBeverageCategoryListDto(allCategories));
}

@Operation(summary = "배너 이미지 APII️", description = "홈 화면의 배너 이미지를 가져옵니다. order는 배너 순서를 의미합니다.")
@Operation(summary = "배너 이미지 API 🔑", description = "홈 화면의 배너 이미지를 가져옵니다. order는 배너 순서를 의미합니다.")
@ApiResponses({
@ApiResponse(responseCode = "2000",description = "OK 성공, access Token과 refresh 토큰을 반환함"),
@ApiResponse(responseCode = "2000",description = "OK 성공"),
@ApiResponse(responseCode = "4003",description = "UNAUTHORIZED, 토큰 모양이 이상함, 토큰 제대로 주세요",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4005",description = "UNAUTHORIZED, 엑세스 토큰 만료, 리프레시 토큰 사용",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4008",description = "UNAUTHORIZED, 토큰 없음, 토큰 줘요",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "4052",description = "BAD_REQUEST, 사용자가 없습니다. 이 api에서 이거 생기면 백앤드 개발자 호출",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
@ApiResponse(responseCode = "5000",description = "SERVER ERROR, 백앤드 개발자에게 알려주세요",content = @Content(schema = @Schema(implementation = ResponseDto.class))),
})
@GetMapping("/banners")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public static class RecipeDto {
private Long recipeId;
List<Long> categoryId;
private String recipeName;
private String ownerImage;
private String nickname;
private String thumbnailUrl;
private String time;
Expand Down Expand Up @@ -121,4 +122,22 @@ public static class CommentDto{
private LocalDate createdAt;
}

@Builder
@Getter
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public static class RecipeBannerDto{
private Integer order;
private String imageUrl;
private String searchKeyword;
}

@Builder
@Getter
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public static class RecipeBannerImageDto {
List<RecipeBannerDto> bannerList;
Integer size;
}
}

0 comments on commit 16115fa

Please sign in to comment.