Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 취향 테스트, 레시피 관련 기능 개발 #17

Merged
merged 7 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Backend CD # actions 이름

on:
push:
branches: [ develop ]
branches: [ feature/#8 ]

jobs:
deploy:
Expand Down Expand Up @@ -31,6 +31,13 @@ jobs:
echo "${{ secrets.APPLICATION_S3 }}" > ./application-s3.yml
shell: bash

- name: make application-openapi-key yml file
run: |
cd ./api-module/src/main/resources
touch ./application-openapi-key.yml
echo "${{ secrets.APPLICATION_OPENAPI }}" > ./application-openapi-key.yml
shell: bash

- name: Gradlew 권한 부여
run: chmod +x ./gradlew

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ out/
**/data/

api-module/src/main/resources/application-prod.yml
api-module/src/main/resources/application-openapi-key.yml
common-module/src/main/resources/application-s3.yml
docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.foodgo.apimodule.cuisine.application;

import com.foodgo.apimodule.cuisine.dto.RecipeDTO;
import com.foodgo.apimodule.cuisine.dto.TestResultType;
import com.foodgo.apimodule.ingredient.dto.IngredientInfo;
import com.foodgo.apimodule.ingredient.mapper.IngredientMapper;
import com.foodgo.coremodule.cuisine.domain.Ingredient;
import com.foodgo.coremodule.cuisine.domain.TestType;
import com.foodgo.coremodule.cuisine.exception.CuisineErrorCode;
import com.foodgo.coremodule.cuisine.exception.CuisineException;
import com.foodgo.coremodule.cuisine.service.CuisineQueryService;
import com.foodgo.coremodule.user.domain.User;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

@Service
@RequiredArgsConstructor
public class CuisineFindUseCase {

private final CuisineQueryService cuisineQueryService;

@Value("${spring.openapi.key.recipe}")
private String apiKey;

public List<IngredientInfo> findIngredientInfo(User user) {

List<IngredientInfo> infoList = new ArrayList<>();

List<Ingredient> ingredients = cuisineQueryService.findIngredientsByUserId(user.getId());
for (Ingredient ingredient : ingredients) {
final IngredientInfo infoDTO = IngredientMapper.toInfoDTO(ingredient);
infoList.add(infoDTO);
}

return infoList;
}

public TestResultType findTestResult(User user) {

TestType test = cuisineQueryService.findTestType(user.getId());
return new TestResultType(test);
}

public List<RecipeDTO.RecipeDetail> findRecipeResult(RecipeDTO.Request request) throws URISyntaxException {

String apiUrl = "http://openapi.foodsafetykorea.go.kr/api/" +
apiKey + "/COOKRCP01/json/1/100/RCP_NM=" + request.rcpNm();

URI uri = new URI(apiUrl);

WebClient webClient = WebClient.create();
RecipeDTO.TotalResponse response = webClient.get()
.uri(uri)
.retrieve()
.bodyToMono(RecipeDTO.TotalResponse.class)
.doOnError(error -> {
throw new CuisineException(CuisineErrorCode.OPEN_API_INFO_ERROR);
})
.block();

// row 리스트만 추출
return response.COOKRCP01().row();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.foodgo.apimodule.cuisine.application;

import com.foodgo.apimodule.ingredient.dto.IngredientAddReq;
import com.foodgo.apimodule.cuisine.dto.TestResultType;
import com.foodgo.apimodule.ingredient.mapper.IngredientMapper;
import com.foodgo.commonmodule.image.service.AwsS3Service;
import com.foodgo.coremodule.cuisine.domain.CuisineTest;
import com.foodgo.coremodule.cuisine.domain.Ingredient;
import com.foodgo.coremodule.cuisine.service.CuisineQueryService;
import com.foodgo.coremodule.user.domain.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

@Service
@RequiredArgsConstructor
@Transactional
public class CuisineSaveUseCase {

private final CuisineQueryService cuisineQueryService;
private final AwsS3Service awsS3Service;

public void saveIngredient(IngredientAddReq addReq, MultipartFile multipartFile, User user) {

String imageUrl = awsS3Service.uploadFile(multipartFile);
Ingredient ingredient = IngredientMapper.toIngredientEntity(addReq, user, imageUrl);

cuisineQueryService.saveIngredient(ingredient);
}


public void deleteIngredient(Long ingredientId) {

cuisineQueryService.deleteIngredient(ingredientId);
}

public void saveCuisineTest(User user, TestResultType resultType) {

final CuisineTest cuisineTest = CuisineTest.builder().type(resultType.testType()).user(user).build();
cuisineQueryService.saveCuisineTest(cuisineTest);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.foodgo.apimodule.cuisine.dto;

import java.util.List;

public class RecipeDTO {

public record Request(
String rcpNm // 메뉴명
) {
}

// 전체 응답을 나타내는 클래스
public record TotalResponse(
CookRcp COOKRCP01
) {
public record CookRcp(
String total_count,
List<RecipeDetail> row, // 여러 개의 레시피 데이터를 포함하는 리스트
Result RESULT
) {
}
}

// 개별 레시피 데이터를 나타내는 클래스
public record RecipeDetail(
String RCP_SEQ, // 일련번호
String RCP_NM, // 메뉴명
String RCP_WAY2, // 조리방법
String RCP_PAT2, // 요리종류
String INFO_WGT, // 중량(1인분)
String INFO_ENG, // 열량
String INFO_CAR, // 탄수화물
String INFO_PRO, // 단백질
String INFO_FAT, // 지방
String INFO_NA, // 나트륨
String HASH_TAG, // 해쉬태그
String ATT_FILE_NO_MAIN, // 메인 이미지 경로
String ATT_FILE_NO_MK, // 서브 이미지 경로
String RCP_PARTS_DTLS, // 재료 정보
String MANUAL01, // 조리법 1
String MANUAL02, // 조리법 2
String MANUAL03, // 조리법 3
String MANUAL04, // 조리법 4
String MANUAL05, // 조리법 5
String MANUAL06, // 조리법 6
String MANUAL07, // 조리법 7
String MANUAL08, // 조리법 8
String MANUAL09, // 조리법 9
String MANUAL10, // 조리법 10
String MANUAL11, // 조리법 11
String MANUAL12, // 조리법 12
String MANUAL13, // 조리법 13
String MANUAL14, // 조리법 14
String MANUAL15, // 조리법 15
String MANUAL16, // 조리법 16
String MANUAL17, // 조리법 17
String MANUAL18, // 조리법 18
String MANUAL19, // 조리법 19
String MANUAL20, // 조리법 20
String RCP_NA_TIP // 저감 조리법 TIP
) {
}

// 결과 메시지를 나타내는 클래스
public record Result(
String MSG,
String CODE
) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.foodgo.apimodule.cuisine.dto;

import com.foodgo.coremodule.cuisine.domain.TestType;

public record TestResultType(
TestType testType
) {
}
Loading
Loading