|
4 | 4 | import com.example.helper.service.MealService; |
5 | 5 | import com.fasterxml.jackson.core.JsonProcessingException; |
6 | 6 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 7 | +import jakarta.servlet.http.HttpServletRequest; |
7 | 8 | import lombok.extern.slf4j.Slf4j; |
8 | 9 | import org.springframework.beans.BeanUtils; |
9 | 10 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -48,182 +49,76 @@ public String hello() { |
48 | 49 | } |
49 | 50 |
|
50 | 51 | @PostMapping("/kor") |
51 | | - public @ResponseBody String readKorMeal() throws JsonProcessingException { |
| 52 | + public Map<String, Object> readKorMeal() throws JsonProcessingException { |
52 | 53 | // input : None (먼저 서버에서 현재 시간 측정) |
53 | 54 | // output : 한국어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.) |
54 | 55 |
|
55 | | - // TODO 아래 기능 구현해 주세요. |
56 | 56 | String nowMeal = mealService.getNowKorMeal(); |
| 57 | + Map<String, Object> responseBody = mealService.responseMeal(nowMeal); |
57 | 58 |
|
58 | | - // Response Body Construct |
59 | | - // TODO 더 좋은 방식이 있으면 구현해 주세요. ex) dto 이용. |
60 | | - // const responseBody = { |
61 | | - // version: "2.0", |
62 | | - // template: { |
63 | | - // outputs: [ |
64 | | - // { |
65 | | - // simpleText: { |
66 | | - // text: nowMeal |
67 | | - // } |
68 | | - // } |
69 | | - // ] |
70 | | - // } |
71 | | - // }; |
72 | | - |
73 | | - Map<String, Object> simpleText = new HashMap<>(); |
74 | | - simpleText.put("text", nowMeal); |
75 | | - |
76 | | - Map<String, Object> simpleTextWrapper = new HashMap<>(); |
77 | | - simpleTextWrapper.put("simpleText", simpleText); |
78 | | - |
79 | | - List<Object> outputs = new ArrayList(1); |
80 | | - outputs.add(simpleTextWrapper); |
81 | | - |
82 | | - Map<String, Object> template = new HashMap<>(); |
83 | | - template.put("outputs", outputs); |
84 | | - |
85 | | - Map<String, Object> responseBody = new HashMap<>(); |
86 | | - responseBody.put("version", "2.0"); |
87 | | - responseBody.put("template", template); |
88 | | - |
89 | | - ObjectMapper objectMapper = new ObjectMapper(); |
90 | | - String result = objectMapper.writeValueAsString(responseBody); |
91 | | - |
92 | | - return result; |
| 59 | + // if need to stratify. |
| 60 | + // ObjectMapper objectMapper = new ObjectMapper(); |
| 61 | + // String result = objectMapper.writeValueAsString(responseBody); |
| 62 | + |
| 63 | + return responseBody; |
93 | 64 | } |
94 | 65 |
|
95 | 66 | @PostMapping("/eng") |
96 | | - public @ResponseBody String readEngMeal() throws JsonProcessingException { |
| 67 | + public Map<String, Object> readEngMeal() throws JsonProcessingException { |
97 | 68 | // input : None (먼저 서버에서 현재 시간 측정) |
98 | 69 | // output : 영어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.) |
99 | 70 |
|
100 | | - // TODO 아래 기능 구현해 주세요. |
101 | 71 | String nowMeal = mealService.getNowEngMeal(); |
| 72 | + Map<String, Object> responseBody = mealService.responseMeal(nowMeal); |
| 73 | + |
| 74 | + // if need to stratify. |
| 75 | + // ObjectMapper objectMapper = new ObjectMapper(); |
| 76 | + // String result = objectMapper.writeValueAsString(responseBody); |
102 | 77 |
|
103 | | - // Response Body Construct |
104 | | - // TODO 더 좋은 방식이 있으면 구현해 주세요. ex) dto 이용. |
105 | | - // const responseBody = { |
106 | | - // version: "2.0", |
107 | | - // template: { |
108 | | - // outputs: [ |
109 | | - // { |
110 | | - // simpleText: { |
111 | | - // text: nowMeal |
112 | | - // } |
113 | | - // } |
114 | | - // ] |
115 | | - // } |
116 | | - // }; |
117 | | - |
118 | | - Map<String, Object> simpleText = new HashMap<>(); |
119 | | - simpleText.put("text", nowMeal); |
120 | | - |
121 | | - Map<String, Object> simpleTextWrapper = new HashMap<>(); |
122 | | - simpleTextWrapper.put("simpleText", simpleText); |
123 | | - |
124 | | - List<Object> outputs = new ArrayList(1); |
125 | | - outputs.add(simpleTextWrapper); |
126 | | - |
127 | | - Map<String, Object> template = new HashMap<>(); |
128 | | - template.put("outputs", outputs); |
129 | | - |
130 | | - Map<String, Object> responseBody = new HashMap<>(); |
131 | | - responseBody.put("version", "2.0"); |
132 | | - responseBody.put("template", template); |
133 | | - |
134 | | - ObjectMapper objectMapper = new ObjectMapper(); |
135 | | - String result = objectMapper.writeValueAsString(responseBody); |
136 | | - |
137 | | - return result; |
| 78 | + return responseBody; |
138 | 79 | } |
139 | 80 |
|
140 | 81 | @PostMapping("/speckor") |
141 | | - public @ResponseBody String readSpecKorMeal() throws JsonProcessingException { |
| 82 | + public Map<String, Object> readSpecKorMeal(@RequestBody Map<String, Map<String, Map<String, String>>> requestBody) throws JsonProcessingException { |
142 | 83 | // input : 날짜요일내일 + 아점저 + 1/2학 |
143 | 84 | // output : 한국어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.) |
144 | 85 |
|
145 | | - // TODO 아래 기능 구현해 주세요. |
146 | | - String specMeal = mealService.getSpecKorMeal(); |
147 | | - |
148 | | - // Response Body Construct |
149 | | - // TODO 더 좋은 방식이 있으면 구현해 주세요. ex) dto 이용. |
150 | | - // const responseBody = { |
151 | | - // version: "2.0", |
152 | | - // template: { |
153 | | - // outputs: [ |
154 | | - // { |
155 | | - // simpleText: { |
156 | | - // text: specMeal |
157 | | - // } |
158 | | - // } |
159 | | - // ] |
160 | | - // } |
161 | | - // }; |
162 | | - |
163 | | - Map<String, Object> simpleText = new HashMap<>(); |
164 | | - simpleText.put("text", specMeal); |
165 | | - |
166 | | - Map<String, Object> simpleTextWrapper = new HashMap<>(); |
167 | | - simpleTextWrapper.put("simpleText", simpleText); |
| 86 | + Map<String, Map<String, String>> action = requestBody.get("action"); |
| 87 | + Map<String, String> params = action.get("params"); |
| 88 | + String dateCustom = params.get("dateCustom"); |
| 89 | + String bld = params.get("bld"); |
168 | 90 |
|
169 | | - List<Object> outputs = new ArrayList(1); |
170 | | - outputs.add(simpleTextWrapper); |
| 91 | + log.info(dateCustom + " " + bld); |
171 | 92 |
|
172 | | - Map<String, Object> template = new HashMap<>(); |
173 | | - template.put("outputs", outputs); |
| 93 | + String specMeal = mealService.getSpecKorMeal(dateCustom, bld); |
| 94 | + Map<String, Object> responseBody = mealService.responseMeal(specMeal); |
174 | 95 |
|
175 | | - Map<String, Object> responseBody = new HashMap<>(); |
176 | | - responseBody.put("version", "2.0"); |
177 | | - responseBody.put("template", template); |
| 96 | + // if need to stratify. |
| 97 | + // ObjectMapper objectMapper = new ObjectMapper(); |
| 98 | + // String result = objectMapper.writeValueAsString(responseBody); |
178 | 99 |
|
179 | | - ObjectMapper objectMapper = new ObjectMapper(); |
180 | | - String result = objectMapper.writeValueAsString(responseBody); |
181 | | - |
182 | | - return result; |
| 100 | + return responseBody; |
183 | 101 | } |
184 | 102 |
|
185 | 103 | @PostMapping("/speceng") |
186 | | - public @ResponseBody String readSpecEngMeal() throws JsonProcessingException { |
| 104 | + public Map<String, Object> readSpecEngMeal(@RequestBody Map<String, Map<String, Map<String, String>>> requestBody) throws JsonProcessingException { |
187 | 105 | // input : 날짜요일내일 + 아점저 + 1/2학 |
188 | 106 | // output : 영어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.) |
189 | 107 |
|
190 | | - // TODO 아래 기능 구현해 주세요. |
191 | | - String specMeal = mealService.getSpecEngMeal(); |
192 | | - |
193 | | - // Response Body Construct |
194 | | - // TODO 더 좋은 방식이 있으면 구현해 주세요. ex) dto 이용. |
195 | | - // const responseBody = { |
196 | | - // version: "2.0", |
197 | | - // template: { |
198 | | - // outputs: [ |
199 | | - // { |
200 | | - // simpleText: { |
201 | | - // text: specMeal |
202 | | - // } |
203 | | - // } |
204 | | - // ] |
205 | | - // } |
206 | | - // }; |
207 | | - |
208 | | - Map<String, Object> simpleText = new HashMap<>(); |
209 | | - simpleText.put("text", specMeal); |
210 | | - |
211 | | - Map<String, Object> simpleTextWrapper = new HashMap<>(); |
212 | | - simpleTextWrapper.put("simpleText", simpleText); |
213 | | - |
214 | | - List<Object> outputs = new ArrayList(1); |
215 | | - outputs.add(simpleTextWrapper); |
| 108 | + Map<String, Map<String, String>> action = requestBody.get("action"); |
| 109 | + Map<String, String> params = action.get("params"); |
| 110 | + String dateCustom = params.get("dateCustom"); |
| 111 | + String bld = params.get("bld"); |
216 | 112 |
|
217 | | - Map<String, Object> template = new HashMap<>(); |
218 | | - template.put("outputs", outputs); |
| 113 | + log.info(dateCustom + " " + bld); |
219 | 114 |
|
220 | | - Map<String, Object> responseBody = new HashMap<>(); |
221 | | - responseBody.put("version", "2.0"); |
222 | | - responseBody.put("template", template); |
| 115 | + String specMeal = mealService.getSpecEngMeal(dateCustom, bld); |
| 116 | + Map<String, Object> responseBody = mealService.responseMeal(specMeal); |
223 | 117 |
|
224 | | - ObjectMapper objectMapper = new ObjectMapper(); |
225 | | - String result = objectMapper.writeValueAsString(responseBody); |
| 118 | + // if need to stratify. |
| 119 | + // ObjectMapper objectMapper = new ObjectMapper(); |
| 120 | + // String result = objectMapper.writeValueAsString(responseBody); |
226 | 121 |
|
227 | | - return result; |
| 122 | + return responseBody; |
228 | 123 | } |
229 | 124 | } |
0 commit comments