Skip to content

Commit

Permalink
Merge pull request #379 from JNU-econovation/feat/#368
Browse files Browse the repository at this point in the history
[BE/feat] 식사 분석하는 API 기능 변경에 따른 유스케이스 개발 및 기존 도메인 리팩토링
  • Loading branch information
LJH098 authored Jul 13, 2024
2 parents e003244 + ae3435c commit 978c11e
Show file tree
Hide file tree
Showing 34 changed files with 411 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@
import com.gaebaljip.exceed.application.port.in.meal.GetSpecificMealQuery;
import com.gaebaljip.exceed.application.port.in.member.GetMaintainMealUsecase;
import com.gaebaljip.exceed.application.port.in.member.GetTargetMealUsecase;
import com.gaebaljip.exceed.application.service.nutritionist.GetAllCalorieAnalysisService;
import com.gaebaljip.exceed.common.ApiResponse;
import com.gaebaljip.exceed.common.ApiResponseGenerator;
import com.gaebaljip.exceed.common.annotation.AuthenticationMemberId;
import com.gaebaljip.exceed.common.docs.meal.GetMealExceptionDocs;
import com.gaebaljip.exceed.common.docs.meal.GetMealFoodExceptionDocs;
import com.gaebaljip.exceed.common.swagger.ApiErrorExceptionsExample;
import com.gaebaljip.exceed.dto.CurrentMealDTO;
import com.gaebaljip.exceed.dto.MaintainMealDTO;
import com.gaebaljip.exceed.dto.SpecificMealDTO;
import com.gaebaljip.exceed.dto.TargetMealDTO;
import com.gaebaljip.exceed.dto.*;
import com.gaebaljip.exceed.dto.request.GetAllAnalysisRequest;
import com.gaebaljip.exceed.dto.response.*;

