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

운영 환경 반영 #473

Merged
merged 15 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gaebaljip.exceed.adapter.in.food.response;

import com.gaebaljip.exceed.adapter.out.jpa.food.FoodEntity;
import com.gaebaljip.exceed.application.domain.food.FoodEntity;

public record GetFoodResponse(
Long foodId,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.gaebaljip.exceed.application.domain.food.FoodEntity;
import com.gaebaljip.exceed.application.domain.member.MemberEntity;

public interface FoodRepository extends JpaRepository<FoodEntity, Long> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import org.springframework.stereotype.Component;

import com.gaebaljip.exceed.application.domain.food.FoodEntity;
import com.gaebaljip.exceed.application.domain.member.MemberEntity;
import com.gaebaljip.exceed.application.port.out.food.FoodPort;
import com.gaebaljip.exceed.common.exception.food.FoodNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import org.springframework.stereotype.Repository;

import com.gaebaljip.exceed.application.domain.food.FoodEntity;
import com.gaebaljip.exceed.application.domain.food.QFoodEntity;
import com.gaebaljip.exceed.common.dto.PageableFoodDTO;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
import org.springframework.stereotype.Component;

import com.gaebaljip.exceed.adapter.out.jpa.nutritionist.MonthlyMealPort;
import com.gaebaljip.exceed.application.domain.meal.DailyMeal;
import com.gaebaljip.exceed.application.domain.meal.Meal;
import com.gaebaljip.exceed.application.domain.meal.DailyMealFoods;
import com.gaebaljip.exceed.application.domain.meal.MealEntity;
import com.gaebaljip.exceed.application.domain.meal.MealFoodEntity;
import com.gaebaljip.exceed.application.domain.member.MemberEntity;
Expand All @@ -30,7 +29,6 @@
public class MealPersistenceAdapter implements MealPort, DailyMealPort, MonthlyMealPort {

private final MealRepository mealRepository;
private final MealFoodConverter mealFoodConverter;
private final MealFoodRepository mealFoodRepository;

@Override
Expand All @@ -40,14 +38,29 @@ public MealEntity command(MealEntity mealEntity) {

@Override
@Timer
public List<Meal> query(DailyMealDTO dailyMealDTO) {
public DailyMealFoods queryDailyMealFoods(DailyMealDTO dailyMealDTO) {
LocalDateTime today = dailyMealDTO.date().toLocalDate().atStartOfDay();
LocalDateTime tomorrow = today.plusDays(1);
List<Long> mealIds =
mealRepository.findMealIdsByMemberAndDaily(
today, tomorrow, dailyMealDTO.memberId());
List<MealFoodEntity> mealFoodEntities = mealFoodRepository.findMFTByIdInQuery(mealIds);
return mealFoodConverter.toMeals(mealFoodEntities);
return new DailyMealFoods(mealFoodEntities);
}

@Override
public List<MealEntity> queryMeals(DailyMealDTO dailyMealDTO) {
LocalDateTime today = dailyMealDTO.date().toLocalDate().atStartOfDay();
LocalDateTime tomorrow = today.plusDays(1);
List<MealEntity> mealEntities =
mealRepository.findMealsByMemberAndDaily(today, tomorrow, dailyMealDTO.memberId());
return mealEntities;
}

@Override
public DailyMealFoods queryMealFoods(List<Long> mealIds) {
List<MealFoodEntity> mealFoodEntities = mealFoodRepository.findMFTByIdInQuery(mealIds);
return new DailyMealFoods(mealFoodEntities);
}

@Override
Expand All @@ -61,20 +74,18 @@ public MonthlyMeal query(MonthlyMealDTO monthlyMealDTO) {
mealRepository.findMealIdsByMemberAndMonth(
startOfMonth, endOfMonth, monthlyMealDTO.memberId());
List<MealFoodEntity> mealFoodEntities = mealFoodRepository.findMFTByIdInQuery(mealIds);

List<Meal> meals = mealFoodConverter.toMeals(mealFoodEntities);
Map<LocalDate, DailyMeal> monthlyMeal =
meals.stream()
Map<LocalDate, DailyMealFoods> monthlyMeal =
mealFoodEntities.stream()
.collect(
Collectors.groupingBy(
meal -> meal.getMealDateTime().toLocalDate(),
mealFood -> mealFood.getCreatedDate().toLocalDate(),
Collectors.collectingAndThen(
Collectors.toList(), DailyMeal::new)));
List<Meal> emptyMeal = new ArrayList<>();
Collectors.toList(), DailyMealFoods::new)));
List<MealFoodEntity> emptyMealFood = new ArrayList<>();
startOfMonth
.toLocalDate()
.datesUntil(endOfMonth.toLocalDate())
.forEach(day -> monthlyMeal.putIfAbsent(day, new DailyMeal(emptyMeal)));
.forEach(day -> monthlyMeal.putIfAbsent(day, new DailyMealFoods(emptyMealFood)));
return new MonthlyMeal(monthlyMeal);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public interface MealRepository extends JpaRepository<MealEntity, Long> {
List<Long> findMealIdsByMemberAndDaily(
LocalDateTime today, LocalDateTime tomorrow, Long memberId);

@Query(
"select m from MealEntity m where m.memberEntity.id = :memberId and m.createdDate >= :today and m.createdDate < :tomorrow")
List<MealEntity> findMealsByMemberAndDaily(
LocalDateTime today, LocalDateTime tomorrow, Long memberId);

@Timer
@Query(
"select m.id from MealEntity m where m.memberEntity.id = :memberId and m.createdDate >= :startOfMonth and m.createdDate < :endOfMonth")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gaebaljip.exceed.adapter.out.jpa.food;
package com.gaebaljip.exceed.application.domain.food;

import javax.persistence.*;

Expand Down

This file was deleted.

This file was deleted.

Loading
Loading