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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class KoyeonController {

/***
* 고연전 여부 반환
* TODO: 프론트 api 변경 후 삭제 필요
*/
@GetMapping("")
@Operation(summary = "고연전 시즌 여부를 t/f로 반환", description = "고연전 시즌 여부를 t/f로 반환")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@Table(name = "tb_koyeon")
@NoArgsConstructor
public class Koyeon {
@Id
@Schema(description = "id", example = "1")
private Long id;
@Schema(description = "name", example = "고연전")
private String name;
@Schema(description = "isKoyeon", example = "true")
private Boolean isKoyeon;

public Koyeon(Long id, String name, Boolean isKoyeon) {
this.id = id;
this.name = name;
this.isKoyeon = isKoyeon;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package devkor.com.teamcback.domain.koyeon.service;

import devkor.com.teamcback.domain.schoolcalendar.entity.SchoolCalendar;
import devkor.com.teamcback.domain.schoolcalendar.repository.SchoolCalendarRepository;
import devkor.com.teamcback.domain.koyeon.dto.response.*;
import devkor.com.teamcback.domain.koyeon.entity.*;
import devkor.com.teamcback.domain.koyeon.repository.*;
Expand All @@ -24,13 +26,15 @@ public class KoyeonService {
private final MenuRepository menuRepository;
private final TagMenuRepository tagMenuRepository;
private final FreePubNicknameRepository freePubNicknameRepository;
private final SchoolCalendarRepository schoolCalendarRepository;

/**
* 고연전 여부 확인
*/
@Transactional(readOnly = true)
public Koyeon isKoyeon() {
return koyeonRepository.findById(1L).orElseThrow(() -> new GlobalException(NOT_FOUND_KOYEON));
SchoolCalendar schoolCalendar = findSchoolCalendar();
return new Koyeon(schoolCalendar.getId(), schoolCalendar.getName(), schoolCalendar.isActive());
}

/**
Expand Down Expand Up @@ -126,4 +130,8 @@ private static List<GlobalPubSearchRes> orderSequence(Map<GlobalPubSearchRes, In
private FreePub findFreePub(Long pubId) {
return freePubRepository.findById(pubId).orElseThrow(() -> new GlobalException(NOT_FOUND_PUB));
}

private SchoolCalendar findSchoolCalendar() {
return schoolCalendarRepository.findById(2L).orElseThrow(() -> new GlobalException(NOT_FOUND_SCHOOL_CALENDAR));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package devkor.com.teamcback.domain.operatingtime.scheduler;

import devkor.com.teamcback.domain.schoolcalendar.service.SchoolCalendarService;
import devkor.com.teamcback.domain.operatingtime.entity.DayOfWeek;
import devkor.com.teamcback.domain.operatingtime.service.HolidayService;
import devkor.com.teamcback.domain.operatingtime.service.OperatingService;
Expand All @@ -21,16 +22,7 @@ public class OperatingScheduler {
private final OperatingService operatingService;
private final HolidayService holidayService;
private final RedisLockUtil redisLockUtil;

private static final int SUMMER_VACATION_START_MONTH = 6;
private static final int SUMMER_VACATION_START_DAY = 22;
private static final int SUMMER_VACATION_END_MONTH = 9;
private static final int SUMMER_VACATION_END_DAY = 1;

private static final int WINTER_VACATION_START_MONTH = 12;
private static final int WINTER_VACATION_START_DAY = 21;
private static final int WINTER_VACATION_END_MONTH = 3;
private static final int WINTER_VACATION_END_DAY = 3;
private final SchoolCalendarService schoolCalendarService;

private static DayOfWeek dayOfWeek = null;
private static Boolean isHoliday = null;
Expand Down Expand Up @@ -86,7 +78,7 @@ private void setState() {
log.info("dayOfWeek: {}", dayOfWeek.toString());
isHoliday = isHoliday(now); // 공휴일 여부
log.info("isHoliday: {}", isHoliday);
isVacation = isVacation(now); // 방학 여부
isVacation = isVacation(); // 방학 여부
log.info("isVacation: {}", isVacation);
isEvenWeek = false; // 토요일 짝수 주 여부
if(dayOfWeek == DayOfWeek.SATURDAY) { // 토요일이면 몇째주 토요일인지 계산
Expand All @@ -113,25 +105,8 @@ private boolean isHoliday(LocalDate date) {
return holidayService.isHoliday(date);
}

private boolean isVacation(LocalDate date) {
int month = date.getMonthValue();
int day = date.getDayOfMonth();

// 여름방학 기간
if((month == SUMMER_VACATION_START_MONTH && day >= SUMMER_VACATION_START_DAY) ||
(month == SUMMER_VACATION_END_MONTH && day <= SUMMER_VACATION_END_DAY) ||
(month > SUMMER_VACATION_START_MONTH && month < SUMMER_VACATION_END_MONTH)) {
return true;
}

// 겨울방학 기간
if((month == WINTER_VACATION_START_MONTH && day >= WINTER_VACATION_START_DAY) ||
(month == WINTER_VACATION_END_MONTH && day <= WINTER_VACATION_END_DAY) ||
(month < WINTER_VACATION_END_MONTH)) {
return true;
}

return false;
private boolean isVacation() {
return schoolCalendarService.isVacationTf();
}

private boolean isEvenWeek(LocalDate now) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package devkor.com.teamcback.domain.schoolcalendar.controller;

import devkor.com.teamcback.domain.schoolcalendar.dto.response.UpdateSchoolCalendarRes;
import devkor.com.teamcback.domain.schoolcalendar.service.SchoolCalendarService;
import devkor.com.teamcback.global.response.CommonResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/admin/school-calendar")
public class AdminSchoolCalendarController {
private final SchoolCalendarService schoolCalendarService;

/***
* 방학 여부 수정
*/
@PutMapping("/vacation")
@Operation(summary = "방학 여부 수정(토글)", description = "방학 여부 수정")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "정상 처리 되었습니다."),
@ApiResponse(responseCode = "404", description = "Not Found",
content = @Content(schema = @Schema(implementation = CommonResponse.class))),
})
public CommonResponse<UpdateSchoolCalendarRes> updateVacationActive() {
return CommonResponse.success(schoolCalendarService.updateVacationActive());
}

/***
* 고연전 여부 수정
*/
@PutMapping("/koyeon")
@Operation(summary = "고연전 여부 수정(토글)", description = "고연전 여부 수정")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "정상 처리 되었습니다."),
@ApiResponse(responseCode = "404", description = "Not Found",
content = @Content(schema = @Schema(implementation = CommonResponse.class))),
})
public CommonResponse<UpdateSchoolCalendarRes> updateKoyeonActive() {
return CommonResponse.success(schoolCalendarService.updateKoyeonActive());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package devkor.com.teamcback.domain.schoolcalendar.controller;

import devkor.com.teamcback.domain.schoolcalendar.dto.response.GetSchoolCalendarRes;
import devkor.com.teamcback.domain.schoolcalendar.service.SchoolCalendarService;
import devkor.com.teamcback.global.response.CommonResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/school-calendar")
public class SchoolCalendarController {
private final SchoolCalendarService schoolCalendarService;

/***
* 방학 여부 반환
*/
@GetMapping("/vacation")
@Operation(summary = "방학 여부를 t/f로 반환", description = "방학 여부를 t/f로 반환")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "정상 처리 되었습니다."),
@ApiResponse(responseCode = "404", description = "Not Found",
content = @Content(schema = @Schema(implementation = CommonResponse.class))),
})
public CommonResponse<GetSchoolCalendarRes> isVacation() {
return CommonResponse.success(schoolCalendarService.isVacation());
}

