-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from Bab-Al/feat/26-recipe
✨ [FEAT] RECIPE API
- Loading branch information
Showing
14 changed files
with
394 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,7 @@ out/ | |
.vscode/ | ||
|
||
## yml | ||
**/application.properties | ||
**/application.properties | ||
/venv/ | ||
/RecBole_Sys/ | ||
/log/ |
54 changes: 54 additions & 0 deletions
54
src/main/java/BabAl/BabalServer/controller/RecipeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package BabAl.BabalServer.controller; | ||
|
||
import BabAl.BabalServer.apiPayload.ApiResponse; | ||
import BabAl.BabalServer.dto.request.RecipeRecommendationsDto; | ||
import BabAl.BabalServer.dto.response.RecipeIngredientsResponseDto; | ||
import BabAl.BabalServer.dto.response.RecipeRecommendationsResponseDto; | ||
import BabAl.BabalServer.jwt.JwtUtil; | ||
import BabAl.BabalServer.service.RecipeService; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.w3c.dom.stylesheets.LinkStyle; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/recipe") | ||
@Tag(name = "Recipe Recommendation Page", description = "Recipe API") | ||
public class RecipeController { | ||
|
||
private final RecipeService recipeService; | ||
|
||
@GetMapping("/ingredients") // 레시피 재료 검색 | ||
@Operation(summary = "레시피 재료 검색", description = "레시피 재료 검색할 때 사용하는 API") | ||
@ApiResponses(value = { | ||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "요청이 정상 처리되었습니다", content = @Content(mediaType = "application/json")), | ||
}) | ||
public ApiResponse<RecipeIngredientsResponseDto> getIngredients(@RequestParam String alpha) throws JsonProcessingException { | ||
return ApiResponse.onSuccess(recipeService.getIngredients(alpha)); | ||
} | ||
|
||
@PostMapping("/recommendation") // 재료를 입력하면 사용자 프로필과 재료로 레시피 추천 | ||
@Operation(summary = "레시피 추천", description = "레시피 추천받을 때 사용하는 API") | ||
@ApiResponses(value = { | ||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "요청이 정상 처리되었습니다", content = @Content(mediaType = "application/json")), | ||
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "MEMBER4001", description = "사용자가 없습니다", content = @Content(mediaType = "application/json")) | ||
}) | ||
public ApiResponse<List<RecipeRecommendationsResponseDto>> getRecommendations(@RequestHeader("Authorization") String token, | ||
@Valid @RequestBody RecipeRecommendationsDto dto) throws JsonProcessingException { | ||
return ApiResponse.onSuccess(recipeService.getRecommendations(extractUserEmail(token), dto)); | ||
} | ||
|
||
public String extractUserEmail(String token) { | ||
String jwtToken = token.substring(7); | ||
String userEmail = JwtUtil.getEmail(jwtToken); | ||
return userEmail; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/BabAl/BabalServer/dto/flaskRequest/IngredientAlpha.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package BabAl.BabalServer.dto.flaskRequest; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class IngredientAlpha { | ||
private String alphabet; | ||
|
||
public static IngredientAlpha ingredientAlpha(String alpha) { | ||
return IngredientAlpha.builder().alphabet(alpha).build(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/BabAl/BabalServer/dto/flaskRequest/RecipeRecommendation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package BabAl.BabalServer.dto.flaskRequest; | ||
|
||
import BabAl.BabalServer.domain.User; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class RecipeRecommendation { | ||
private List<String> ingredients; | ||
private List<String> tags; | ||
private String gender; | ||
private int age; | ||
|
||
public static RecipeRecommendation recipeRecommendation(Optional<User> user, List<String> ingredients) { | ||
return RecipeRecommendation.builder() | ||
.ingredients(ingredients) | ||
.tags(user.get().getTagList()) | ||
.gender(String.valueOf(user.get().getGender())) | ||
.age(user.get().getAge()) | ||
.build(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/BabAl/BabalServer/dto/flaskResponse/RecipeRecommendationResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package BabAl.BabalServer.dto.flaskResponse; | ||
|
||
import lombok.*; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class RecipeRecommendationResponse { | ||
private String name; | ||
private int minutes; | ||
private float calories; | ||
private float carbohydrate; | ||
private float protein; | ||
private float fat; | ||
private int n_steps; | ||
private String steps; | ||
private int n_ingredients; | ||
private List<String> ingredients; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/BabAl/BabalServer/dto/request/RecipeRecommendationsDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package BabAl.BabalServer.dto.request; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class RecipeRecommendationsDto { | ||
private List<String> ingredients; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/BabAl/BabalServer/dto/response/RecipeIngredientsResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package BabAl.BabalServer.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class RecipeIngredientsResponseDto { | ||
private int count; | ||
private List<String> ingredients; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/BabAl/BabalServer/dto/response/RecipeRecommendationListResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package BabAl.BabalServer.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class RecipeRecommendationListResponseDto { | ||
RecipeRecommendationsResponseDto mine; | ||
RecipeRecommendationsResponseDto others; | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/BabAl/BabalServer/dto/response/RecipeRecommendationsResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package BabAl.BabalServer.dto.response; | ||
|
||
import BabAl.BabalServer.dto.flaskResponse.RecipeRecommendationResponse; | ||
import lombok.*; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class RecipeRecommendationsResponseDto { | ||
private String name; | ||
private int minutes; | ||
private float calories; | ||
private float carbohydrate; | ||
private float protein; | ||
private float fat; | ||
private int n_steps; | ||
private List<String> steps; | ||
private int n_ingredients; | ||
private List<String> ingredients; | ||
|
||
public static RecipeRecommendationsResponseDto recipeRecommendationsResponse(RecipeRecommendationResponse dto, List<String> stepList) { | ||
return RecipeRecommendationsResponseDto.builder() | ||
.name(dto.getName()) | ||
.minutes(dto.getMinutes()) | ||
.calories(dto.getCalories()) | ||
.carbohydrate(dto.getCarbohydrate()) | ||
.protein(dto.getProtein()) | ||
.fat(dto.getFat()) | ||
.n_steps(dto.getN_steps()) | ||
.steps(stepList) | ||
.n_ingredients(dto.getN_ingredients()) | ||
.ingredients(dto.getIngredients()) | ||
.build(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/BabAl/BabalServer/service/RecipeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package BabAl.BabalServer.service; | ||
|
||
import BabAl.BabalServer.dto.request.RecipeRecommendationsDto; | ||
import BabAl.BabalServer.dto.response.RecipeIngredientsResponseDto; | ||
import BabAl.BabalServer.dto.response.RecipeRecommendationsResponseDto; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
|
||
import java.util.List; | ||
|
||
public interface RecipeService { | ||
|
||
// 레시피 검색 | ||
RecipeIngredientsResponseDto getIngredients(String alpha) throws JsonProcessingException; | ||
|
||
// 레시피 추천 | ||
List<RecipeRecommendationsResponseDto> getRecommendations(String userEmail, RecipeRecommendationsDto ingredients) throws JsonProcessingException; | ||
} |
Oops, something went wrong.