-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/#29' into develop
- Loading branch information
Showing
12 changed files
with
329 additions
and
26 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 |
---|---|---|
|
@@ -2,7 +2,7 @@ name: Backend CD # actions 이름 | |
|
||
on: | ||
push: | ||
branches: [ fix/#28 ] | ||
branches: [ feature/#29 ] | ||
|
||
jobs: | ||
deploy: | ||
|
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
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
45 changes: 29 additions & 16 deletions
45
...dule/src/main/java/com/foodgo/apimodule/ingredient/presentation/IngredientController.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 |
---|---|---|
@@ -1,36 +1,49 @@ | ||
package com.foodgo.apimodule.ingredient.presentation; | ||
|
||
import java.net.URISyntaxException; | ||
|
||
import com.foodgo.apimodule.ingredient.application.IngredientFindUseCase; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.foodgo.commonmodule.common.ApplicationResponse; | ||
import com.foodgo.coremodule.ingredient.dto.request.IngredientGetRequest; | ||
import com.foodgo.coremodule.ingredient.dto.response.IngredientGetResponse; | ||
import com.foodgo.coremodule.security.annotation.UserResolver; | ||
import com.foodgo.coremodule.user.domain.User; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.net.URISyntaxException; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/v1/ingredients") | ||
@Tag(name = "ingredient", description = "식재료 관련 API") | ||
public class IngredientController { | ||
|
||
private final IngredientFindUseCase ingredientFindUseCase; | ||
private final IngredientFindUseCase ingredientFindUseCase; | ||
|
||
@PostMapping("") | ||
public ApplicationResponse<IngredientGetResponse.Row> getIngredientInfo( | ||
@UserResolver User user, | ||
@RequestBody @Valid IngredientGetRequest request | ||
) throws URISyntaxException { | ||
return ApplicationResponse.onSuccess(ingredientFindUseCase.getIngredient(user, request)); | ||
} | ||
@PostMapping("") | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "식재료 정보 확인 성공", | ||
useReturnTypeSchema = true | ||
) | ||
} | ||
) | ||
@Operation(summary = "식재료 정보 확인 API", description = "식재료 정보 확인 + 리포트 DB 저장 API 입니다.") | ||
public ApplicationResponse<IngredientGetResponse.Row> getIngredientInfo( | ||
@UserResolver User user, | ||
@RequestBody @Valid IngredientGetRequest request | ||
) throws URISyntaxException { | ||
return ApplicationResponse.onSuccess(ingredientFindUseCase.getIngredient(user, request)); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
api-module/src/main/java/com/foodgo/apimodule/report/application/ReportFindUseCase.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,19 @@ | ||
package com.foodgo.apimodule.report.application; | ||
|
||
import com.foodgo.coremodule.report.dto.ReportComparisonDTO; | ||
import com.foodgo.coremodule.report.service.ReportQueryService; | ||
import com.foodgo.coremodule.user.domain.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReportFindUseCase { | ||
|
||
private final ReportQueryService reportQueryService; | ||
|
||
// 통게 dto list 만들기 | ||
public ReportComparisonDTO getStatistics(User user) { | ||
return reportQueryService.getWeeklyReportComparison(user.getId()); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
api-module/src/main/java/com/foodgo/apimodule/report/dto/ReportStatistics.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,8 @@ | ||
package com.foodgo.apimodule.report.dto; | ||
|
||
public record ReportStatistics( | ||
String name, | ||
Double lastweek, | ||
Double thisweek | ||
) { | ||
} |
41 changes: 41 additions & 0 deletions
41
api-module/src/main/java/com/foodgo/apimodule/report/mapper/ReportMapper.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,41 @@ | ||
package com.foodgo.apimodule.report.mapper; | ||
|
||
import com.foodgo.coremodule.ingredient.dto.response.IngredientGetResponse; | ||
import com.foodgo.coremodule.report.domain.MealType; | ||
import com.foodgo.coremodule.report.domain.Report; | ||
import com.foodgo.coremodule.user.domain.User; | ||
|
||
import java.time.LocalTime; | ||
|
||
public class ReportMapper { | ||
|
||
public static Report mapToReport(User user, IngredientGetResponse.Row row) { | ||
MealType mealType = determineMealType(); // MealType을 결정하는 메서드 호출 | ||
|
||
return Report.builder() | ||
.user(user) | ||
.type(mealType) // MealType 저장 | ||
.total(Double.parseDouble(row.getNutrCont1())) // 총 칼로리 | ||
.carb(Double.parseDouble(row.getNutrCont2())) // 탄수화물 | ||
.protein(Double.parseDouble(row.getNutrCont3())) // 단백질 | ||
.fat(Double.parseDouble(row.getNutrCont4())) // 지방 | ||
.sugar(Double.parseDouble(row.getNutrCont5())) // 당류 | ||
.sodium(Double.parseDouble(row.getNutrCont6())) // 나트륨 | ||
.cholesterol(Double.parseDouble(row.getNutrCont7())) // 콜레스테롤 | ||
.saturatedFat(Double.parseDouble(row.getNutrCont8())) // 포화지방산 | ||
.transFat(Double.parseDouble(row.getNutrCont9())) // 트랜스지방 | ||
.build(); | ||
} | ||
|
||
private static MealType determineMealType() { | ||
LocalTime now = LocalTime.now(); | ||
|
||
if (now.isBefore(LocalTime.NOON)) { | ||
return MealType.BREAKFAST; // 정오 이전이면 아침 | ||
} else if (now.isBefore(LocalTime.of(15, 0))) { | ||
return MealType.LUNCH; // 오후 3시 이전이면 점심 | ||
} else { | ||
return MealType.DINNER; // 그 이후는 저녁 | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
api-module/src/main/java/com/foodgo/apimodule/report/presentation/ReportController.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,45 @@ | ||
package com.foodgo.apimodule.report.presentation; | ||
|
||
import com.foodgo.apimodule.report.application.ReportFindUseCase; | ||
import com.foodgo.commonmodule.common.ApplicationResponse; | ||
import com.foodgo.coremodule.report.dto.ReportComparisonDTO; | ||
import com.foodgo.coremodule.security.annotation.UserResolver; | ||
import com.foodgo.coremodule.user.domain.User; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/v1/report") | ||
@Tag(name = "report", description = "리포트 관련 API") | ||
public class ReportController { | ||
|
||
private final ReportFindUseCase reportFindUseCase; | ||
|
||
@GetMapping() | ||
@ApiResponses( | ||
value = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "리포트 통계 확인 성공", | ||
useReturnTypeSchema = true | ||
) | ||
} | ||
) | ||
@Operation(summary = "리포트 통계 확인 API", description = "리포트 통계 확인 API 입니다.") | ||
public ApplicationResponse<ReportComparisonDTO> findReportStatistics( | ||
@UserResolver User user) { | ||
|
||
ReportComparisonDTO comparisonDTO = reportFindUseCase.getStatistics(user); | ||
return ApplicationResponse.onSuccess(comparisonDTO); | ||
} | ||
|
||
} |
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
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
23 changes: 23 additions & 0 deletions
23
core-module/src/main/java/com/foodgo/coremodule/report/dto/ReportComparisonDTO.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,23 @@ | ||
package com.foodgo.coremodule.report.dto; | ||
|
||
public record ReportComparisonDTO( | ||
Double lastWeekTotal, | ||
Double thisWeekTotal, | ||
Double lastWeekCarbs, | ||
Double thisWeekCarbs, | ||
Double lastWeekProteins, | ||
Double thisWeekProteins, | ||
Double lastWeekFats, | ||
Double thisWeekFats, | ||
Double lastWeekSugar, | ||
Double thisWeekSugar, | ||
Double lastWeekSodium, | ||
Double thisWeekSodium, | ||
Double lastWeekCholesterol, | ||
Double thisWeekCholesterol, | ||
Double lastWeekSaturatedFat, | ||
Double thisWeekSaturatedFat, | ||
Double lastWeekTransFat, | ||
Double thisWeekTransFat | ||
) { | ||
} |
Oops, something went wrong.