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