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
226 changes: 187 additions & 39 deletions src/main/java/com/example/helper/controller/MealController.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.example.helper.controller;
import com.example.helper.dto.MealWrapper;
import com.example.helper.dto.Mealdto;
import com.example.helper.entity.Meal;
import com.example.helper.service.MealService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
Expand All @@ -25,57 +28,202 @@ public String hello() {
return "Hello HELPERs. 초기 세팅 완료.";
}

@PostMapping("/test")
public @ResponseBody void test(String testStr) {
log.info(testStr);
}
@PostMapping("/create")
public @ResponseBody String createMeal(MealWrapper mealWrapper) {
// 여기 구현해주세 222
Meal meal = mealWrapper.getMeal();
// merge test
// Meal saved = mealService.save(meal);
public @ResponseBody String createMeal(@RequestBody Mealdto mealDto) {
// input : 식단 json
// output : None

// DTO to Entity
Meal meal = new Meal();
BeanUtils.copyProperties(mealDto, meal);

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

return "saved"; // Responsebody 넣어서 보내는거 해보세요
return "saved";
}

@PostMapping("/kor")
public @ResponseBody String readKorMeal() {
// input : utc
// output : 카톡 서버맞게 한국어식단 JSON으로
// const responseBody = {
// version: "2.0",
// template: {
// outputs: [
// {
// simpleText: {
// text: rows[0].menu
// }
// }
// ]
// }
// };
// res.status(200).send(responseBody);
return "saved"; // Responsebody 넣어서 보내는거 해보세요
public @ResponseBody String readKorMeal() throws JsonProcessingException {
// input : None (먼저 서버에서 현재 시간 측정)
// output : 한국어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.)

// TODO 아래 기능 구현해 주세요.
String nowMeal = mealService.getNowKorMeal();

// Response Body Construct
// TODO 더 좋은 방식이 있으면 구현해 주세요. ex) dto 이용.
// const responseBody = {
// version: "2.0",
// template: {
// outputs: [
// {
// simpleText: {
// text: nowMeal
// }
// }
// ]
// }
// };

Map<String, Object> simpleText = new HashMap<>();
simpleText.put("text", nowMeal);

Map<String, Object> simpleTextWrapper = new HashMap<>();
simpleTextWrapper.put("simpleText", simpleText);

List<Object> outputs = new ArrayList(1);
outputs.add(simpleTextWrapper);

Map<String, Object> template = new HashMap<>();
template.put("outputs", outputs);

Map<String, Object> responseBody = new HashMap<>();
responseBody.put("version", "2.0");
responseBody.put("template", template);

ObjectMapper objectMapper = new ObjectMapper();
String result = objectMapper.writeValueAsString(responseBody);

return result;
}

@PostMapping("/eng")
public @ResponseBody String readEngMeal() {
// input : utc
// output : 카톡 서버맞게 영어식단 JSON으로
public @ResponseBody String readEngMeal() throws JsonProcessingException {
// input : None (먼저 서버에서 현재 시간 측정)
// output : 영어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.)

// TODO 아래 기능 구현해 주세요.
String nowMeal = mealService.getNowEngMeal();

// Response Body Construct
// TODO 더 좋은 방식이 있으면 구현해 주세요. ex) dto 이용.
// const responseBody = {
// version: "2.0",
// template: {
// outputs: [
// {
// simpleText: {
// text: nowMeal
// }
// }
// ]
// }
// };

Map<String, Object> simpleText = new HashMap<>();
simpleText.put("text", nowMeal);

Map<String, Object> simpleTextWrapper = new HashMap<>();
simpleTextWrapper.put("simpleText", simpleText);

List<Object> outputs = new ArrayList(1);
outputs.add(simpleTextWrapper);

Map<String, Object> template = new HashMap<>();
template.put("outputs", outputs);

return "saved"; // Responsebody 넣어서 보내는거 해보세요
Map<String, Object> responseBody = new HashMap<>();
responseBody.put("version", "2.0");
responseBody.put("template", template);

ObjectMapper objectMapper = new ObjectMapper();
String result = objectMapper.writeValueAsString(responseBody);

return result;
}

@PostMapping("/speckor")
public @ResponseBody String readSpecKorMeal() {
public @ResponseBody String readSpecKorMeal() throws JsonProcessingException {
// input : 날짜요일내일 + 아점저 + 1/2학
// output : 해당 식단 찾아 카톡 서버맞게 JSON으로
// output : 한국어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.)

// TODO 아래 기능 구현해 주세요.
String specMeal = mealService.getSpecKorMeal();

// Response Body Construct
// TODO 더 좋은 방식이 있으면 구현해 주세요. ex) dto 이용.
// const responseBody = {
// version: "2.0",
// template: {
// outputs: [
// {
// simpleText: {
// text: specMeal
// }
// }
// ]
// }
// };

Map<String, Object> simpleText = new HashMap<>();
simpleText.put("text", specMeal);

Map<String, Object> simpleTextWrapper = new HashMap<>();
simpleTextWrapper.put("simpleText", simpleText);

List<Object> outputs = new ArrayList(1);
outputs.add(simpleTextWrapper);

Map<String, Object> template = new HashMap<>();
template.put("outputs", outputs);

Map<String, Object> responseBody = new HashMap<>();
responseBody.put("version", "2.0");
responseBody.put("template", template);

return "saved"; // Responsebody 넣어서 보내는거 해보세요
ObjectMapper objectMapper = new ObjectMapper();
String result = objectMapper.writeValueAsString(responseBody);

return result;
}

@PostMapping("/speceng")
public @ResponseBody String readSpecEngMeal() {
public @ResponseBody String readSpecEngMeal() throws JsonProcessingException {
// input : 날짜요일내일 + 아점저 + 1/2학
// output : 해당 식단 찾아 카톡 서버맞게 JSON으로
// output : 영어 식단이 포함된 JSON (단, JSON은 카톡 서버가 받을 수 있는 형식이여야 함.)

// TODO 아래 기능 구현해 주세요.
String specMeal = mealService.getSpecEngMeal();

// Response Body Construct
// TODO 더 좋은 방식이 있으면 구현해 주세요. ex) dto 이용.
// const responseBody = {
// version: "2.0",
// template: {
// outputs: [
// {
// simpleText: {
// text: specMeal
// }
// }
// ]
// }
// };

Map<String, Object> simpleText = new HashMap<>();
simpleText.put("text", specMeal);

Map<String, Object> simpleTextWrapper = new HashMap<>();
simpleTextWrapper.put("simpleText", simpleText);

List<Object> outputs = new ArrayList(1);
outputs.add(simpleTextWrapper);

Map<String, Object> template = new HashMap<>();
template.put("outputs", outputs);

Map<String, Object> responseBody = new HashMap<>();
responseBody.put("version", "2.0");
responseBody.put("template", template);

ObjectMapper objectMapper = new ObjectMapper();
String result = objectMapper.writeValueAsString(responseBody);

return "saved"; // Responsebody 넣어서 보내는거 해보세요
return result;
}
}
9 changes: 0 additions & 9 deletions src/main/java/com/example/helper/dto/MealWrapper.java

This file was deleted.

28 changes: 12 additions & 16 deletions src/main/java/com/example/helper/dto/Mealdto.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
package com.example.helper.dto;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import jakarta.persistence.Column;
import lombok.*;

@ToString
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Mealdto {


public Mealdto(String title, String meal_date, String kind_of_meal, String menu) {
this.title = title;
this.meal_date = meal_date;
this.kind_of_meal = kind_of_meal;
this.menu = menu;
}

private String title;
private String meal_date;
private String kind_of_meal;
private Integer bldgType;
private Integer langType;
private Integer dateType;
private Integer kindType;
private String bldg;
private String date;
private String kind;
private String menu;

private String special;
}
20 changes: 13 additions & 7 deletions src/main/java/com/example/helper/entity/Meal.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@ public class Meal {
@Id
@GeneratedValue
private Long id;

@Column
private String title;

private Integer bldgType;
@Column
private String meal_date;

private Integer langType;
@Column
private String kind_of_meal;

private Integer dateType;
@Column
private Integer kindType;
@Column
private String bldg;
@Column
private String date;
@Column
private String kind;
@Column
private String menu;
@Column
private String special;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import com.example.helper.entity.Meal;

import java.util.Optional;

public interface MealRepository {
Meal save(Meal meal);

Long findIdByDateTitleKind(String title, String meal_date, String kind_of_meal);
Optional<Meal> findByPk(Integer bldgType, Integer langType, Integer dateType, Integer kindType, String date);

Meal findById(Long mealId);
Optional<Meal> findById(Long mealId);

Long delete(Long mealId);
}
Loading