File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
src/main/java/com/example/helper Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 1010import lombok .extern .slf4j .Slf4j ;
1111import org .springframework .beans .BeanUtils ;
1212import org .springframework .beans .factory .annotation .Autowired ;
13+ import org .springframework .http .HttpStatus ;
1314import org .springframework .web .bind .annotation .*;
1415
1516import java .util .ArrayList ;
1617import java .util .HashMap ;
1718import java .util .List ;
1819import java .util .Map ;
20+ import org .springframework .web .server .ResponseStatusException ;
1921
2022
2123@ RestController // @Controller + @ResponseBody. return이 view가 아닌, http body에 직접 쓰여짐.
@@ -253,8 +255,12 @@ public DateMealDto DateMealRead(
253255 .date (day .toString ())
254256 .build ();
255257
256- DateMealDto dateMealDtoList = dateMealService .getDateMenus (dateReqDto );
257-
258- return dateMealDtoList ;
258+ try {
259+ DateMealDto dateMealDto = dateMealService .getDateMenus (dateReqDto );
260+ return dateMealDto ;
261+ } catch (IllegalStateException e ) {
262+ throw new ResponseStatusException (
263+ HttpStatus .NOT_ACCEPTABLE , e .getMessage ());
264+ }
259265 }
260266}
Original file line number Diff line number Diff line change @@ -28,7 +28,9 @@ public DateMealDto getDateMenus(DateReqDto dateReqDto) {
2828 .build ();
2929
3030 // TODO: exception handling(target data is not in DB)
31-
31+ if (checkMenusEmpty (result )) {
32+ throw new IllegalStateException ("해당 날짜의 식단이 존재하지 않습니다." );
33+ }
3234 return result ;
3335 }
3436
@@ -71,4 +73,11 @@ public String padZero(String str) {
7173 }
7274 return result ;
7375 }
76+
77+ public boolean checkMenusEmpty (DateMealDto dateMealDto ) {
78+ return dateMealDto .getBreakfast ().isEmpty () &&
79+ dateMealDto .getLunch ().isEmpty () &&
80+ dateMealDto .getDinner ().isEmpty () &&
81+ dateMealDto .getLunch_corner ().isEmpty ();
82+ }
7483}
You can’t perform that action at this time.
0 commit comments