-
Notifications
You must be signed in to change notification settings - Fork 7
/
EatMealService.java
62 lines (54 loc) · 2.34 KB
/
EatMealService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.gaebaljip.exceed.application.service.meal;
import java.util.List;
import javax.transaction.Transactional;
import org.springframework.stereotype.Service;
import com.gaebaljip.exceed.application.domain.food.FoodEntity;
import com.gaebaljip.exceed.application.domain.meal.MealEntity;
import com.gaebaljip.exceed.application.domain.meal.MealFoodEntity;
import com.gaebaljip.exceed.application.domain.member.MemberEntity;
import com.gaebaljip.exceed.application.port.in.meal.EatMealCommand;
import com.gaebaljip.exceed.application.port.in.meal.EatMealUsecase;
import com.gaebaljip.exceed.application.port.out.food.FoodPort;
import com.gaebaljip.exceed.application.port.out.meal.MealFoodPort;
import com.gaebaljip.exceed.application.port.out.meal.MealPort;
import com.gaebaljip.exceed.application.port.out.member.MemberPort;
import com.gaebaljip.exceed.common.exception.meal.InvalidMultipleException;
import lombok.RequiredArgsConstructor;
/**
* 식사를 등록한다.
*
* @author hwangdaesun
* @version 1.0
*/
@Service
@RequiredArgsConstructor
public class EatMealService implements EatMealUsecase {
private final FoodPort foodPort;
private final MemberPort memberPort;
private final MealPort mealPort;
private final MealFoodPort mealFoodPort;
/**
* 몇 인분(multiple) 검증 식사를 등록한다.
*
* @param command : 누가 무엇을 언제 얼마나 먹었는 지에 대한 정보가 들어있다.
* @return mealId : 식사 엔티티의 PK
* @throws InvalidMultipleException : 0인분 이하거나 100인분 초과일 경우
*/
@Override
@Transactional
public Long execute(EatMealCommand command) {
List<FoodEntity> foodEntities =
foodPort.queryAllEntities(
command.eatMealFoodDTOS().stream()
.mapToLong(eatMealFood -> eatMealFood.foodId())
.boxed()
.toList());
MemberEntity memberEntity = memberPort.query(command.memberId());
MealEntity mealEntity =
mealPort.command(MealEntity.createMeal(memberEntity, command.mealType()));
mealFoodPort.command(
MealFoodEntity.createMealFoods(
foodEntities, mealEntity, command.eatMealFoodDTOS()));
return mealEntity.getId();
}
}