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

BE 운영 서버 반영 #428

Merged
merged 31 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
25d3f48
test/#414 : 로그인 관련 웹 계층 단위 테스트 수행
hwangdaesun Jul 20, 2024
f9ecf4b
test/#414 : 오늘 먹은 식사 조회 API 컨트롤러 계층 단위 테스트 보충
hwangdaesun Jul 20, 2024
e618bae
test/#414 : 분석 조회 웹 계층 단위 테스트 리팩토링
hwangdaesun Jul 20, 2024
fb5681a
Merge pull request #416 from JNU-econovation/test/#414
hwangdaesun Jul 20, 2024
7e7b803
test/#421: 음식 조회 query 메서드 수정
LJH098 Jul 21, 2024
5fa394f
test/#421: GetFoodIntegrationTest
LJH098 Jul 21, 2024
1a850cd
Merge pull request #422 from JNU-econovation/test/#421
hwangdaesun Jul 21, 2024
615875c
refactor/#423 : DTO명 수정
hwangdaesun Jul 21, 2024
6d09953
refactor/#423 : 패키지 이동
hwangdaesun Jul 21, 2024
11d23f4
refactor/#423 : DailyMeal 도메인이 하루에 식사를 하지 않는 경우 포함하도록 하게 수정
hwangdaesun Jul 21, 2024
ea59e73
chore/#423 : easyRandom 의존성 추가
hwangdaesun Jul 21, 2024
947208b
test/#423 : DailyMeal 도메인 테스트 수행
hwangdaesun Jul 21, 2024
9f019d1
refactor/#423 : DailyMeal이 meals가 0인 경우를 포함하여 Service코드에서 meals가 0인 경…
hwangdaesun Jul 21, 2024
a0039aa
refactor/#423 : DailyMeal 도메인 리팩토링함으로써 Service에서 meals가 0일 경우 제외하도록 수…
hwangdaesun Jul 21, 2024
8be8a2f
test/#423 : CalorieAnalyzer 도메인이 meals가 0일 경우 분석 결과가 false가 나오는 지 테스트
hwangdaesun Jul 21, 2024
e2c468b
refactor/#423 : GetAllCalorieAnalysisService 단위 테스트 수행
hwangdaesun Jul 21, 2024
89778c2
Merge pull request #424 from JNU-econovation/test/#423
hwangdaesun Jul 22, 2024
0004ddf
test/#425 : 실제 회원가입 및 온보딩 그리고 회원수정 Flow에 맞게 수정
hwangdaesun Jul 22, 2024
8c1fc84
fix/#425 : checkDate 메서드를 updatedAt 기준으로 해당 날짜보다 과거에 있는 것 확인하도록 수정
hwangdaesun Jul 22, 2024
b05ebd0
test/#425 : findMemberBeforeDate 메서드 테스트
hwangdaesun Jul 22, 2024
7bd2fc5
fix/#425 : 미래중 가장 가까운 기록을 찾도록 메서드 수정
hwangdaesun Jul 22, 2024
c7dd1d4
test/#425 : findMostRecentFutureMember 메서드 테스트
hwangdaesun Jul 22, 2024
43ca70d
refactor/#425 : CustomMemberRepositoryImpl, CustomHistoryRepositoryIm…
hwangdaesun Jul 22, 2024
1bf09fd
test/#425 : 회원 수정 통합 테스트 보충
hwangdaesun Jul 22, 2024
281a5af
test/#425 : testData.sql 수정으로 인한 변경
hwangdaesun Jul 22, 2024
c626d57
feat/#425 : 켈린더 조회시 회원 가입 전의 날짜를 조회하는 경우 validate 하는 Usecase 개발
hwangdaesun Jul 22, 2024
a9a19e7
test/#425 : @MockBean 추가
hwangdaesun Jul 22, 2024
7236874
test/#425 : 날짜와 식사 기록 유무에 따라서 켈린더 상세 조회 테스트 추가 및 수정
hwangdaesun Jul 22, 2024
ee549e3
refactor/#425 : createdDate -> id로 수정
hwangdaesun Jul 22, 2024
a6982b5
test/#425 : 메서드명 when~expected로 수정
hwangdaesun Jul 22, 2024
764e34f
Merge pull request #427 from JNU-econovation/fix/#425
hwangdaesun Jul 22, 2024
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
3 changes: 1 addition & 2 deletions BE/exceed/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ dependencies {
testImplementation "org.testcontainers:testcontainers:1.19.8"
testImplementation "org.testcontainers:junit-jupiter:1.19.8"
testImplementation "org.testcontainers:localstack:1.19.8"
testImplementation "org.jeasy:easy-random-core:5.0.0"



Expand Down Expand Up @@ -216,8 +217,6 @@ jacocoTestReport {
fileTree(dir: it, excludes: [
"**/ExceedApplication",
"**/*Config*",
"**/*Request*",
"**/*Response*",
"**/*Exception*",
"**/*Filter*",
"**/*Docs*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.gaebaljip.exceed.adapter.in.nutritionist.request.GetAllAnalysisRequest;
import com.gaebaljip.exceed.application.port.in.meal.GetCurrentMealQuery;
import com.gaebaljip.exceed.application.port.in.meal.GetSpecificMealQuery;
import com.gaebaljip.exceed.application.port.in.meal.ValidateBeforeSignUpUsecase;
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;
Expand Down Expand Up @@ -46,6 +47,7 @@ public class GetMealController {
private final GetCurrentMealQuery getCurrentMealQuery;
private final GetSpecificMealQuery getSpecificMealQuery;
private final GetAllCalorieAnalysisService getAllCalorieAnalysisService;
private final ValidateBeforeSignUpUsecase validateDateBeforeSignUpUsecase;

/** 오늘 먹은 식사 정보(단,탄,지 및 칼로리) 조회 */
@Operation(summary = "오늘 먹은 식사 정보 조회", description = "오늘 먹은 식사 정보(단,탄,지 및 칼로리)를 조회한다.")
Expand All @@ -68,6 +70,7 @@ public ApiResponse<ApiResponse.CustomBody<GetMealFoodResponse>> getMealFood(
@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate date,
@Parameter(hidden = true) @AuthenticationMemberId Long memberId) {
LocalDateTime localDateTime = date.atStartOfDay();
validateDateBeforeSignUpUsecase.execute(memberId, localDateTime);
MaintainMealDTO maintainMealDTO = getMaintainMealUsecase.execute(memberId, localDateTime);
TargetMealDTO targetMealDTO = getTargetMealUsecase.execute(memberId, localDateTime);
SpecificMealDTO specificMealDTO = getSpecificMealQuery.execute(memberId, localDateTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import com.gaebaljip.exceed.application.domain.member.MemberEntity;
import com.gaebaljip.exceed.application.port.out.food.FoodPort;
import com.gaebaljip.exceed.common.exception.member.MemberNotFoundException;
import com.gaebaljip.exceed.common.exception.food.FoodNotFoundException;

import lombok.RequiredArgsConstructor;

Expand Down Expand Up @@ -48,6 +48,6 @@ public List<FoodEntity> findByMemberEntity(MemberEntity memberEntity) {

@Override
public FoodEntity query(Long foodId) {
return foodRepository.findById(foodId).orElseThrow(() -> MemberNotFoundException.EXECPTION);
return foodRepository.findById(foodId).orElseThrow(() -> FoodNotFoundException.Exception);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.gaebaljip.exceed.application.port.out.meal;
package com.gaebaljip.exceed.adapter.out.jpa.meal;

import java.util.List;

import org.springframework.stereotype.Component;

import com.gaebaljip.exceed.adapter.out.jpa.meal.ConsumedFoodConverter;
import com.gaebaljip.exceed.application.domain.meal.Meal;
import com.gaebaljip.exceed.application.domain.meal.MealEntity;
import com.gaebaljip.exceed.common.annotation.Timer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
import com.gaebaljip.exceed.application.domain.meal.MealEntity;
import com.gaebaljip.exceed.application.domain.member.MemberEntity;
import com.gaebaljip.exceed.application.port.out.meal.DailyMealPort;
import com.gaebaljip.exceed.application.port.out.meal.MealConverter;
import com.gaebaljip.exceed.application.port.out.meal.MealPort;
import com.gaebaljip.exceed.common.annotation.Timer;
import com.gaebaljip.exceed.common.dto.DailyMealDTO;
import com.gaebaljip.exceed.common.dto.MonthlyMealDTO;
import com.gaebaljip.exceed.common.dto.TodayMealDTO;

import lombok.RequiredArgsConstructor;

Expand All @@ -25,19 +24,18 @@ public class MealPersistenceAdapter implements MealPort, DailyMealPort, MonthlyM

private final MealRepository mealRepository;
private final MealConverter mealConverter;
private final int FIRST_DAY = 1;

@Override
public MealEntity command(MealEntity mealEntity) {
return mealRepository.save(mealEntity);
}

@Override
public List<Meal> query(TodayMealDTO todayMealDTO) {
LocalDateTime today = todayMealDTO.date().toLocalDate().atStartOfDay();
public List<Meal> query(DailyMealDTO dailyMealDTO) {
LocalDateTime today = dailyMealDTO.date().toLocalDate().atStartOfDay();
LocalDateTime tomorrow = today.plusDays(1);
List<MealEntity> mealEntities =
mealRepository.findAllTodayMeal(today, tomorrow, todayMealDTO.memberId());
mealRepository.findAllTodayMeal(today, tomorrow, dailyMealDTO.memberId());
return mealConverter.toMeals(mealEntities);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public HistoryEntity command(HistoryEntity historyEntity) {
}

@Override
public HistoryEntity findByMemberIdAndDate(Long memberId, LocalDateTime date) {
return historyRepository.findByMemberIdAndDate(memberId, date);
public HistoryEntity findMostRecentFutureMember(Long memberId, LocalDateTime date) {
return historyRepository.findMostRecentFutureMember(memberId, date);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public MemberEntity findCheckedMemberByEmail(String email) {
}

@Override
public Optional<MemberEntity> findByIdAndDate(Long memberId, LocalDateTime date) {
return memberRepository.findByIdAndDate(memberId, date);
public Optional<MemberEntity> findMemberBeforeDate(Long memberId, LocalDateTime date) {
return memberRepository.findMemberBeforeDate(memberId, date);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

@Repository
public interface CustomHistoryRepository {
HistoryEntity findByMemberIdAndDate(Long memberId, LocalDateTime date);
HistoryEntity findMostRecentFutureMember(Long memberId, LocalDateTime date);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ public class CustomHistoryRepositoryImpl implements CustomHistoryRepository {
private final JPAQueryFactory queryFactory;

@Override
public HistoryEntity findByMemberIdAndDate(Long memberId, LocalDateTime date) {
public HistoryEntity findMostRecentFutureMember(Long memberId, LocalDateTime date) {
return queryFactory
.selectFrom(historyEntity)
.where(historyEntity.id.eq(memberId).and(checkDate(historyEntity, date)))
.orderBy(historyEntity.id.desc())
.where(
historyEntity
.memberEntity
.id
.eq(memberId)
.and(checkFutureDate(historyEntity, date)))
.orderBy(historyEntity.id.asc())
.fetchFirst();
}

private BooleanExpression checkDate(QHistoryEntity historyEntity, LocalDateTime date) {
return historyEntity.createdDate.before(date);
private BooleanExpression checkFutureDate(QHistoryEntity historyEntity, LocalDateTime date) {
return historyEntity.createdDate.after(date);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

@Repository
public interface CustomMemberRepository {
Optional<MemberEntity> findByIdAndDate(Long memberId, LocalDateTime date);
Optional<MemberEntity> findMemberBeforeDate(Long memberId, LocalDateTime date);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CustomMemberRepositoryImpl implements CustomMemberRepository {
private final JPAQueryFactory queryFactory;

@Override
public Optional<MemberEntity> findByIdAndDate(Long memberId, LocalDateTime date) {
public Optional<MemberEntity> findMemberBeforeDate(Long memberId, LocalDateTime date) {
MemberEntity result =
queryFactory
.selectFrom(memberEntity)
Expand All @@ -31,6 +31,6 @@ public Optional<MemberEntity> findByIdAndDate(Long memberId, LocalDateTime date)
}

private BooleanExpression checkDate(QMemberEntity memberEntity, LocalDateTime date) {
return memberEntity.createdDate.eq(date);
return memberEntity.updatedDate.before(date);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

@Getter
@Builder
@ToString
public class ConsumedFood {

private Food food;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@

import java.util.List;

import com.gaebaljip.exceed.common.exception.meal.InsufficientMealsException;
import com.gaebaljip.exceed.common.exception.meal.NotSameDateException;

import lombok.*;

/**
* 같은 날짜 즉, 하루에 먹은 식사를 나타내는 클래스 오늘 먹은 식사들을 분석하여 칼로리,단,탄,지를 계산한다.
* 하루에 먹은 식사들을 분석하여 칼로리,단,탄,지를 계산
*
* @author hwangdaesun
* @version 1.0
* @throws NotSameDateException : 식사들의 날짜가 다를 경우
* @throws InsufficientMealsException : 식사를 한 번도 하지 않았을 경우
*/
@Getter
@ToString
Expand All @@ -24,8 +22,7 @@ public class DailyMeal {
private final List<Meal> meals;

public DailyMeal(List<Meal> meals) {
validateSize(meals);
validateSameMealDate(meals);
validateSameDateIfNotEmpty(meals);
this.meals = meals;
}

Expand All @@ -45,20 +42,21 @@ public double calculateCurrentFat() {
return meals.stream().mapToDouble(Meal::getCurrentFat).sum();
}

private void validateSize(List<Meal> meals) {
if (meals.isEmpty()) {
throw InsufficientMealsException.EXECPTION;
private void validateSameDateIfNotEmpty(List<Meal> meals) {
if (!meals.isEmpty() && !isSameDate(meals)) {
throw NotSameDateException.EXECPTION;
}
}

private void validateSameMealDate(List<Meal> meals) {
if (getDistinctSize(meals) != 1) throw NotSameDateException.EXECPTION;
}

private int getDistinctSize(List<Meal> meals) {
return meals.stream()
.map(meal -> meal.getMealDateTime().toLocalDate())
.collect(toSet())
.size();
private boolean isSameDate(List<Meal> meals) {
int size =
meals.stream()
.map(meal -> meal.getMealDateTime().toLocalDate())
.collect(toSet())
.size();
if (size != 1) {
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
@Builder
public class Unit {
private double servingSize;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.gaebaljip.exceed.application.domain.member;

import java.time.LocalDateTime;

import javax.persistence.*;

import org.hibernate.annotations.ColumnDefault;
Expand Down Expand Up @@ -98,4 +100,8 @@ public boolean checkOnBoarding() {
&& this.getGender() != null
&& this.getTargetWeight() != null;
}

public boolean checkIfBeforeSignUp(LocalDateTime checkDateTime) {
return checkDateTime.isBefore(this.getCreatedDate());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.gaebaljip.exceed.application.port.in.meal;

import java.time.LocalDateTime;

import com.gaebaljip.exceed.common.annotation.UseCase;

@UseCase
public interface ValidateBeforeSignUpUsecase {
void execute(Long memberId, LocalDateTime dateTime);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import org.springframework.stereotype.Component;

import com.gaebaljip.exceed.application.domain.meal.Meal;
import com.gaebaljip.exceed.common.dto.TodayMealDTO;
import com.gaebaljip.exceed.common.dto.DailyMealDTO;

@Component
public interface DailyMealPort {
List<Meal> query(TodayMealDTO todayMealDTO);
List<Meal> query(DailyMealDTO dailyMealDTO);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public interface HistoryPort {
HistoryEntity command(HistoryEntity historyEntity);

HistoryEntity findByMemberIdAndDate(Long memberId, LocalDateTime date);
HistoryEntity findMostRecentFutureMember(Long memberId, LocalDateTime date);

List<HistoryEntity> findByMemberEntity(MemberEntity memberEntity);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface MemberPort {

MemberEntity findCheckedMemberByEmail(String email);

Optional<MemberEntity> findByIdAndDate(Long memberId, LocalDateTime date);
Optional<MemberEntity> findMemberBeforeDate(Long memberId, LocalDateTime date);

Boolean existsByEmail(String email);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import com.gaebaljip.exceed.application.port.in.meal.GetCurrentMealQuery;
import com.gaebaljip.exceed.application.port.out.meal.DailyMealPort;
import com.gaebaljip.exceed.common.dto.CurrentMealDTO;
import com.gaebaljip.exceed.common.dto.TodayMealDTO;
import com.gaebaljip.exceed.common.exception.meal.InvalidMultipleException;
import com.gaebaljip.exceed.common.dto.DailyMealDTO;
import com.gaebaljip.exceed.common.exception.meal.NotSameDateException;

import lombok.RequiredArgsConstructor;

Expand All @@ -26,36 +26,24 @@
@RequiredArgsConstructor
public class GetCurrentMealService implements GetCurrentMealQuery {

public static final double ZERO = 0.0;
private final DailyMealPort dailyMealPort;

/**
* DailyMeal 도메인이 오늘 먹은 식사들을 분석하여 칼로리,단,탄,지 정보를 반환한다. 만약 식사 정보가 존재하지 않을 경우는 칼로리,단,탄,지 모두 ZERO를
* 반환한다.
* DailyMeal 도메인이 오늘 먹은 식사들을 분석하여 칼로리,단,탄,지 정보를 반환
*
* @param memberId : 누가 무엇을 언제 얼마나 먹었는 지에 대한 정보가 들어있다.
* @return mealId : 식사 엔티티의 PK
* @throws InvalidMultipleException : 0인분 이하거나 100인분 초과일 경우
* @param memberId : 누가 무엇을 언제 얼마나 먹었는 지에 대한 정보
* @return currentMealDTO : calorie, carbohydrate, protein, fat
* @throws NotSameDateException : 같은 날짜가 아닐 경우
*/
@Override
@Transactional(readOnly = true)
public CurrentMealDTO execute(Long memberId) {
List<Meal> meals = dailyMealPort.query(new TodayMealDTO(memberId, LocalDateTime.now()));
if (meals.isEmpty()) {
return CurrentMealDTO.builder()
.calorie(ZERO)
.carbohydrate(ZERO)
.fat(ZERO)
.protein(ZERO)
.build();
} else {
DailyMeal dailyMeal = new DailyMeal(meals);
return CurrentMealDTO.builder()
.calorie(dailyMeal.calculateCurrentCalorie())
.carbohydrate(dailyMeal.calculateCurrentCarbohydrate())
.fat(dailyMeal.calculateCurrentFat())
.protein(dailyMeal.calculateCurrentProtein())
.build();
}
List<Meal> meals = dailyMealPort.query(new DailyMealDTO(memberId, LocalDateTime.now()));
DailyMeal dailyMeal = new DailyMeal(meals);
return CurrentMealDTO.of(
dailyMeal.calculateCurrentCalorie(),
dailyMeal.calculateCurrentCarbohydrate(),
dailyMeal.calculateCurrentProtein(),
dailyMeal.calculateCurrentFat());
}
}
Loading
Loading