Skip to content

Commit

Permalink
added restaurantInfo api v2
Browse files Browse the repository at this point in the history
  • Loading branch information
dh28be committed May 31, 2024
1 parent bb63916 commit fbf6c12
Show file tree
Hide file tree
Showing 28 changed files with 899 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ build/
out/
logs/

#src/main/resources/application.yml
.env
31 changes: 26 additions & 5 deletions src/main/java/pro/hexa/unist/meal/controller/HomeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
import org.springframework.web.bind.annotation.*;
import pro.hexa.unist.meal.domain.mealTable.domain.MealTable;
import pro.hexa.unist.meal.service.MealTableService;
import pro.hexa.unist.meal.service.RestaurantInfoService;
import pro.hexa.unist.meal.service.RestaurantInfoServiceV1;
import pro.hexa.unist.meal.service.RestaurantInfoServiceV2WeekDay;
import pro.hexa.unist.meal.service.RestaurantInfoServiceV2WeekEnd;
import pro.hexa.unist.meal.service.dto.MealTableDto;
import pro.hexa.unist.meal.service.dto.RestaurantInfoDto;
import pro.hexa.unist.meal.service.dto.RestaurantInfoDtoV1;
import pro.hexa.unist.meal.service.dto.RestaurantInfoDtoV2;

