Skip to content

Commit 4dd2d8e

Browse files
authored
Merge pull request #18 from gist-helper/specmeal
Specmeal
2 parents c4ffff2 + 0fbeddc commit 4dd2d8e

File tree

10 files changed

+424
-113
lines changed

10 files changed

+424
-113
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ dependencies {
2525

2626
testImplementation 'org.springframework.boot:spring-boot-starter-test'
2727
testImplementation 'org.junit.platform:junit-platform-launcher:1.5.0'
28-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.0'
29-
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.5.0'
28+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1'
29+
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.1'
3030

3131
}
3232

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.example.helper.constant;
2+
3+
public enum Messages {
4+
EXIST_MEAL_ERROR("이미 존재하는 식단입니다."),
5+
NO_EXIST_MEAL_ERROR("조건에 맞는 식단이 존재하지 않습니다."),
6+
NO_MEAL_KOR("식단 준비중입니다."),
7+
NO_MEAL_ENG("The meal is being prepared."),
8+
INVALID_DATE("유효하지 않은 날짜입니다."),
9+
DUMMY_MEAL_KOR("2023-01-27 조식\n\n제2학생회관1층\n\n흰밥*김가루양념밥\n"),
10+
DUMMY_MEAL_ENG("2023-01-27 Breakfast\n\nStudent Union Bldg.2 1st floor\n\nWhite rice*Seasoned rice with seaweed\n");
11+
private String message;
12+
Messages(String message) {
13+
this.message = message;
14+
}
15+
public String getMessages() {
16+
return message;
17+
}
18+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.example.helper.constant;
2+
3+
import jakarta.persistence.criteria.CriteriaBuilder;
4+
5+
public enum SpecMealInputsEng {
6+
TODAY("today"),
7+
TOMORROW("tomorrow"),
8+
MON("Mon", Types.DATE_MON.getType()),
9+
TUE("Tue", Types.DATE_TUE.getType()),
10+
WED("Wed", Types.DATE_WED.getType()),
11+
THR("Thr", Types.DATE_THR.getType()),
12+
FRI("Fri", Types.DATE_FRI.getType()),
13+
SAT("Sat", Types.DATE_SAT.getType()),
14+
SUN("Sun", Types.DATE_SUN.getType()),
15+
DAY_1("st"),
16+
DAY_2("nd"),
17+
DAY_3("rd"),
18+
DAY_OTHER("th"),
19+
BREAKFAST("breakfast", Types.KIND_BREAKFAST.getType()),
20+
LUNCH("lunch", Types.KIND_LUNCH.getType()),
21+
DINNER("dinner", Types.KIND_DINNER.getType());
22+
private String input;
23+
private Integer inputValue;
24+
SpecMealInputsEng (String input) {
25+
this.input = input;
26+
}
27+
28+
SpecMealInputsEng (String input, Integer inputValue) {
29+
this.input = input;
30+
this.inputValue = inputValue;
31+
}
32+
public String getInputs() {
33+
return input;
34+
}
35+
public Integer getInputValue() { return inputValue; }
36+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.example.helper.constant;
2+
3+
4+
public enum SpecMealInputsKor {
5+
TODAY("오늘"),
6+
TOMORROW("내일"),
7+
MON("월", Types.DATE_MON.getType()),
8+
TUE("화", Types.DATE_TUE.getType()),
9+
WED("수", Types.DATE_WED.getType()),
10+
THR("목", Types.DATE_THR.getType()),
11+
FRI("금", Types.DATE_FRI.getType()),
12+
SAT("토", Types.DATE_SAT.getType()),
13+
SUM("일", Types.DATE_SUN.getType()),
14+
DAY("일"),
15+
BREAKFAST("조식", Types.KIND_BREAKFAST.getType()),
16+
LUNCH("중식", Types.KIND_LUNCH.getType()),
17+
DINNER("석식", Types.KIND_DINNER.getType());
18+
private String input;
19+
private Integer inputValue;
20+
SpecMealInputsKor(String input) {
21+
this.input = input;
22+
}
23+
SpecMealInputsKor(String input, Integer inputValue) {
24+
this.input = input;
25+
this.inputValue = inputValue;
26+
}
27+
public String getInputs() {
28+
return input;
29+
}
30+
public Integer getInputValue() { return inputValue; }
31+
32+
public static Integer getTypeByString(String str){
33+
for(SpecMealInputsKor each : values())
34+
if (each.getInputs().equals(str)) {
35+
return each.getInputValue();
36+
}
37+
return -1;
38+
}
39+
}

src/main/java/com/example/helper/constant/Types.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ public enum Types {
99
KIND_BREAKFAST(0),
1010
KIND_LUNCH(1),
1111
KIND_DINNER(2),
12-
KIND_LUNCH_CORNER(3);
12+
KIND_LUNCH_CORNER(3),
13+
DATE_MON(1),
14+
DATE_TUE(2),
15+
DATE_WED(3),
16+
DATE_THR(4),
17+
DATE_FRI(5),
18+
DATE_SAT(6),
19+
DATE_SUN(7);
1320

1421
private Integer type;
1522

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

Lines changed: 31 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.example.helper.service.MealService;
88
import com.fasterxml.jackson.core.JsonProcessingException;
99
import com.fasterxml.jackson.databind.ObjectMapper;
10+
import java.time.LocalDateTime;
11+
import java.time.ZoneId;
1012
import java.util.Map.Entry;
1113
import lombok.extern.slf4j.Slf4j;
1214
import org.springframework.beans.BeanUtils;
@@ -50,9 +52,13 @@ public String createMeal(@RequestBody Mealdto mealDto) {
5052
BeanUtils.copyProperties(mealDto, meal);
5153

5254
// DB Save
53-
Long saved = mealService.mealCreate(meal);
54-
55-
return "saved";
55+
try {
56+
Long saved = mealService.mealCreate(meal);
57+
return "saved";
58+
} catch (IllegalStateException e) {
59+
throw new ResponseStatusException(
60+
HttpStatus.NOT_ACCEPTABLE, e.getMessage());
61+
}
5662
}
5763

5864
@PostMapping("/kor")
@@ -62,9 +68,6 @@ public Map<String, Object> readKorMeal() throws JsonProcessingException {
6268

6369
String nowMeal = mealService.getNowKorMeal();
6470
Map<String, Object> responseBody = mealService.responseMeal(nowMeal);
65-
// if need to stratify.
66-
// ObjectMapper objectMapper = new ObjectMapper();
67-
// String result = objectMapper.writeValueAsString(responseBody);
6871

6972
return responseBody;
7073
}
@@ -77,104 +80,50 @@ public Map<String, Object> readEngMeal() throws JsonProcessingException {
7780
String nowMeal = mealService.getNowEngMeal();
7881
Map<String, Object> responseBody = mealService.responseMeal(nowMeal);
7982

80-
// if need to stratify.
81-
// ObjectMapper objectMapper = new ObjectMapper();
82-
// String result = objectMapper.writeValueAsString(responseBody);
83-
8483
return responseBody;
8584
}
8685

87-
@PostMapping("/spectest")
88-
public Map<String, Object> readSpecKortest(@RequestBody Map<String, Object> requestBody) throws JsonProcessingException {
89-
// input : 날짜요일내일 + 아점저 + 1/2학
86+
@PostMapping("/speckor")
87+
public Map<String, Object> readSpecKorMeal(@RequestBody Map<String, Object> requestBody) throws JsonProcessingException {
88+
// input : 날짜요일내일 + 아점저
9089
// output : 한국어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.)
9190

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);
91+
// how to print the request body
92+
//for (Entry<String, Object> entrySet : requestBody.entrySet()) {
93+
// log.info(entrySet.getKey() + " : " + entrySet.getValue());
94+
//}
11695

11796
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());
97+
Map<String, Object> action = objectMapper.convertValue(requestBody.get("action"), Map.class);
98+
Map<String, Object> params = objectMapper.convertValue(action.get("params"), Map.class);
12199

122-
//Map<String, String> params2 = new HashMap<>();
123-
//params2.put()
124-
//log.info(params2.get("dateCustom") + " " + params2.get("bld"));
100+
//log.info(params2.get("dateCustom").toString() + " " + params2.get("bld").toString());
101+
String dateCustom = params.get("dateCustom").toString();
102+
String bld = params.get("bld").toString();
125103

126-
String specMeal = mealService.getSpecKorMeal(dateCustom, bld);
104+
LocalDateTime currentDateTime = LocalDateTime.now(ZoneId.of("Asia/Seoul"));
105+
String specMeal = mealService.getSpecKorMeal(dateCustom, bld, currentDateTime);
127106
Map<String, Object> responseBody = mealService.responseMeal(specMeal);
128107

129-
// if need to stratify.
130-
// ObjectMapper objectMapper = new ObjectMapper();
131-
// String result = objectMapper.writeValueAsString(responseBody);
132-
133-
return responseBody;
134-
}
135-
136-
@PostMapping("/speckor")
137-
public Map<String, Object> readSpecKorMeal(@RequestBody Map<String, Map<String, Map<String, Object>>> requestBody) throws JsonProcessingException {
138-
// input : 날짜요일내일 + 아점저 + 1/2학
139-
// output : 한국어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.)
140-
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");
145-
146-
log.info(dateCustom + " " + bld);
147-
log.info(dateCustom + " " + bld);
148-
149-
String specMeal = mealService.getSpecKorMeal(dateCustom, bld);
150-
Map<String, Object> responseBody = mealService.responseMeal(specMeal);
151-
152-
// if need to stratify.
153-
// ObjectMapper objectMapper = new ObjectMapper();
154-
// String result = objectMapper.writeValueAsString(responseBody);
155-
156108
return responseBody;
157109
}
158110

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

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");
116+
ObjectMapper objectMapper = new ObjectMapper();
117+
Map<String, Object> action = objectMapper.convertValue(requestBody.get("action"), Map.class);
118+
Map<String, Object> params = objectMapper.convertValue(action.get("params"), Map.class);
168119

169-
log.info(dateCustom + " " + bld);
120+
//log.info(params2.get("dateCustom").toString() + " " + params2.get("bld").toString());
121+
String dateCustom = params.get("dateCustom").toString();
122+
String bld = params.get("bld").toString();
170123

171124
String specMeal = mealService.getSpecEngMeal(dateCustom, bld);
172125
Map<String, Object> responseBody = mealService.responseMeal(specMeal);
173126

174-
// if need to stratify.
175-
// ObjectMapper objectMapper = new ObjectMapper();
176-
// String result = objectMapper.writeValueAsString(responseBody);
177-
178127
return responseBody;
179128
}
180129

src/main/java/com/example/helper/entity/Meal.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.example.helper.entity;
22

3+
import com.example.helper.constant.Types;
34
import jakarta.persistence.Column;
45
import jakarta.persistence.Entity;
56
import jakarta.persistence.GeneratedValue;
@@ -45,9 +46,15 @@ public String generateMenu() {
4546
menu += this.date + " " + this.kind + "\n\n";
4647
menu += this.bldg + "\n\n";
4748
menu += this.menu;
48-
if(kindType == 1) {
49-
menu += "\n\\코너\\\n";
50-
menu += this.special;
49+
if(kindType == Types.KIND_LUNCH.getType()) {
50+
if(langType == Types.LANG_KOR.getType()) {
51+
menu += "\n\\코너\\\n";
52+
menu += this.special;
53+
}
54+
else if(langType == Types.LANG_ENG.getType()) {
55+
menu += "\n\\Coner\\\n";
56+
menu += this.special;
57+
}
5158
}
5259
return menu;
5360
}

0 commit comments

Comments
 (0)