-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/#368 : 특정 날짜의 단,탄,지,칼로리 성분 분석하는 Usecase 구현
- Loading branch information
1 parent
1a00e90
commit c5ff22d
Showing
6 changed files
with
131 additions
and
6 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
11 changes: 11 additions & 0 deletions
11
...ain/java/com/gaebaljip/exceed/application/port/in/nutritionist/GetAllAnalysisUsecase.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,11 @@ | ||
package com.gaebaljip.exceed.application.port.in.nutritionist; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import com.gaebaljip.exceed.dto.AllAnalysisDTO; | ||
import com.gaebaljip.exceed.dto.request.GetAllAnalysisRequest; | ||
|
||
@Component | ||
public interface GetAllAnalysisUsecase { | ||
AllAnalysisDTO execute(GetAllAnalysisRequest request); | ||
} |
69 changes: 69 additions & 0 deletions
69
...a/com/gaebaljip/exceed/application/service/nutritionist/GetAllCalorieAnalysisService.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,69 @@ | ||
package com.gaebaljip.exceed.application.service.nutritionist; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.gaebaljip.exceed.application.domain.meal.DailyMeal; | ||
import com.gaebaljip.exceed.application.domain.meal.Meal; | ||
import com.gaebaljip.exceed.application.domain.member.Member; | ||
import com.gaebaljip.exceed.application.domain.nutritionist.*; | ||
import com.gaebaljip.exceed.application.port.in.nutritionist.GetAllAnalysisUsecase; | ||
import com.gaebaljip.exceed.application.port.out.meal.DailyMealPort; | ||
import com.gaebaljip.exceed.application.port.out.member.MemberPort; | ||
import com.gaebaljip.exceed.dto.AllAnalysisDTO; | ||
import com.gaebaljip.exceed.dto.TodayMealDTO; | ||
import com.gaebaljip.exceed.dto.request.GetAllAnalysisRequest; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* 한달치 모든 영양소 달성도를 날짜별로 측정하여 반환한다. | ||
* | ||
* @author hwangdaesun | ||
* @version 1.0 | ||
*/ | ||
@Service | ||
@RequiredArgsConstructor | ||
public class GetAllCalorieAnalysisService implements GetAllAnalysisUsecase { | ||
|
||
private final DailyMealPort dailyMealPort; | ||
private final MemberPort memberPort; | ||
|
||
/** | ||
* CalorieAnalyzer 도메인이 특정 날짜에 목표 칼로리를 달성했는 지를 판단하여 달성했을 경우 true를 반환 | ||
* | ||
* @param request : 회원 PK와 날짜 | ||
* @return GetAnalysisResponse : 날짜별 칼로리 달성 여부 | ||
*/ | ||
@Override | ||
public AllAnalysisDTO execute(GetAllAnalysisRequest request) { | ||
List<Meal> meals = | ||
dailyMealPort.query(new TodayMealDTO(request.memberId(), request.dateTime())); | ||
Member member = memberPort.query(request.memberId(), request.dateTime()); | ||
if (meals.isEmpty()) { | ||
return createEmptyMealAnalysis(request); | ||
} | ||
DailyMeal dailyMeal = new DailyMeal(meals); | ||
CalorieAnalyzer calorieAnalyzer = | ||
CalorieAnalyzerFactory.getInstance().createAnalyzer(dailyMeal, member); | ||
ProteinAnalyzer proteinAnalyzer = | ||
ProteinAnalyzerFactory.getInstance().createAnalyzer(dailyMeal, member); | ||
CarbohydrateAnalyzer carbohydrateAnalyzer = | ||
CarbohydrateAnalyzerFactory.getInstance().createAnalyzer(dailyMeal, member); | ||
FatAnalyzer fatAnalyzer = | ||
FatAnalyzerFactory.getInstance().createAnalyzer(dailyMeal, member); | ||
return AllAnalysisDTO.of( | ||
true, | ||
request.dateTime().toLocalDate(), | ||
calorieAnalyzer.analyze(), | ||
proteinAnalyzer.analyze(), | ||
carbohydrateAnalyzer.analyze(), | ||
fatAnalyzer.analyze()); | ||
} | ||
|
||
public AllAnalysisDTO createEmptyMealAnalysis(GetAllAnalysisRequest request) { | ||
return AllAnalysisDTO.of( | ||
false, request.dateTime().toLocalDate(), false, false, false, false); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
BE/exceed/src/main/java/com/gaebaljip/exceed/dto/AllAnalysisDTO.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,28 @@ | ||
package com.gaebaljip.exceed.dto; | ||
|
||
import java.time.LocalDate; | ||
|
||
public record AllAnalysisDTO( | ||
Boolean isVisited, | ||
LocalDate date, | ||
boolean isCalorieAchieved, | ||
boolean isProteinAchieved, | ||
boolean isFatAchieved, | ||
boolean isCarbohydrateAchieved) { | ||
|
||
public static AllAnalysisDTO of( | ||
Boolean isVisited, | ||
LocalDate date, | ||
boolean isCalorieAchieved, | ||
boolean isProteinAchieved, | ||
boolean isFatAchieved, | ||
boolean isCarbohydrateAchieved) { | ||
return new AllAnalysisDTO( | ||
isVisited, | ||
date, | ||
isCalorieAchieved, | ||
isProteinAchieved, | ||
isFatAchieved, | ||
isCarbohydrateAchieved); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
BE/exceed/src/main/java/com/gaebaljip/exceed/dto/request/GetAllAnalysisRequest.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,9 @@ | ||
package com.gaebaljip.exceed.dto.request; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record GetAllAnalysisRequest(Long memberId, LocalDateTime dateTime) { | ||
public static GetAllAnalysisRequest of(Long memberId, LocalDateTime dateTime) { | ||
return new GetAllAnalysisRequest(memberId, dateTime); | ||
} | ||
} |
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