/***
* 고연전 여부 반환
*/
@GetMapping("/koyeon")
@Operation(summary = "고연전 여부를 t/f로 반환", description = "고연전 여부를 t/f로 반환")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "정상 처리 되었습니다."),
@ApiResponse(responseCode = "404", description = "Not Found",
content = @Content(schema = @Schema(implementation = CommonResponse.class))),
})
public CommonResponse<GetSchoolCalendarRes> isKoyeon() {
return CommonResponse.success(schoolCalendarService.isKoyeon());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package devkor.com.teamcback.domain.schoolcalendar.dto.response;

import devkor.com.teamcback.domain.schoolcalendar.entity.SchoolCalendar;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;

@Schema(description = "방학 여부 응답 dto")
@Getter
public class GetSchoolCalendarRes {

@Schema(description = "학교 일정 ID", example = "1")
private Long id;
@Schema(description = "학교 일정 이름", example = "방학")
private String name;
@Schema(description = "일정 여부", example = "true")
private boolean isActive;

public GetSchoolCalendarRes(SchoolCalendar schoolCalendar) {
this.id = schoolCalendar.getId();
this.name = schoolCalendar.getName();
this.isActive = schoolCalendar.isActive();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package devkor.com.teamcback.domain.schoolcalendar.dto.response;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "편의시설 수정 응답 dto")
@JsonIgnoreProperties
public class UpdateSchoolCalendarRes {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package devkor.com.teamcback.domain.schoolcalendar.entity;

import devkor.com.teamcback.domain.common.entity.BaseEntity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Getter
@Table(name = "tb_school_calendar")
@NoArgsConstructor
public class SchoolCalendar extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(nullable = false)
private String name;

@Setter
@Column(nullable = false)
private boolean isActive;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package devkor.com.teamcback.domain.schoolcalendar.repository;

import devkor.com.teamcback.domain.schoolcalendar.entity.SchoolCalendar;
import org.springframework.data.jpa.repository.JpaRepository;

public interface SchoolCalendarRepository extends JpaRepository<SchoolCalendar, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package devkor.com.teamcback.domain.schoolcalendar.service;

import devkor.com.teamcback.domain.schoolcalendar.dto.response.GetSchoolCalendarRes;
import devkor.com.teamcback.domain.schoolcalendar.dto.response.UpdateSchoolCalendarRes;
import devkor.com.teamcback.domain.schoolcalendar.entity.SchoolCalendar;
import devkor.com.teamcback.domain.schoolcalendar.repository.SchoolCalendarRepository;
import devkor.com.teamcback.global.exception.exception.GlobalException;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import static devkor.com.teamcback.global.response.ResultCode.NOT_FOUND_SCHOOL_CALENDAR;

@Service
@RequiredArgsConstructor
public class SchoolCalendarService {
private final SchoolCalendarRepository schoolCalendarRepository;

/**
* 방학 여부 반환
*/
public GetSchoolCalendarRes isVacation() {
return new GetSchoolCalendarRes(findSchoolCalendar(1L));
}

/**
* 고연전 여부 반환
*/
public GetSchoolCalendarRes isKoyeon() {
return new GetSchoolCalendarRes(findSchoolCalendar(2L));
}

/**
* 방학 여부 수정(토글)
*/
@Transactional
public UpdateSchoolCalendarRes updateVacationActive() {
updateSchoolCalendarActive(1L);
return new UpdateSchoolCalendarRes();
}

/**
* 고연전 여부 수정(토글)
*/
@Transactional
public UpdateSchoolCalendarRes updateKoyeonActive() {
updateSchoolCalendarActive(2L);
return new UpdateSchoolCalendarRes();
}

/**
* 방학 여부 반환
*/
public boolean isVacationTf() {
SchoolCalendar schoolCalendar = schoolCalendarRepository.findById(1L).orElseThrow(() -> new GlobalException(NOT_FOUND_SCHOOL_CALENDAR));
return schoolCalendar.isActive();
}

/**
* 학교 일정 진행 여부 수정
*/
private void updateSchoolCalendarActive(long id) {
SchoolCalendar schoolCalendar = findSchoolCalendar(id);
schoolCalendar.setActive(!schoolCalendar.isActive()); // 수정
}

private SchoolCalendar findSchoolCalendar(Long id) {
return schoolCalendarRepository.findById(id).orElseThrow(() -> new GlobalException(NOT_FOUND_SCHOOL_CALENDAR));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class SearchBuildingDetailRes {

public SearchBuildingDetailRes(List<SearchMainFacilityRes> facilities, List<PlaceType> types, Building building, String imageUrl, boolean bookmarked) {
this.buildingId = building.getId();
this.name = "고려대학교 서울캠퍼스 " + building.getName();
this.name = "고려대학교 " + building.getName();
this.address = building.getAddress();
this.latitude = building.getNode().getLatitude();
this.longitude = building.getNode().getLongitude();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class SearchBuildingRes {

public SearchBuildingRes(Building building, String imageUrl, List<PlaceType> placeTypes) {
this.buildingId = building.getId();
this.name = "고려대학교 서울캠퍼스 " + building.getName();
this.name = "고려대학교 " + building.getName();
this.imageUrl = imageUrl != null ? imageUrl : building.getImageUrl();
this.detail = building.getDetail();
this.address = building.getAddress();
Expand Down
Loading
Loading