Skip to content

Commit 8714a87

Browse files
김산김산
authored andcommitted
[#7] Feat: specific meal input is developed
1 parent fc94ca5 commit 8714a87

File tree

1 file changed

+61
-13
lines changed

1 file changed

+61
-13
lines changed

src/main/java/com/example/helper/controller/MealController.java

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@
77
import com.example.helper.service.MealService;
88
import com.fasterxml.jackson.core.JsonProcessingException;
99
import com.fasterxml.jackson.databind.ObjectMapper;
10-
import jakarta.servlet.http.HttpServletRequest;
10+
import java.util.Map.Entry;
1111
import lombok.extern.slf4j.Slf4j;
1212
import org.springframework.beans.BeanUtils;
1313
import org.springframework.beans.factory.annotation.Autowired;
1414
import org.springframework.http.HttpStatus;
1515
import org.springframework.web.bind.annotation.*;
1616

17-
import java.util.ArrayList;
1817
import java.util.HashMap;
19-
import java.util.List;
2018
import java.util.Map;
2119
import org.springframework.web.server.ResponseStatusException;
2220

@@ -86,16 +84,66 @@ public Map<String, Object> readEngMeal() throws JsonProcessingException {
8684
return responseBody;
8785
}
8886

87+
@PostMapping("/spectest")
88+
public Map<String, Object> readSpecKortest(@RequestBody Map<String, Object> requestBody) throws JsonProcessingException {
89+
// input : 날짜요일내일 + 아점저 + 1/2학
90+
// output : 한국어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.)
91+
92+
Map<String, Object> action = new HashMap<>();
93+
action.put("action", requestBody.get("action"));
94+
95+
Map<String, Object> params = new HashMap<>();
96+
params.put("params", action.get("action"));
97+
98+
Map<String, Object> paramssss = new HashMap<>();
99+
paramssss.put("params", params.get("params"));
100+
101+
String dateCustom = (String) paramssss.get("dateCustom");
102+
String bld = (String) paramssss.get("bld");
103+
104+
log.info("req body : " + requestBody.toString());
105+
log.info("action body : " + action.toString());
106+
log.info("params body : " + params.toString());
107+
log.info("paramssss body : " + paramssss.toString());
108+
109+
for (Entry<String, Object> entrySet : requestBody.entrySet()) {
110+
log.info(entrySet.getKey() + " : " + entrySet.getValue());
111+
}
112+
113+
log.info("###########RESULT############");
114+
log.info(dateCustom + " " + bld);
115+
log.info(dateCustom + " " + bld);
116+
117+
ObjectMapper objectMapper = new ObjectMapper();
118+
Map<String, Object> action2 = objectMapper.convertValue(requestBody.get("action"), Map.class);
119+
Map<String, Object> params2 = objectMapper.convertValue(action2.get("params"), Map.class);
120+
log.info(params2.get("dateCustom").toString() + " " + params2.get("bld").toString());
121+
122+
//Map<String, String> params2 = new HashMap<>();
123+
//params2.put()
124+
//log.info(params2.get("dateCustom") + " " + params2.get("bld"));
125+
126+
String specMeal = mealService.getSpecKorMeal(dateCustom, bld);
127+
Map<String, Object> responseBody = mealService.responseMeal(specMeal);
128+
129+
// if need to stratify.
130+
// ObjectMapper objectMapper = new ObjectMapper();
131+
// String result = objectMapper.writeValueAsString(responseBody);
132+
133+
return responseBody;
134+
}
135+
89136
@PostMapping("/speckor")
90-
public Map<String, Object> readSpecKorMeal(@RequestBody Map<String, Map<String, Map<String, String>>> requestBody) throws JsonProcessingException {
137+
public Map<String, Object> readSpecKorMeal(@RequestBody Map<String, Map<String, Map<String, Object>>> requestBody) throws JsonProcessingException {
91138
// input : 날짜요일내일 + 아점저 + 1/2학
92139
// output : 한국어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.)
93140

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");
141+
Map<String, Map<String, Object>> action = requestBody.get("action");
142+
Map<String, Object> params = action.get("params");
143+
String dateCustom = (String) params.get("dateCustom");
144+
String bld = (String) params.get("bld");
98145

146+
log.info(dateCustom + " " + bld);
99147
log.info(dateCustom + " " + bld);
100148

101149
String specMeal = mealService.getSpecKorMeal(dateCustom, bld);
@@ -109,14 +157,14 @@ public Map<String, Object> readSpecKorMeal(@RequestBody Map<String, Map<String,
109157
}
110158

111159
@PostMapping("/speceng")
112-
public Map<String, Object> readSpecEngMeal(@RequestBody Map<String, Map<String, Map<String, String>>> requestBody) throws JsonProcessingException {
160+
public Map<String, Object> readSpecEngMeal(@RequestBody Map<String, Map<String, Map<String, Object>>> requestBody) throws JsonProcessingException {
113161
// input : 날짜요일내일 + 아점저 + 1/2학
114162
// output : 영어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.)
115163

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");
164+
Map<String, Map<String, Object>> action = requestBody.get("action");
165+
Map<String, Object> params = action.get("params");
166+
String dateCustom = (String) params.get("dateCustom");
167+
String bld = (String) params.get("bld");
120168

121169
log.info(dateCustom + " " + bld);
122170

0 commit comments

Comments
 (0)