Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ dependencies {

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.junit.platform:junit-platform-launcher:1.5.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.5.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.1'

}

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/example/helper/constant/Messages.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.helper.constant;

public enum Messages {
EXIST_MEAL_ERROR("이미 존재하는 식단입니다."),
NO_EXIST_MEAL_ERROR("조건에 맞는 식단이 존재하지 않습니다."),
NO_MEAL_KOR("식단 준비중입니다."),
NO_MEAL_ENG("The meal is being prepared."),
INVALID_DATE("유효하지 않은 날짜입니다."),
DUMMY_MEAL_KOR("2023-01-27 조식\n\n제2학생회관1층\n\n흰밥*김가루양념밥\n"),
DUMMY_MEAL_ENG("2023-01-27 Breakfast\n\nStudent Union Bldg.2 1st floor\n\nWhite rice*Seasoned rice with seaweed\n");
private String message;
Messages(String message) {
this.message = message;
}
public String getMessages() {
return message;
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/example/helper/constant/SpecMealInputsEng.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.example.helper.constant;

import jakarta.persistence.criteria.CriteriaBuilder;

public enum SpecMealInputsEng {
TODAY("today"),
TOMORROW("tomorrow"),
MON("Mon", Types.DATE_MON.getType()),
TUE("Tue", Types.DATE_TUE.getType()),
WED("Wed", Types.DATE_WED.getType()),
THR("Thr", Types.DATE_THR.getType()),
FRI("Fri", Types.DATE_FRI.getType()),
SAT("Sat", Types.DATE_SAT.getType()),
SUN("Sun", Types.DATE_SUN.getType()),
DAY_1("st"),
DAY_2("nd"),
DAY_3("rd"),
DAY_OTHER("th"),
BREAKFAST("breakfast", Types.KIND_BREAKFAST.getType()),
LUNCH("lunch", Types.KIND_LUNCH.getType()),
DINNER("dinner", Types.KIND_DINNER.getType());
private String input;
private Integer inputValue;
SpecMealInputsEng (String input) {
this.input = input;
}

SpecMealInputsEng (String input, Integer inputValue) {
this.input = input;
this.inputValue = inputValue;
}
public String getInputs() {
return input;
}
public Integer getInputValue() { return inputValue; }
}
39 changes: 39 additions & 0 deletions src/main/java/com/example/helper/constant/SpecMealInputsKor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.example.helper.constant;


public enum SpecMealInputsKor {
TODAY("오늘"),
TOMORROW("내일"),
MON("월", Types.DATE_MON.getType()),
TUE("화", Types.DATE_TUE.getType()),
WED("수", Types.DATE_WED.getType()),
THR("목", Types.DATE_THR.getType()),
FRI("금", Types.DATE_FRI.getType()),
SAT("토", Types.DATE_SAT.getType()),
SUM("일", Types.DATE_SUN.getType()),
DAY("일"),
BREAKFAST("조식", Types.KIND_BREAKFAST.getType()),
LUNCH("중식", Types.KIND_LUNCH.getType()),
DINNER("석식", Types.KIND_DINNER.getType());
private String input;
private Integer inputValue;
SpecMealInputsKor(String input) {
this.input = input;
}
SpecMealInputsKor(String input, Integer inputValue) {
this.input = input;
this.inputValue = inputValue;
}
public String getInputs() {
return input;
}
public Integer getInputValue() { return inputValue; }

public static Integer getTypeByString(String str){
for(SpecMealInputsKor each : values())
if (each.getInputs().equals(str)) {
return each.getInputValue();
}
return -1;
}
}
9 changes: 8 additions & 1 deletion src/main/java/com/example/helper/constant/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ public enum Types {
KIND_BREAKFAST(0),
KIND_LUNCH(1),
KIND_DINNER(2),
KIND_LUNCH_CORNER(3);
KIND_LUNCH_CORNER(3),
DATE_MON(1),
DATE_TUE(2),
DATE_WED(3),
DATE_THR(4),
DATE_FRI(5),
DATE_SAT(6),
DATE_SUN(7);

private Integer type;

Expand Down
113 changes: 31 additions & 82 deletions src/main/java/com/example/helper/controller/MealController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.example.helper.service.MealService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Map.Entry;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
Expand Down Expand Up @@ -50,9 +52,13 @@ public String createMeal(@RequestBody Mealdto mealDto) {
BeanUtils.copyProperties(mealDto, meal);

// DB Save
Long saved = mealService.mealCreate(meal);

return "saved";
try {
Long saved = mealService.mealCreate(meal);
return "saved";
} catch (IllegalStateException e) {
throw new ResponseStatusException(
HttpStatus.NOT_ACCEPTABLE, e.getMessage());
}
}

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

String nowMeal = mealService.getNowKorMeal();
Map<String, Object> responseBody = mealService.responseMeal(nowMeal);
// if need to stratify.
// ObjectMapper objectMapper = new ObjectMapper();
// String result = objectMapper.writeValueAsString(responseBody);

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

// if need to stratify.
// ObjectMapper objectMapper = new ObjectMapper();
// String result = objectMapper.writeValueAsString(responseBody);

return responseBody;
}

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

Map<String, Object> action = new HashMap<>();
action.put("action", requestBody.get("action"));

Map<String, Object> params = new HashMap<>();
params.put("params", action.get("action"));

Map<String, Object> paramssss = new HashMap<>();
paramssss.put("params", params.get("params"));

String dateCustom = (String) paramssss.get("dateCustom");
String bld = (String) paramssss.get("bld");

log.info("req body : " + requestBody.toString());
log.info("action body : " + action.toString());
log.info("params body : " + params.toString());
log.info("paramssss body : " + paramssss.toString());

for (Entry<String, Object> entrySet : requestBody.entrySet()) {
log.info(entrySet.getKey() + " : " + entrySet.getValue());
}

log.info("###########RESULT############");
log.info(dateCustom + " " + bld);
log.info(dateCustom + " " + bld);
// how to print the request body
//for (Entry<String, Object> entrySet : requestBody.entrySet()) {
// log.info(entrySet.getKey() + " : " + entrySet.getValue());
//}

ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> action2 = objectMapper.convertValue(requestBody.get("action"), Map.class);
Map<String, Object> params2 = objectMapper.convertValue(action2.get("params"), Map.class);
log.info(params2.get("dateCustom").toString() + " " + params2.get("bld").toString());
Map<String, Object> action = objectMapper.convertValue(requestBody.get("action"), Map.class);
Map<String, Object> params = objectMapper.convertValue(action.get("params"), Map.class);

//Map<String, String> params2 = new HashMap<>();
//params2.put()
//log.info(params2.get("dateCustom") + " " + params2.get("bld"));
//log.info(params2.get("dateCustom").toString() + " " + params2.get("bld").toString());
String dateCustom = params.get("dateCustom").toString();
String bld = params.get("bld").toString();

String specMeal = mealService.getSpecKorMeal(dateCustom, bld);
LocalDateTime currentDateTime = LocalDateTime.now(ZoneId.of("Asia/Seoul"));
String specMeal = mealService.getSpecKorMeal(dateCustom, bld, currentDateTime);
Map<String, Object> responseBody = mealService.responseMeal(specMeal);

// if need to stratify.
// ObjectMapper objectMapper = new ObjectMapper();
// String result = objectMapper.writeValueAsString(responseBody);

return responseBody;
}

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

Map<String, Map<String, Object>> action = requestBody.get("action");
Map<String, Object> params = action.get("params");
String dateCustom = (String) params.get("dateCustom");
String bld = (String) params.get("bld");

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

String specMeal = mealService.getSpecKorMeal(dateCustom, bld);
Map<String, Object> responseBody = mealService.responseMeal(specMeal);

// if need to stratify.
// ObjectMapper objectMapper = new ObjectMapper();
// String result = objectMapper.writeValueAsString(responseBody);

return responseBody;
}

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

