Skip to content

Commit

Permalink
#121 식단 조회 API 원복구
Browse files Browse the repository at this point in the history
- 프론트 요구사항 반영으로 복구하였습니다.
  • Loading branch information
Qbeom0925 committed May 13, 2023
1 parent 702fc57 commit 919972a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public class MealCreateReq {
@NotNull(message = "식당 지역 값은 필수입니다.")
private String area;

@ApiModelProperty(value = "메뉴1,메뉴2,메뉴3,메뉴4,메뉴5", example = "계란볶음밥,된장국,김치,단무지", required = true, dataType = "String")
// @ApiModelProperty(value = "메뉴1,메뉴2,메뉴3,메뉴4,메뉴5", example = "계란볶음밥,된장국,김치,단무지", required = true, dataType = "String")
// @NotNull(message = "메뉴 값은 필수입니다.")
// private String meals;

@NotNull(message = "메뉴 값은 필수입니다.")
private String meals;
private List<String> meals;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public static List<MealResponse> toEntity(List<Meal> meals) {
.toDay(meal.getOfferedAt())
.statusType(meal.getStatusType())
.mealType(meal.getMealType())
.meals(Arrays.asList(meal.getMenus().split(",")))
// .meals(Arrays.asList(meal.getMenus().split(",")))
.meals(List.of(meal.getMenu1(), meal.getMenu2(), meal.getMenu3(), meal.getMenu4(), meal.getMenu5(),meal.getMenu6()))
.build()).collect(Collectors.toList());
}
}
11 changes: 9 additions & 2 deletions src/main/java/com/example/myongsick/domain/meal/entity/Meal.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,20 @@ public class Meal {

@Builder
public Meal(MealType mealType,
String menus,
List<String> menus,
// String menus,
LocalDate offeredAt,
Week week,
Area area,
StatusType statusType) {
this.mealType = mealType;
this.menus = menus;
this.menu1 = menus.get(0);
this.menu2 = menus.get(1);
this.menu3 = menus.get(2);
this.menu4 = menus.get(3);
this.menu5 = menus.get(4);
this.menu6 = menus.get(5);
// this.menus = menus;
this.statusType = statusType;
this.offeredAt = offeredAt;
this.love = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
Expand All @@ -31,7 +32,7 @@ public class MealServiceImpl implements MealService {
@Override
public List<MealResponse> getWeekFoods(String area) {
Week week = weekRepository.findByStartDayLessThanEqualAndEndDayGreaterThanEqual(LocalDate.now(), LocalDate.now()).get();
Meal meal = week.getMealList().get(0);
// Meal meal = week.getMealList().get(0);
// List<Meal> mealList = (List<Meal>) meal;
return MealResponse.toEntity(mealRepository.findByWeekAndAreaOrderByArea(week, areaRepository.findByName(area).get()));
}
Expand All @@ -51,8 +52,7 @@ public Boolean createMeal(MealCreateReq mealCreateReq) {
mealRepository.save(Meal.builder()
.mealType(MealType.valueOf(mealCreateReq.getType()))
.area(areaRepository.findByName(mealCreateReq.getArea()).orElseThrow(NotFoundAreaException::new))
.week(weekRepository.findByStartDayLessThanEqualAndEndDayGreaterThanEqual(mealCreateReq.getOfferedAt(), mealCreateReq.getOfferedAt()).orElseThrow(
NotFoundWeekException::new))
.week(weekRepository.findByStartDayLessThanEqualAndEndDayGreaterThanEqual(mealCreateReq.getOfferedAt(), mealCreateReq.getOfferedAt()).orElseThrow(NotFoundWeekException::new))
.offeredAt(mealCreateReq.getOfferedAt())
.statusType(StatusType.valueOf(mealCreateReq.getStatus()))
.menus(mealCreateReq.getMeals())
Expand Down Expand Up @@ -84,7 +84,8 @@ public Boolean notRegisterMeal(MealNotRegisterReq mealNotRegisterReq) {
Area area = areaRepository.findByName(mealNotRegisterReq.getArea()).orElseThrow(NotFoundAreaException::new);
List<Meal> meals = new ArrayList<>();
for(int i = 0; i < 5; i++){
Week week = weekRepository.findByStartDayLessThanEqualAndEndDayGreaterThanEqual(mealNotRegisterReq.getStartedAt().plusDays(i), mealNotRegisterReq.getStartedAt().plusDays(i)).orElseThrow(NotFoundAreaException::new);
Optional<Week> byStartDayLessThanEqualAndEndDayGreaterThanEqual = weekRepository.findByStartDayLessThanEqualAndEndDayGreaterThanEqual(mealNotRegisterReq.getStartedAt().plusDays(i), mealNotRegisterReq.getStartedAt().plusDays(i));
Week week = byStartDayLessThanEqualAndEndDayGreaterThanEqual.orElseThrow(NotFoundAreaException::new);
for(int j = 0; j < MealType.values().length; j++){
if (!area.getName().equals("MCC식당") && !area.getName().equals("명진당식당") && MealType.values()[j].equals(MealType.LUNCH_B)){
continue;
Expand All @@ -102,7 +103,8 @@ private void addMeals(MealNotRegisterReq mealNotRegisterReq, Area area, List<Mea
.area(area)
.week(week)
.mealType(MealType.values()[j])
.menus("등록된 식단내용이(가) 없습니다.")
// .menus("등록된 식단내용이(가) 없습니다.")
.menus(List.of("","등록된 식단내용이(가) 없습니다.","","","",""))
.offeredAt(mealNotRegisterReq.getStartedAt().plusDays(i))
.statusType(StatusType.OPEN)
.build()
Expand Down

0 comments on commit 919972a

Please sign in to comment.