Skip to content

Commit

Permalink
Merge pull request #103 from LikeKNU/develop
Browse files Browse the repository at this point in the history
Cafeteria 스키마 변경
  • Loading branch information
jcw1031 authored Mar 28, 2024
2 parents bea01d3 + 75e62ec commit 7d1e940
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,9 @@

import ac.knu.likeknu.domain.Announcement;
import lombok.Builder;
import lombok.Getter;

@Getter
public class MainAnnouncementsResponse {

private String announcementId;
private String announcementTitle;
private String announcementUrl;

@Builder
public MainAnnouncementsResponse(String announcementId, String announcementTitle, String announcementUrl) {
this.announcementId = announcementId;
this.announcementTitle = announcementTitle;
this.announcementUrl = announcementUrl;
}
@Builder
public record MainAnnouncementsResponse(String announcementId, String announcementTitle, String announcementUrl) {

public static MainAnnouncementsResponse of(Announcement announcement) {
return MainAnnouncementsResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,12 @@
import ac.knu.likeknu.domain.Cafeteria;
import ac.knu.likeknu.domain.value.MealType;
import lombok.Builder;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

@Getter
public class MainMenuResponse {

private final String cafeteriaId;
private final String cafeteriaName;
private final String mealType;
private final List<MenuListDto> menus;

@Builder
public MainMenuResponse(String cafeteriaId, String cafeteriaName, String mealType, List<MenuListDto> menus) {
this.cafeteriaId = cafeteriaId;
this.cafeteriaName = cafeteriaName;
this.mealType = mealType;
this.menus = menus;
}
@Builder
public record MainMenuResponse(String cafeteriaId, String cafeteriaName, String mealType, List<MenuListDto> menus) {

public static MainMenuResponse of(Cafeteria cafeteria, String menu) {
List<MenuListDto> menuList = new ArrayList<>();
Expand All @@ -36,7 +22,7 @@ public static MainMenuResponse of(Cafeteria cafeteria, String menu) {

return MainMenuResponse.builder()
.cafeteriaId(cafeteria.getId())
.cafeteriaName(cafeteria.getCafeteriaName().getCafeteriaName())
.cafeteriaName(cafeteria.getCafeteriaName())
.mealType(MealType.now().getMealTypeKr())
.menus(menuList)
.build();
Expand All @@ -45,10 +31,9 @@ public static MainMenuResponse of(Cafeteria cafeteria, String menu) {
public static MainMenuResponse empty(Cafeteria cafeteria) {
return MainMenuResponse.builder()
.cafeteriaId(cafeteria.getId())
.cafeteriaName(cafeteria.getCafeteriaName().getCafeteriaName())
.cafeteriaName(cafeteria.getCafeteriaName())
.mealType(MealType.now().getMealTypeKr())
.menus(new ArrayList<>())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,13 @@

import ac.knu.likeknu.domain.AcademicCalendar;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

@Getter
public class MainScheduleResponse {

private String scheduleId;
private String scheduleContents;
private String scheduleDate;
private boolean today;

@Builder
public MainScheduleResponse(String scheduleId, String scheduleContents, String scheduleDate, boolean today) {
this.scheduleId = scheduleId;
this.scheduleContents = scheduleContents;
this.scheduleDate = scheduleDate;
this.today = today;
}
@Builder
public record MainScheduleResponse(String scheduleId, String scheduleContents, String scheduleDate, boolean today) {

public static MainScheduleResponse of(AcademicCalendar calendar) {
LocalDate start = calendar.getStartDate();
Expand All @@ -44,7 +30,7 @@ private static boolean isBetween(LocalDate startDate, LocalDate endDate) {
private static String dateParser(LocalDate startDate, LocalDate endDate) {
String date = dateFormatter(startDate);

if(!startDate.isEqual(endDate)) {
if (!startDate.isEqual(endDate)) {
date += " ~ " + dateFormatter(endDate);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static MenuResponse of(Cafeteria cafeteria, Map<LocalDate, List<MealListD

return MenuResponse.builder()
.cafeteriaId(cafeteria.getId())
.cafeteriaName(cafeteria.getCafeteriaName().getCafeteriaName())
.cafeteriaName(cafeteria.getCafeteriaName())
.today(mealList.get(keys.get(0)))
.tomorrow(mealList.get(keys.get(1)))
.build();
Expand Down
26 changes: 3 additions & 23 deletions src/main/java/ac/knu/likeknu/domain/Cafeteria.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package ac.knu.likeknu.domain;

import ac.knu.likeknu.domain.value.CafeteriaName;
import ac.knu.likeknu.domain.value.Campus;
import ac.knu.likeknu.domain.value.MealType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDate;
Expand All @@ -24,48 +21,31 @@ public class Cafeteria {
@Id
private String id;

@Enumerated(EnumType.STRING)
private CafeteriaName cafeteriaName;
private String cafeteriaName;

@Column
private String weekdayBreakfast;

@Column
private String weekdayLunch;

@Column
private String weekdayDinner;

@Column
private String weekendBreakfast;

@Column
private String weekendLunch;

@Column
private String weekendDinner;

@Enumerated(EnumType.STRING)
private Campus campus;

private Integer sequence;

@OneToMany(mappedBy = "cafeteria")
private List<Menu> menus = new ArrayList<>();

protected Cafeteria() {
}

@Builder
public Cafeteria(CafeteriaName cafeteriaName, String weekdayBreakfast, String weekdayLunch, String weekdayDinner, String weekendBreakfast, String weekendLunch, String weekendDinner, Campus campus) {
this.cafeteriaName = cafeteriaName;
this.weekdayBreakfast = weekdayBreakfast;
this.weekdayLunch = weekdayLunch;
this.weekdayDinner = weekdayDinner;
this.weekendBreakfast = weekendBreakfast;
this.weekendLunch = weekendLunch;
this.weekendDinner = weekendDinner;
this.campus = campus;
}

public String getTime(MealType mealType, LocalDate date) {
if (mealType == null)
return null;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/ac/knu/likeknu/domain/Menu.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package ac.knu.likeknu.domain;

import ac.knu.likeknu.domain.value.CafeteriaName;
import ac.knu.likeknu.domain.value.Campus;
import ac.knu.likeknu.domain.value.MealType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
24 changes: 0 additions & 24 deletions src/main/java/ac/knu/likeknu/domain/value/CafeteriaName.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/ac/knu/likeknu/service/MainService.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public List<MainAnnouncementsResponse> getAnnouncementsResponse(Campus campus) {
public List<MainMenuResponse> getMenuResponse(Campus campus) {
List<Cafeteria> cafeterias = cafeteriaRepository.findByCampus(campus);
return cafeterias.stream()
.sorted(Comparator.comparing(cafeteria -> cafeteria.getCafeteriaName().getSequence()))
.sorted(Comparator.comparing(Cafeteria::getSequence))
.map(this::findAndGenerateMenuResponse)
.collect(Collectors.toList());
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ac/knu/likeknu/service/MenuService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public List<MenuResponse> getMenuResponsesByCampus(Campus campus, LocalDate date
List<Cafeteria> cafeterias = cafeteriaRepository.findByCampus(campus);

return cafeterias.stream()
.sorted(Comparator.comparing(cafeteria -> cafeteria.getCafeteriaName().getSequence()))
.sorted(Comparator.comparing(Cafeteria::getSequence))
.map(cafeteria -> MenuResponse.of(cafeteria, createMapContainingMealListDto(cafeteria, date)))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
ALTER TABLE cafeteria
MODIFY COLUMN cafeteria_name VARCHAR(20);

ALTER TABLE cafeteria
ADD COLUMN `sequence` INT;

UPDATE cafeteria
SET cafeteria_name = '직원식당'
WHERE cafeteria_name = 'EMPLOYEE_CAFETERIA';

UPDATE cafeteria
SET cafeteria_name = '학생식당'
WHERE cafeteria_name = 'STUDENT_CAFETERIA';

UPDATE cafeteria
SET cafeteria_name = '생활관식당'
WHERE cafeteria_name = 'DORMITORY';

UPDATE cafeteria
SET cafeteria_name = '늘솜'
WHERE cafeteria_name = 'NEULSOM';

UPDATE cafeteria
SET cafeteria_name = '소담'
WHERE cafeteria_name = 'SODAM';

UPDATE cafeteria
SET cafeteria_name = '은행사/비전'
WHERE cafeteria_name = 'EUNHAENGSA_VISION';

UPDATE cafeteria
SET cafeteria_name = '드림'
WHERE cafeteria_name = 'DREAM';

ALTER TABLE cafeteria
MODIFY COLUMN cafeteria_name VARCHAR(8);
28 changes: 14 additions & 14 deletions src/test/java/ac/knu/likeknu/controller/MainControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ void getAnnouncements() throws Exception {
.param("campus", Campus.CHEONAN.name())
).andExpectAll(
status().isOk(),
jsonPath("$.data.body.[0].announcementId").value(announcementsResponse1.getAnnouncementId()),
jsonPath("$.data.body.[1].announcementTitle").value(announcementsResponse2.getAnnouncementTitle()),
jsonPath("$.data.body.[2].announcementUrl").value(announcementsResponse3.getAnnouncementUrl())
jsonPath("$.data.body.[0].announcementId").value(announcementsResponse1.announcementId()),
jsonPath("$.data.body.[1].announcementTitle").value(announcementsResponse2.announcementTitle()),
jsonPath("$.data.body.[2].announcementUrl").value(announcementsResponse3.announcementUrl())
).andDo(print());

}
Expand Down Expand Up @@ -177,18 +177,18 @@ void getMenuResponsesAndSuccess() throws Exception {
//then
resultActions1.andExpectAll(
status().isOk(),
jsonPath("$.data.body.[0].cafeteriaId").value(menuResponse1.getCafeteriaId()),
jsonPath("$.data.body.[1].cafeteriaName").value(menuResponse2.getCafeteriaName()),
jsonPath("$.data.body.[0].menus.[0].menuId").value(menuResponse1.getMenus().get(0).getMenuId()),
jsonPath("$.data.body.[2].menus.[1].menuName").value(menuResponse4.getMenus().get(1).getMenuName())
jsonPath("$.data.body.[0].cafeteriaId").value(menuResponse1.cafeteriaId()),
jsonPath("$.data.body.[1].cafeteriaName").value(menuResponse2.cafeteriaName()),
jsonPath("$.data.body.[0].menus.[0].menuId").value(menuResponse1.menus().get(0).getMenuId()),
jsonPath("$.data.body.[2].menus.[1].menuName").value(menuResponse4.menus().get(1).getMenuName())
).andDo(print());

resultActions2.andExpectAll(
status().isOk(),
jsonPath("$.data.body.[0].cafeteriaId").value(menuResponse1.getCafeteriaId()),
jsonPath("$.data.body.[1].cafeteriaName").value(menuResponse3.getCafeteriaName()),
jsonPath("$.data.body.[0].menus.[0].menuId").value(menuResponse1.getMenus().get(0).getMenuId()),
jsonPath("$.data.body.[2].menus.[1].menuName").value(menuResponse4.getMenus().get(1).getMenuName())
jsonPath("$.data.body.[0].cafeteriaId").value(menuResponse1.cafeteriaId()),
jsonPath("$.data.body.[1].cafeteriaName").value(menuResponse3.cafeteriaName()),
jsonPath("$.data.body.[0].menus.[0].menuId").value(menuResponse1.menus().get(0).getMenuId()),
jsonPath("$.data.body.[2].menus.[1].menuName").value(menuResponse4.menus().get(1).getMenuName())
).andDo(print());

}
Expand All @@ -211,9 +211,9 @@ void getAcademicCalendar() throws Exception {
//then
resultActions.andExpectAll(
status().isOk(),
jsonPath("$.data.body.[0].scheduleId").value(calendar1.getScheduleId()),
jsonPath("$.data.body.[1].scheduleContents").value(calendar2.getScheduleContents()),
jsonPath("$.data.body.[2].scheduleDate").value(calendar3.getScheduleDate())
jsonPath("$.data.body.[0].scheduleId").value(calendar1.scheduleId()),
jsonPath("$.data.body.[1].scheduleContents").value(calendar2.scheduleContents()),
jsonPath("$.data.body.[2].scheduleDate").value(calendar3.scheduleDate())
).andDo(print());

}
Expand Down

0 comments on commit 7d1e940

Please sign in to comment.