Map<String, Map<String, Object>> action = requestBody.get("action");
Map<String, Object> params = action.get("params");
String dateCustom = (String) params.get("dateCustom");
String bld = (String) params.get("bld");
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Object> action = objectMapper.convertValue(requestBody.get("action"), Map.class);
Map<String, Object> params = objectMapper.convertValue(action.get("params"), Map.class);

log.info(dateCustom + " " + bld);
//log.info(params2.get("dateCustom").toString() + " " + params2.get("bld").toString());
String dateCustom = params.get("dateCustom").toString();
String bld = params.get("bld").toString();

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

// if need to stratify.
// ObjectMapper objectMapper = new ObjectMapper();
// String result = objectMapper.writeValueAsString(responseBody);

return responseBody;
}

Expand Down
13 changes: 10 additions & 3 deletions src/main/java/com/example/helper/entity/Meal.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.helper.entity;

import com.example.helper.constant.Types;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand Down Expand Up @@ -45,9 +46,15 @@ public String generateMenu() {
menu += this.date + " " + this.kind + "\n\n";
menu += this.bldg + "\n\n";
menu += this.menu;
if(kindType == 1) {
menu += "\n\\코너\\\n";
menu += this.special;
if(kindType == Types.KIND_LUNCH.getType()) {
if(langType == Types.LANG_KOR.getType()) {
menu += "\n\\코너\\\n";
menu += this.special;
}
else if(langType == Types.LANG_ENG.getType()) {
menu += "\n\\Coner\\\n";
menu += this.special;
}
}
return menu;
}
Expand Down
Loading