@@ -102,36 +102,50 @@ public String getNowEngMeal() {
102102 return getNowMeal (Types .LANG_ENG .getType ());
103103 }
104104
105- public String getSpecKorMeal (String dateCustom , String bld ) {
105+ public String getSpecKorMeal (String dateCustom , String bld , LocalDateTime currentDateTime ) {
106+ // test를 위해 LocalDateTime 객체를 argument로 받도록 변경
107+
106108 if (!specInputValidation (dateCustom , bld )) {
107109 return Messages .NO_MEAL_KOR .getMessages ();
108110 }
109111
110- LocalDateTime currentDateTime = LocalDateTime .now (ZoneId .of ("Asia/Seoul" ));
111-
112- if (dateCustom .equals (SpecMealInputsKor .TODAY .getInputs ())) {
113- // 오늘
114- String date = currentDateTime .getYear () + "-" ;
115- date += String .format ("%02d" , currentDateTime .getMonth ().getValue ()) + "-" ;
116- date += String .format ("%02d" , currentDateTime .getDayOfMonth ()) + "" ;
117-
118- Optional <Meal > result = sqlMealRepository .findByDate (
119- Types .BLDG2_1ST .getType (),
120- Types .LANG_KOR .getType (),
121- SpecMealInputsKor .getTypeByString (bld ),
122- date );
123- }
124- else if (dateCustom .equals (SpecMealInputsKor .TOMORROW .getInputs ())) {
125- // 내일
126- }
127- else if (dateCustom .length () == 1 ) {
128- // 요일
112+ try {
113+ if (dateCustom .equals (SpecMealInputsKor .TOMORROW .getInputs ())) {
114+ // 내일
115+ currentDateTime = currentDateTime .plusDays (1 );
116+ } else if (dateCustom .length () == 1 ) {
117+ // 요일
118+ Integer dateDiff = getDateDifference (dateCustom , currentDateTime );
119+ currentDateTime = currentDateTime .plusDays (dateDiff );
120+ } else if ((dateCustom .charAt (dateCustom .length () - 1 ) + "" ).equals (SpecMealInputsKor .DAY .getInputs ())) {
121+ // 특정날짜
122+ currentDateTime = currentDateTime .withDayOfMonth (
123+ Integer .parseInt (dateCustom .substring (0 , dateCustom .length () - 1 )));
124+ }
125+ } catch (Exception e ) {
126+ return Messages .INVALID_DATE .getMessages ();
129127 }
130- else if ((dateCustom .charAt (dateCustom .length () - 1 ) + "" ).equals (SpecMealInputsKor .DAY .getInputs ())) {
131- // 특정날짜
128+
129+ String date = currentDateTime .getYear () + "-" ;
130+ date += String .format ("%02d" , currentDateTime .getMonth ().getValue ()) + "-" ;
131+ date += String .format ("%02d" , currentDateTime .getDayOfMonth ()) + "" ;
132+
133+ Optional <Meal > result = sqlMealRepository .findByDate (
134+ Types .BLDG2_1ST .getType (),
135+ Types .LANG_KOR .getType (),
136+ SpecMealInputsKor .getTypeByString (bld ),
137+ date );
138+
139+ // TODO : 존재하지 않는 식단이면, error message 반환.
140+ if (result .isEmpty ()) {
141+ return Messages .NO_MEAL_KOR .getMessages ();
132142 }
133143
134- return "2023-01-27 조식\n \n 제2학생회관1층\n \n 흰밥*김가루양념밥\n " ;
144+ return result .get ().generateMenu ();
145+ }
146+
147+ public Integer getDateDifference (String day , LocalDateTime currentDateTime ) {
148+ return (Integer ) currentDateTime .getDayOfWeek ().getValue () - SpecMealInputsKor .getTypeByString (day );
135149 }
136150
137151 public String getSpecEngMeal (String dateCustom , String bld ) {
0 commit comments