11package com .example .helper .controller ;
2+ import com .example .helper .dto .DateMealDto ;
3+ import com .example .helper .dto .DateReqDto ;
24import com .example .helper .dto .Mealdto ;
35import com .example .helper .entity .Meal ;
6+ import com .example .helper .service .DateMealService ;
47import com .example .helper .service .MealService ;
58import com .fasterxml .jackson .core .JsonProcessingException ;
69import com .fasterxml .jackson .databind .ObjectMapper ;
710import lombok .extern .slf4j .Slf4j ;
811import org .springframework .beans .BeanUtils ;
912import org .springframework .beans .factory .annotation .Autowired ;
13+ import org .springframework .http .HttpStatus ;
1014import org .springframework .web .bind .annotation .*;
1115
1216import java .util .ArrayList ;
1317import java .util .HashMap ;
1418import java .util .List ;
1519import java .util .Map ;
20+ import org .springframework .web .server .ResponseStatusException ;
1621
1722
18- @ RestController
23+ @ RestController // @Controller + @ResponseBody. return이 view가 아닌, http body에 직접 쓰여짐.
1924@ RequestMapping (path = "/meals" , produces = "application/json;charset=UTF-8" )
2025@ Slf4j
2126public class MealController {
2227
2328 @ Autowired
2429 private MealService mealService ;
2530
31+ @ Autowired
32+ private DateMealService dateMealService ;
33+
2634 @ GetMapping ("/all" )
2735 public String hello () {
2836 return "Hello HELPERs. 초기 세팅 완료." ;
2937 }
3038
3139 @ PostMapping ("/test" )
32- public @ ResponseBody void test (String testStr ) {
40+ public void test (String testStr ) {
3341 log .info (testStr );
3442 }
43+
3544 @ PostMapping ("/create" )
36- public @ ResponseBody String createMeal (@ RequestBody Mealdto mealDto ) {
45+ public String createMeal (@ RequestBody Mealdto mealDto ) {
3746 // input : 식단 json
3847 // output : None
3948
@@ -48,7 +57,7 @@ public String hello() {
4857 }
4958
5059 @ PostMapping ("/kor" )
51- public @ ResponseBody String readKorMeal () throws JsonProcessingException {
60+ public String readKorMeal () throws JsonProcessingException {
5261 // input : None (먼저 서버에서 현재 시간 측정)
5362 // output : 한국어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.)
5463
@@ -70,7 +79,7 @@ public String hello() {
7079 // }
7180 // };
7281
73- Map <String , Object > simpleText = new HashMap <>();
82+ Map <String , Object > simpleText = new HashMap <>();
7483 simpleText .put ("text" , nowMeal );
7584
7685 Map <String , Object > simpleTextWrapper = new HashMap <>();
@@ -93,7 +102,7 @@ public String hello() {
93102 }
94103
95104 @ PostMapping ("/eng" )
96- public @ ResponseBody String readEngMeal () throws JsonProcessingException {
105+ public String readEngMeal () throws JsonProcessingException {
97106 // input : None (먼저 서버에서 현재 시간 측정)
98107 // output : 영어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.)
99108
@@ -115,7 +124,7 @@ public String hello() {
115124 // }
116125 // };
117126
118- Map <String , Object > simpleText = new HashMap <>();
127+ Map <String , Object > simpleText = new HashMap <>();
119128 simpleText .put ("text" , nowMeal );
120129
121130 Map <String , Object > simpleTextWrapper = new HashMap <>();
@@ -138,7 +147,7 @@ public String hello() {
138147 }
139148
140149 @ PostMapping ("/speckor" )
141- public @ ResponseBody String readSpecKorMeal () throws JsonProcessingException {
150+ public String readSpecKorMeal () throws JsonProcessingException {
142151 // input : 날짜요일내일 + 아점저 + 1/2학
143152 // output : 한국어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.)
144153
@@ -160,7 +169,7 @@ public String hello() {
160169 // }
161170 // };
162171
163- Map <String , Object > simpleText = new HashMap <>();
172+ Map <String , Object > simpleText = new HashMap <>();
164173 simpleText .put ("text" , specMeal );
165174
166175 Map <String , Object > simpleTextWrapper = new HashMap <>();
@@ -183,7 +192,7 @@ public String hello() {
183192 }
184193
185194 @ PostMapping ("/speceng" )
186- public @ ResponseBody String readSpecEngMeal () throws JsonProcessingException {
195+ public String readSpecEngMeal () throws JsonProcessingException {
187196 // input : 날짜요일내일 + 아점저 + 1/2학
188197 // output : 영어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.)
189198
@@ -205,7 +214,7 @@ public String hello() {
205214 // }
206215 // };
207216
208- Map <String , Object > simpleText = new HashMap <>();
217+ Map <String , Object > simpleText = new HashMap <>();
209218 simpleText .put ("text" , specMeal );
210219
211220 Map <String , Object > simpleTextWrapper = new HashMap <>();
@@ -226,4 +235,32 @@ public String hello() {
226235
227236 return result ;
228237 }
238+
239+ // FE쪽에서 query에 담아주면 아래처럼 dto 객체 하나만 req로 받으면 되서 코드 깔끔함.
240+ // DateMealDto dateMealDtoList = dateMealService.getDateMeal(dateReqDto);
241+ // 근데 FE에서 보낼때 parameter 일일이 적기 귀찮으니 pathvariable로 받아서 처리
242+ @ GetMapping ("/date/{year}/{month}/{day}/{bldgType}/{langType}" )
243+ public DateMealDto DateMealRead (
244+ @ PathVariable ("langType" ) Integer langType ,
245+ @ PathVariable ("bldgType" ) Integer bldgType ,
246+ @ PathVariable ("year" ) Integer year ,
247+ @ PathVariable ("month" ) Integer month ,
248+ @ PathVariable ("day" ) Integer day ) {
249+
250+ DateReqDto dateReqDto = DateReqDto .builder ()
251+ .langType (langType )
252+ .bldgType (bldgType )
253+ .year (year .toString ())
254+ .month (month .toString ())
255+ .date (day .toString ())
256+ .build ();
257+
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+ }
265+ }
229266}
0 commit comments