import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -45,6 +44,7 @@ public class GetMealController {
private final GetTargetMealUsecase getTargetMealUsecase;
private final GetCurrentMealQuery getCurrentMealQuery;
private final GetSpecificMealQuery getSpecificMealQuery;
private final GetAllCalorieAnalysisService getAllCalorieAnalysisService;

/** 오늘 먹은 식사 정보(단,탄,지 및 칼로리) 조회 */
@Operation(summary = "오늘 먹은 식사 정보 조회", description = "오늘 먹은 식사 정보(단,탄,지 및 칼로리)를 조회한다.")
Expand All @@ -70,11 +70,16 @@ public ApiResponse<ApiResponse.CustomBody<GetMealFoodResponse>> getMealFood(
MaintainMealDTO maintainMealDTO = getMaintainMealUsecase.execute(memberId, localDateTime);
TargetMealDTO targetMealDTO = getTargetMealUsecase.execute(memberId, localDateTime);
SpecificMealDTO specificMealDTO = getSpecificMealQuery.execute(memberId, localDateTime);
GetMealResponse getMealResponse =
new GetMealResponse(
maintainMealDTO, targetMealDTO, specificMealDTO.currentMealDTO());

AllAnalysisDTO allAnalysisDTO =
getAllCalorieAnalysisService.execute(
GetAllAnalysisRequest.of(memberId, localDateTime));
return ApiResponseGenerator.success(
new GetMealFoodResponse(getMealResponse, specificMealDTO.mealRecordDTOS()),
new GetMealFoodResponse(
GetMealResponse.of(
maintainMealDTO, targetMealDTO, specificMealDTO.currentMealDTO()),
specificMealDTO.mealRecordDTOS(),
allAnalysisDTO),
HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gaebaljip.exceed.application.port.in.nutritionist.GetAnalysisUsecase;
import com.gaebaljip.exceed.application.port.in.nutritionist.GetCalorieAnalysisUsecase;
import com.gaebaljip.exceed.common.ApiResponse;
import com.gaebaljip.exceed.common.ApiResponseGenerator;
import com.gaebaljip.exceed.common.annotation.AuthenticationMemberId;
import com.gaebaljip.exceed.common.docs.nutritionist.GetAnalysisExceptionDocs;
import com.gaebaljip.exceed.common.swagger.ApiErrorExceptionsExample;
import com.gaebaljip.exceed.dto.request.GetAnalysisRequest;
import com.gaebaljip.exceed.dto.response.GetAnalysisResponse;
import com.gaebaljip.exceed.dto.request.GetCalorieAnalysisRequest;
import com.gaebaljip.exceed.dto.response.GetCalorieAnalysisResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
Expand All @@ -34,17 +34,17 @@
@Tag(name = "[분석 조회]")
public class GetAnalysisController {

private final GetAnalysisUsecase getAnalysisUsecase;
private final GetCalorieAnalysisUsecase getAnalysisUsecase;

@Operation(summary = "월별 식사 정보 분석", description = "월별 식사 정보를 분석한다.")
@GetMapping("/achieve/{date}")
@ApiErrorExceptionsExample(GetAnalysisExceptionDocs.class)
public ApiResponse<ApiResponse.CustomBody<GetAnalysisResponse>> getAnalysis(
public ApiResponse<ApiResponse.CustomBody<GetCalorieAnalysisResponse>> getAnalysis(
@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date,
@Parameter(hidden = true) @AuthenticationMemberId Long memberId) {
LocalDateTime localDateTime = date.atStartOfDay();
GetAnalysisResponse achieveListResponse =
getAnalysisUsecase.execute(new GetAnalysisRequest(memberId, localDateTime));
GetCalorieAnalysisResponse achieveListResponse =
getAnalysisUsecase.execute(new GetCalorieAnalysisRequest(memberId, localDateTime));
return ApiResponseGenerator.success(achieveListResponse, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import org.springframework.stereotype.Component;

import com.gaebaljip.exceed.adapter.out.jpa.nutritionist.MonthlyTargetPort;
import com.gaebaljip.exceed.application.domain.member.Member;
import com.gaebaljip.exceed.application.domain.member.MemberEntity;
import com.gaebaljip.exceed.application.port.out.member.MemberPort;
Expand All @@ -17,7 +16,7 @@

@Component
@RequiredArgsConstructor
public class MemberPersistenceAdapter implements MemberPort, MonthlyTargetPort {
public class MemberPersistenceAdapter implements MemberPort {

private final MemberRepository memberRepository;
private final MemberConverter memberConverter;
Expand All @@ -34,7 +33,6 @@ public MemberEntity command(MemberEntity memberEntity) {
return memberRepository.save(memberEntity);
}

/** 회원 수정 기능 구현 후 -> Map<LocalDate date, MemberModel> 변경 */
@Override
public Member query(Long memberId, LocalDateTime date) {
MemberEntity memberEntity =
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.gaebaljip.exceed.application.domain.nutritionist;

import com.gaebaljip.exceed.application.domain.meal.DailyMeal;
import com.gaebaljip.exceed.application.domain.member.Member;

public abstract class AbstractAnalyzerFactory {
public abstract Analyzer createAnalyzer(DailyMeal dailyMeal, Member member);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.gaebaljip.exceed.application.domain.nutritionist;

public interface Analyzable {
boolean analyze();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.gaebaljip.exceed.application.domain.nutritionist;

import com.gaebaljip.exceed.application.domain.meal.DailyMeal;
import com.gaebaljip.exceed.application.domain.member.Member;

public abstract class Analyzer implements Analyzable {

protected DailyMeal dailyMeal;
protected Member member;

public Analyzer(DailyMeal dailyMeal, Member member) {
this.dailyMeal = dailyMeal;
this.member = member;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.gaebaljip.exceed.application.domain.nutritionist;

import com.gaebaljip.exceed.application.domain.meal.DailyMeal;
import com.gaebaljip.exceed.application.domain.member.Member;

public class CalorieAnalyzer extends Analyzer {
public CalorieAnalyzer(DailyMeal dailyMeal, Member member) {
super(dailyMeal, member);
}

@Override
public boolean analyze() {
return member.measureTargetCalorie() - dailyMeal.calculateCurrentCalorie() <= 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.gaebaljip.exceed.application.domain.nutritionist;

import com.gaebaljip.exceed.application.domain.meal.DailyMeal;
import com.gaebaljip.exceed.application.domain.member.Member;

public class CalorieAnalyzerFactory extends AbstractAnalyzerFactory {

private CalorieAnalyzerFactory() {}

private static class SingletonHolder {
private static final CalorieAnalyzerFactory INSTANCE = new CalorieAnalyzerFactory();
}

public static CalorieAnalyzerFactory getInstance() {
return SingletonHolder.INSTANCE;
}

@Override
public CalorieAnalyzer createAnalyzer(DailyMeal dailyMeal, Member member) {
return new CalorieAnalyzer(dailyMeal, member);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.gaebaljip.exceed.application.domain.nutritionist;

import com.gaebaljip.exceed.application.domain.meal.DailyMeal;
import com.gaebaljip.exceed.application.domain.member.Member;

public class CarbohydrateAnalyzer extends Analyzer {
public CarbohydrateAnalyzer(DailyMeal dailyMeal, Member member) {
super(dailyMeal, member);
}

@Override
public boolean analyze() {
return member.measureTargetCarbohydrate() - dailyMeal.calculateCurrentCarbohydrate() <= 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.gaebaljip.exceed.application.domain.nutritionist;

import com.gaebaljip.exceed.application.domain.meal.DailyMeal;
import com.gaebaljip.exceed.application.domain.member.Member;

public class CarbohydrateAnalyzerFactory extends AbstractAnalyzerFactory {

private CarbohydrateAnalyzerFactory() {}

private static class SingletonHolder {
private static final CarbohydrateAnalyzerFactory INSTANCE =
new CarbohydrateAnalyzerFactory();
}

public static CarbohydrateAnalyzerFactory getInstance() {
return SingletonHolder.INSTANCE;
}

@Override
public CarbohydrateAnalyzer createAnalyzer(DailyMeal dailyMeal, Member member) {
return new CarbohydrateAnalyzer(dailyMeal, member);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.gaebaljip.exceed.application.domain.nutritionist;

import com.gaebaljip.exceed.application.domain.meal.DailyMeal;
import com.gaebaljip.exceed.application.domain.member.Member;

public class FatAnalyzer extends Analyzer {
public FatAnalyzer(DailyMeal dailyMeal, Member member) {
super(dailyMeal, member);
}

@Override
public boolean analyze() {
return member.measureTargetFat() - dailyMeal.calculateCurrentFat() <= 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.gaebaljip.exceed.application.domain.nutritionist;

import com.gaebaljip.exceed.application.domain.meal.DailyMeal;
import com.gaebaljip.exceed.application.domain.member.Member;

public class FatAnalyzerFactory extends AbstractAnalyzerFactory {

private FatAnalyzerFactory() {}

private static class SingletonHolder {
private static final FatAnalyzerFactory INSTANCE = new FatAnalyzerFactory();
}

public static FatAnalyzerFactory getInstance() {
return SingletonHolder.INSTANCE;
}

@Override
public FatAnalyzer createAnalyzer(DailyMeal dailyMeal, Member member) {
return new FatAnalyzer(dailyMeal, member);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.gaebaljip.exceed.application.domain.nutritionist;

import com.gaebaljip.exceed.application.domain.meal.DailyMeal;
import com.gaebaljip.exceed.application.domain.member.Member;

public class ProteinAnalyzer extends Analyzer {
public ProteinAnalyzer(DailyMeal dailyMeal, Member member) {
super(dailyMeal, member);
}

@Override
public boolean analyze() {
return member.measureTargetProtein() - dailyMeal.calculateCurrentProtein() <= 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.gaebaljip.exceed.application.domain.nutritionist;

import com.gaebaljip.exceed.application.domain.meal.DailyMeal;
import com.gaebaljip.exceed.application.domain.member.Member;

public class ProteinAnalyzerFactory extends AbstractAnalyzerFactory {

private ProteinAnalyzerFactory() {}

private static class SingletonHolder {
private static final ProteinAnalyzerFactory INSTANCE = new ProteinAnalyzerFactory();
}

public static ProteinAnalyzerFactory getInstance() {
return SingletonHolder.INSTANCE;
}

@Override
public ProteinAnalyzer createAnalyzer(DailyMeal dailyMeal, Member member) {
return new ProteinAnalyzer(dailyMeal, member);
}
}
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);
}

This file was deleted.

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.request.GetCalorieAnalysisRequest;
import com.gaebaljip.exceed.dto.response.GetCalorieAnalysisResponse;

@Component
public interface GetCalorieAnalysisUsecase {
GetCalorieAnalysisResponse execute(GetCalorieAnalysisRequest getCalorieAnalysisRequest);
}
Loading

0 comments on commit 978c11e

Please sign in to comment.