@RestController
@RequestMapping("")
Expand All @@ -20,7 +23,9 @@
public class HomeController {

private final MealTableService mealTableService;
private final RestaurantInfoService restaurantInfoService;
private final RestaurantInfoServiceV1 restaurantInfoServiceV1;
private final RestaurantInfoServiceV2WeekDay restaurantInfoServiceV2WeekDay;
private final RestaurantInfoServiceV2WeekEnd restaurantInfoServiceV2WeekEnd;

@GetMapping("/health")
public ResponseEntity<Boolean> healthCheck() {
Expand All @@ -44,9 +49,25 @@ public ResponseEntity<List<MealTableDto>> menuListResponseEntity(@RequestParam(r
}

@GetMapping("/mainpage/restaurantInfo")
public ResponseEntity<RestaurantInfoDto> restaurantInfoResponseEntity() {
public ResponseEntity<RestaurantInfoDtoV1> restaurantInfoV1ResponseEntity() {

RestaurantInfoDto restaurantInfo = restaurantInfoService.findAll();
RestaurantInfoDtoV1 restaurantInfo = restaurantInfoServiceV1.findAll();

return new ResponseEntity<>(restaurantInfo, HttpStatus.OK);
}

@GetMapping("/mainpage/restaurantInfo/weekDay")
public ResponseEntity<RestaurantInfoDtoV2> restaurantInfoV1WeekDayResponseEntity() {

RestaurantInfoDtoV2 restaurantInfo = restaurantInfoServiceV2WeekDay.findAllWeekDay();

return new ResponseEntity<>(restaurantInfo, HttpStatus.OK);
}

@GetMapping("/mainpage/restaurantInfo/weekEnd")
public ResponseEntity<RestaurantInfoDtoV2> restaurantInfoV1WeekEndResponseEntity() {

RestaurantInfoDtoV2 restaurantInfo = restaurantInfoServiceV2WeekEnd.findAllWeekEnd();

return new ResponseEntity<>(restaurantInfo, HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pro.hexa.unist.meal.domain.restaurantInfo.domain.RestaurantInfo;
import pro.hexa.unist.meal.domain.restaurantInfo.repository.RestaurantInfoRepository;
import pro.hexa.unist.meal.domain.restaurantInfo.v1.domain.RestaurantInfoV1;
import pro.hexa.unist.meal.domain.restaurantInfo.v1.repository.RestaurantInfoRepositoryV1;
import pro.hexa.unist.meal.service.MainService;

import javax.transaction.Transactional;
Expand All @@ -19,10 +19,10 @@
@RequestMapping("/restaurantInfo")
@RequiredArgsConstructor
@Transactional
public class RestaurantInfoController {
public class RestaurantInfoControllerV1 {

private static final Logger log = LoggerFactory.getLogger(RestaurantInfoController.class);
private final RestaurantInfoRepository repository;
private static final Logger log = LoggerFactory.getLogger(RestaurantInfoControllerV1.class);
private final RestaurantInfoRepositoryV1 repository;
private final MainService mainService;

@PostMapping("/dormitoryKorean")
Expand Down Expand Up @@ -113,27 +113,27 @@ private void uploadRestaurantInfo(String restaurantName, String breakfastStartTi

mainService.verifySecretKey(theKey);

RestaurantInfo breakfast;
RestaurantInfo lunch;
RestaurantInfo dinner;
RestaurantInfoV1 breakfast;
RestaurantInfoV1 lunch;
RestaurantInfoV1 dinner;

if (breakfastIsOpened != null) {
String[] parsedBreakfastStartTime = breakfastStartTime.split(":");
String[] parsedBreakfastEndTime = breakfastEndTime.split(":");
breakfast = new RestaurantInfo(restaurantName, breakfastPrice, true, Integer.parseInt(parsedBreakfastStartTime[0]), Integer.parseInt(parsedBreakfastStartTime[1]), Integer.parseInt(parsedBreakfastEndTime[0]), Integer.parseInt(parsedBreakfastEndTime[1]), "breakfast");
} else breakfast = new RestaurantInfo(restaurantName, false, "breakfast");
breakfast = new RestaurantInfoV1(restaurantName, breakfastPrice, true, Integer.parseInt(parsedBreakfastStartTime[0]), Integer.parseInt(parsedBreakfastStartTime[1]), Integer.parseInt(parsedBreakfastEndTime[0]), Integer.parseInt(parsedBreakfastEndTime[1]), "breakfast");
} else breakfast = new RestaurantInfoV1(restaurantName, false, "breakfast");

if (lunchIsOpened != null) {
String[] parsedLunchStartTime = lunchStartTime.split(":");
String[] parsedLunchEndTime = lunchEndTime.split(":");
lunch = new RestaurantInfo(restaurantName, lunchPrice, lunchIsOpened, Integer.parseInt(parsedLunchStartTime[0]), Integer.parseInt(parsedLunchStartTime[1]), Integer.parseInt(parsedLunchEndTime[0]), Integer.parseInt(parsedLunchEndTime[1]), "lunch");
} else lunch = new RestaurantInfo(restaurantName, false, "lunch");
lunch = new RestaurantInfoV1(restaurantName, lunchPrice, lunchIsOpened, Integer.parseInt(parsedLunchStartTime[0]), Integer.parseInt(parsedLunchStartTime[1]), Integer.parseInt(parsedLunchEndTime[0]), Integer.parseInt(parsedLunchEndTime[1]), "lunch");
} else lunch = new RestaurantInfoV1(restaurantName, false, "lunch");

if (dinnerIsOpened != null) {
String[] parsedDinnerStartTime = dinnerStartTime.split(":");
String[] parsedDinnerEndTime = dinnerEndTime.split(":");
dinner = new RestaurantInfo(restaurantName, dinnerPrice, dinnerIsOpened, Integer.parseInt(parsedDinnerStartTime[0]), Integer.parseInt(parsedDinnerStartTime[1]), Integer.parseInt(parsedDinnerEndTime[0]), Integer.parseInt(parsedDinnerEndTime[1]), "dinner");
} else dinner = new RestaurantInfo(restaurantName, false, "dinner");
dinner = new RestaurantInfoV1(restaurantName, dinnerPrice, dinnerIsOpened, Integer.parseInt(parsedDinnerStartTime[0]), Integer.parseInt(parsedDinnerStartTime[1]), Integer.parseInt(parsedDinnerEndTime[0]), Integer.parseInt(parsedDinnerEndTime[1]), "dinner");
} else dinner = new RestaurantInfoV1(restaurantName, false, "dinner");

repository.deleteByRestaurantName(restaurantName);
repository.save(breakfast);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
package pro.hexa.unist.meal.controller;

import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pro.hexa.unist.meal.domain.restaurantInfo.v2.domain.RestaurantInfoV2;
import pro.hexa.unist.meal.domain.restaurantInfo.v2.model.DayType;
import pro.hexa.unist.meal.domain.restaurantInfo.v2.repository.RestaurantInfoRepositoryV2;
import pro.hexa.unist.meal.service.MainService;

import javax.transaction.Transactional;
import java.net.URI;
import java.net.URISyntaxException;

@RestController
@RequestMapping("/restaurantInfo/weekDay")
@RequiredArgsConstructor
@Transactional
public class RestaurantInfoControllerV2WeekDay {

private static final Logger log = LoggerFactory.getLogger(RestaurantInfoControllerV2WeekDay.class);
private final RestaurantInfoRepositoryV2 repository;
private final MainService mainService;

@PostMapping("/dormitoryKorean")
public ResponseEntity<Void> saveDormitoryKoreanRestaurantInfo(
String breakfastStartTime,
String breakfastEndTime,
Integer breakfastPrice,
Boolean breakfastIsOpened,
String lunchStartTime,
String lunchEndTime,
Integer lunchPrice,
Boolean lunchIsOpened,
String dinnerStartTime,
String dinnerEndTime,
Integer dinnerPrice,
Boolean dinnerIsOpened,
String theKey
) throws URISyntaxException {

uploadRestaurantInfo("기숙사 식당(한식)", breakfastStartTime, breakfastEndTime, breakfastPrice, breakfastIsOpened, lunchStartTime, lunchEndTime, lunchPrice, lunchIsOpened, dinnerStartTime, dinnerEndTime, dinnerPrice, dinnerIsOpened, theKey);
return ResponseEntity.created(new URI("/importSuccess")).build();
}

@PostMapping("/dormitoryHalal")
public ResponseEntity<Void> saveDormitoryHalalRestaurantInfo(
String breakfastStartTime,
String breakfastEndTime,
Integer breakfastPrice,
Boolean breakfastIsOpened,
String lunchStartTime,
String lunchEndTime,
Integer lunchPrice,
Boolean lunchIsOpened,
String dinnerStartTime,
String dinnerEndTime,
Integer dinnerPrice,
Boolean dinnerIsOpened,
String theKey
) throws URISyntaxException {

uploadRestaurantInfo("기숙사 식당(할랄)", breakfastStartTime, breakfastEndTime, breakfastPrice, breakfastIsOpened, lunchStartTime, lunchEndTime, lunchPrice, lunchIsOpened, dinnerStartTime, dinnerEndTime, dinnerPrice, dinnerIsOpened, theKey);
return ResponseEntity.created(new URI("/importSuccess")).build();
}

@PostMapping("/student")
public ResponseEntity<Void> saveStudentRestaurantInfo(
String breakfastStartTime,
String breakfastEndTime,
Integer breakfastPrice,
Boolean breakfastIsOpened,
String lunchStartTime,
String lunchEndTime,
Integer lunchPrice,
Boolean lunchIsOpened,
String dinnerStartTime,
String dinnerEndTime,
Integer dinnerPrice,
Boolean dinnerIsOpened,
String theKey
) throws URISyntaxException {

uploadRestaurantInfo("학생 식당", breakfastStartTime, breakfastEndTime, breakfastPrice, breakfastIsOpened, lunchStartTime, lunchEndTime, lunchPrice, lunchIsOpened, dinnerStartTime, dinnerEndTime, dinnerPrice, dinnerIsOpened, theKey);
return ResponseEntity.created(new URI("/importSuccess")).build();
}

@PostMapping("/professor")
public ResponseEntity<Void> saveProfessorRestaurantInfo(
String breakfastStartTime,
String breakfastEndTime,
Integer breakfastPrice,
Boolean breakfastIsOpened,
String lunchStartTime,
String lunchEndTime,
Integer lunchPrice,
Boolean lunchIsOpened,
String dinnerStartTime,
String dinnerEndTime,
Integer dinnerPrice,
Boolean dinnerIsOpened,
String theKey
) throws URISyntaxException {

uploadRestaurantInfo("교직원 식당", breakfastStartTime, breakfastEndTime, breakfastPrice, breakfastIsOpened, lunchStartTime, lunchEndTime, lunchPrice, lunchIsOpened, dinnerStartTime, dinnerEndTime, dinnerPrice, dinnerIsOpened, theKey);
return ResponseEntity.created(new URI("/importSuccess")).build();
}

private void uploadRestaurantInfo(String restaurantName, String breakfastStartTime, String breakfastEndTime, Integer breakfastPrice, Boolean breakfastIsOpened, String lunchStartTime, String lunchEndTime, Integer lunchPrice, Boolean lunchIsOpened, String dinnerStartTime, String dinnerEndTime, Integer dinnerPrice, Boolean dinnerIsOpened, String theKey) {

mainService.verifySecretKey(theKey);

RestaurantInfoV2 breakfast;
RestaurantInfoV2 lunch;
RestaurantInfoV2 dinner;

if (breakfastIsOpened != null) {
String[] parsedBreakfastStartTime = breakfastStartTime.split(":");
String[] parsedBreakfastEndTime = breakfastEndTime.split(":");
breakfast = new RestaurantInfoV2(restaurantName, breakfastPrice, true, Integer.parseInt(parsedBreakfastStartTime[0]), Integer.parseInt(parsedBreakfastStartTime[1]), Integer.parseInt(parsedBreakfastEndTime[0]), Integer.parseInt(parsedBreakfastEndTime[1]), "breakfast", DayType.WEEKDAY);
} else breakfast = new RestaurantInfoV2(restaurantName, false, "breakfast", DayType.WEEKDAY);

if (lunchIsOpened != null) {
String[] parsedLunchStartTime = lunchStartTime.split(":");
String[] parsedLunchEndTime = lunchEndTime.split(":");
lunch = new RestaurantInfoV2(restaurantName, lunchPrice, lunchIsOpened, Integer.parseInt(parsedLunchStartTime[0]), Integer.parseInt(parsedLunchStartTime[1]), Integer.parseInt(parsedLunchEndTime[0]), Integer.parseInt(parsedLunchEndTime[1]), "lunch", DayType.WEEKDAY);
} else lunch = new RestaurantInfoV2(restaurantName, false, "lunch", DayType.WEEKDAY);

if (dinnerIsOpened != null) {
String[] parsedDinnerStartTime = dinnerStartTime.split(":");
String[] parsedDinnerEndTime = dinnerEndTime.split(":");
dinner = new RestaurantInfoV2(restaurantName, dinnerPrice, dinnerIsOpened, Integer.parseInt(parsedDinnerStartTime[0]), Integer.parseInt(parsedDinnerStartTime[1]), Integer.parseInt(parsedDinnerEndTime[0]), Integer.parseInt(parsedDinnerEndTime[1]), "dinner", DayType.WEEKDAY);
} else dinner = new RestaurantInfoV2(restaurantName, false, "dinner", DayType.WEEKDAY);

repository.deleteByRestaurantNameAndDayType(restaurantName, DayType.WEEKDAY);
repository.save(breakfast);
repository.save(lunch);
repository.save(dinner);

log.info("{} restaurant info uploaded", restaurantName);
}
}
Loading

0 comments on commit fbf6c12

Please sign in to comment.