Skip to content

Commit

Permalink
Merge pull request #61 from CAUSOLDOUTMEN/fix/60-nutrition-info
Browse files Browse the repository at this point in the history
  • Loading branch information
win-luck authored Nov 8, 2023
2 parents 649a54c + d8c27fa commit 737e304
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions k8s/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ spec:
resources:
limits:
memory: "512Mi"
cpu: 0.3
cpu: 0.5
ports:
- containerPort: 8080
readinessProbe:
httpGet:
path: /swagger-ui/index.html
port: 8080
initialDelaySeconds: 30
initialDelaySeconds: 40
periodSeconds: 5
failureThreshold: 24
---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.diareat.diareat.food.dto;

import com.diareat.diareat.user.domain.BaseNutrition;
import lombok.AllArgsConstructor;
import lombok.Getter;

Expand All @@ -23,7 +24,14 @@ public class ResponseNutritionSumByDateDto {
double ratioProtein;
double ratioFat;

public static ResponseNutritionSumByDateDto of (Long userId, LocalDate checkDate, int nutritionSumType, int totalKcal, int totalCarbohydrate, int totalProtein, int totalFat, double ratioKcal, double ratioCarbohydrate, double ratioProtein, double ratioFat){
return new ResponseNutritionSumByDateDto(userId, checkDate, nutritionSumType, totalKcal, totalCarbohydrate, totalProtein, totalFat, ratioKcal, ratioCarbohydrate, ratioProtein, ratioFat);
BaseNutrition baseNutrition;

public static ResponseNutritionSumByDateDto of (Long userId, LocalDate checkDate, int nutritionSumType, int totalKcal,
int totalCarbohydrate, int totalProtein, int totalFat, double ratioKcal,
double ratioCarbohydrate, double ratioProtein, double ratioFat,
BaseNutrition baseNutrition){
return new ResponseNutritionSumByDateDto(userId, checkDate, nutritionSumType, totalKcal,
totalCarbohydrate, totalProtein, totalFat, ratioKcal,
ratioCarbohydrate, ratioProtein, ratioFat, baseNutrition);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,9 @@ private ResponseNutritionSumByDateDto calculateNutritionSumAndRatio(Long userId,
double ratioProtein = Math.round((((double) totalProtein / (double) targetUser.getBaseNutrition().getProtein()) * 100.0) * 10.0) / 10.0;
double ratioFat = Math.round((((double) totalFat / (double) targetUser.getBaseNutrition().getFat()) * 100.0) * 10.0) / 10.0;

return ResponseNutritionSumByDateDto.of(userId, checkDate, nutritionSumType, totalKcal, totalCarbohydrate, totalProtein, totalFat, ratioKcal, ratioCarbohydrate, ratioProtein, ratioFat);
return ResponseNutritionSumByDateDto.of(userId, checkDate, nutritionSumType, totalKcal,
totalCarbohydrate, totalProtein, totalFat, ratioKcal,
ratioCarbohydrate, ratioProtein, ratioFat, targetUser.getBaseNutrition());
}

private void validateUser(Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ void testGetNutritionSumByDate() throws Exception{
//Given
LocalDate date = LocalDate.now();
ResponseNutritionSumByDateDto responseNutritionSumByDateDto = ResponseNutritionSumByDateDto.of(testUserId,date,1
,500,100,50,50,0.2,0.3,0.4,0.5);
,500,100,50,50,0.2,0.3,0.4,0.5,
BaseNutrition.createNutrition(500,100,50,50));
ApiResponse<ResponseNutritionSumByDateDto> expectedResponse = ApiResponse.success(responseNutritionSumByDateDto,ResponseCode.FOOD_READ_SUCCESS.getMessage());
when(foodService.getNutritionSumByDate(any(Long.class),any(LocalDate.class))).thenReturn(responseNutritionSumByDateDto);

Expand All @@ -279,6 +280,7 @@ void testGetNutritionSumByDate() throws Exception{
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioCarbohydrate").value(expectedResponse.getData().getRatioCarbohydrate()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioProtein").value(expectedResponse.getData().getRatioProtein()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioFat").value(expectedResponse.getData().getRatioFat()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.baseNutrition.carbohydrate").value(expectedResponse.getData().getBaseNutrition().getCarbohydrate()))
.andExpect(MockMvcResultMatchers.jsonPath("$.msg").value(expectedResponse.getMsg()));
}

Expand All @@ -290,7 +292,8 @@ void testGetNutritionSumByWeek() throws Exception {
//Given
LocalDate date = LocalDate.now();
ResponseNutritionSumByDateDto responseNutritionSumByDateDto = ResponseNutritionSumByDateDto.of(testUserId, date, 7
, 500, 100, 50, 50, 0.2, 0.3, 0.4, 0.5);
, 500, 100, 50, 50, 0.2, 0.3, 0.4, 0.5,
BaseNutrition.createNutrition(500, 100, 50, 50));
ApiResponse<ResponseNutritionSumByDateDto> expectedResponse = ApiResponse.success(responseNutritionSumByDateDto, ResponseCode.FOOD_READ_SUCCESS.getMessage());
when(foodService.getNutritionSumByWeek(any(Long.class))).thenReturn(responseNutritionSumByDateDto);

Expand All @@ -312,6 +315,7 @@ void testGetNutritionSumByWeek() throws Exception {
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioCarbohydrate").value(expectedResponse.getData().getRatioCarbohydrate()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioProtein").value(expectedResponse.getData().getRatioProtein()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioFat").value(expectedResponse.getData().getRatioFat()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.baseNutrition.carbohydrate").value(expectedResponse.getData().getBaseNutrition().getCarbohydrate()))
.andExpect(MockMvcResultMatchers.jsonPath("$.msg").value(expectedResponse.getMsg()));
}

Expand All @@ -323,7 +327,8 @@ void testGetNutritionSumByMonth() throws Exception {
//Given
LocalDate date = LocalDate.now();
ResponseNutritionSumByDateDto responseNutritionSumByDateDto = ResponseNutritionSumByDateDto.of(testUserId, date, 30
, 500, 100, 50, 50, 0.2, 0.3, 0.4, 0.5);
, 500, 100, 50, 50, 0.2, 0.3, 0.4, 0.5,
BaseNutrition.createNutrition(500, 100, 50, 50));
ApiResponse<ResponseNutritionSumByDateDto> expectedResponse = ApiResponse.success(responseNutritionSumByDateDto, ResponseCode.FOOD_READ_SUCCESS.getMessage());
when(foodService.getNutritionSumByMonth(any(Long.class))).thenReturn(responseNutritionSumByDateDto);

Expand All @@ -345,6 +350,7 @@ void testGetNutritionSumByMonth() throws Exception {
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioCarbohydrate").value(expectedResponse.getData().getRatioCarbohydrate()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioProtein").value(expectedResponse.getData().getRatioProtein()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioFat").value(expectedResponse.getData().getRatioFat()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.baseNutrition.carbohydrate").value(expectedResponse.getData().getBaseNutrition().getCarbohydrate()))
.andExpect(MockMvcResultMatchers.jsonPath("$.msg").value(expectedResponse.getMsg()));
}

Expand Down

0 comments on commit 737e304

Please sign in to comment.