Skip to content

Commit

Permalink
fix: 다음날 식단 메뉴에 operatingTime이 현재 날짜 기준이었음
Browse files Browse the repository at this point in the history
  • Loading branch information
jcw1031 committed Mar 3, 2024
1 parent f912ffa commit 7a3f5e0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 28 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.1.3'
id 'io.spring.dependency-management' version '1.1.3'
id 'org.springframework.boot' version '3.2.3'
id 'io.spring.dependency-management' version '1.1.4'
}

group = 'ac.knu'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Getter
Expand Down Expand Up @@ -40,7 +41,7 @@ public static MealListDto of(MealType mealType, Cafeteria cafeteria, Menu menu)

return MealListDto.builder()
.mealType(mealType.getMealTypeKr())
.operatingTime(cafeteria.getTime(mealType))
.operatingTime(cafeteria.getTime(mealType, menu.getMenuDate()))
.menus(menuList)
.date(menu.getMenuDate())
.build();
Expand All @@ -49,7 +50,7 @@ public static MealListDto of(MealType mealType, Cafeteria cafeteria, Menu menu)
public static MealListDto empty(MealType mealType, LocalDate date) {
return MealListDto.builder()
.mealType(mealType.getMealTypeKr())
.menus(new ArrayList<>())
.menus(Collections.emptyList())
.date(date)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ public static MenuResponse of(Cafeteria cafeteria, Map<LocalDate, List<MealListD
.tomorrow(mealList.get(keys.get(1)))
.build();
}

}
23 changes: 11 additions & 12 deletions src/main/java/ac/knu/likeknu/domain/Cafeteria.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -66,32 +66,31 @@ public Cafeteria(CafeteriaName cafeteriaName, String weekdayBreakfast, String we
this.campus = campus;
}

public String getTime(MealType mealType) {
if(mealType == null)
public String getTime(MealType mealType, LocalDate date) {
if (mealType == null)
return null;

if(isWeekend()) {
if (isWeekend(date)) {
//주말일 때
if(isBreakfast(mealType))
if (isBreakfast(mealType))
return weekendBreakfast;
else if(isLunch(mealType))
else if (isLunch(mealType))
return weekendLunch;
else
return weekendDinner;
}
else {
} else {
//평일일 때
if(isBreakfast(mealType))
if (isBreakfast(mealType))
return weekdayBreakfast;
else if(isLunch(mealType))
else if (isLunch(mealType))
return weekdayLunch;
else
return weekdayDinner;
}
}

private boolean isWeekend() {
return LocalDateTime.now().getDayOfWeek().getValue() >= 6;
private boolean isWeekend(LocalDate date) {
return date.getDayOfWeek().getValue() >= 6;
}

private boolean isBreakfast(MealType mealType) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/ac/knu/likeknu/service/MenuService.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ private MealListDto findRepositoryAndMapDto(MealType mealType, Cafeteria cafeter
.map(menu -> MealListDto.of(mealType, cafeteria, menu))
.orElse(MealListDto.empty(mealType, date));
}

}
11 changes: 1 addition & 10 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
spring.datasource.url=jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_SCHEMA}?characterEncoding=UTF-8&serverTimezone=UTC
spring.datasource.username=${DB_USERNAME}
spring.datasource.password=${DB_PASSWORD}

spring.jpa.hibernate.ddl-auto=validate

admin.username=${ADMIN_USERNAME}
admin.password=${ADMIN_PASSWORD}

slack.webhook=${SLACK_WEBHOOK}
spring.profiles.active=dev

0 comments on commit 7a3f5e0

Please sign in to comment.