Skip to content

Commit

Permalink
Merge pull request #192 from JNU-econovation/feat-191
Browse files Browse the repository at this point in the history
Feat 191
  • Loading branch information
capDoYeonLee authored Dec 6, 2024
2 parents 292d0e6 + d5b09cf commit 855b809
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ public class FilterEntity extends BaseEntity {
@Column(nullable = false)
private String filterColor;

// @OneToOne(fetch = FetchType.LAZY)
// @JoinColumn(name = "member_id")
// private MemberEntity member;

@Column(nullable = false)
private Long memberId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.demo.schedule.application.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Getter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SemesterScheduleResponse {
private String eventName;
private String eventStartDate;
private String eventEndDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ public List<AllPrivateCalendarResponse> getPrivateSchedule() {
return responseConverter.toPrivateModel(model);
}

public List<SemesterScheduleResponse> getSemesterSchedule() {
LocalDateTime requestNow = LocalDateTime.now();
List<ScheduleEntity> semesterScheduleResponses = scheduleJpaRepository.findOneSemesterPublicSchedule(requestNow);
return responseConverter.toSemesterScheduleResponse(semesterScheduleResponses);
}


public List<ScheduleEntity> findWeekendSchedule() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.example.demo.filter.persistence.FilterRepository;
import com.example.demo.schedule.application.dto.*;
import com.example.demo.schedule.domain.model.ScheduleModel;
import com.example.demo.schedule.infrastructure.persistence.ScheduleEntity;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -64,6 +65,20 @@ private AllPublicCalendarResponse toPublicCalendarResponse(ScheduleModel model)
.build();
}

public List<SemesterScheduleResponse> toSemesterScheduleResponse(List<ScheduleEntity> entities) {
return entities.stream()
.map(this::buildSemesterResponse)
.collect(Collectors.toList());
}

private SemesterScheduleResponse buildSemesterResponse(ScheduleEntity entity) {
return SemesterScheduleResponse.builder()
.eventName(entity.getEventName())
.eventStartDate(entity.getEventStartDate().toString())
.eventEndDate(entity.getEventEndDate().toString())
.build();
}


public List<AllPrivateCalendarResponse> toPrivateModel(List<ScheduleModel> models) {
return models.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.example.demo.filter.persistence.FilterEntity;
import com.example.demo.schedule.domain.ScheduleRepository;
import jakarta.persistence.EntityManager;
import jakarta.persistence.TypedQuery;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
Expand Down Expand Up @@ -32,6 +33,38 @@ public ScheduleEntity save(ScheduleEntity entity) {
}
}

public List<ScheduleEntity> findOneSemesterPublicSchedule(LocalDateTime requestDate) {
int month = requestDate.getMonthValue();
int year = requestDate.getYear();

LocalDateTime startDate;
LocalDateTime endDate;

if (month >= 2 && month <= 7) {
// 2월 ~ 7월
startDate = LocalDateTime.of(year, 2, 1, 0, 0);
endDate = LocalDateTime.of(year, 7, 31, 23, 59, 59);
} else if (month >= 8 && month <= 12) {
// 8월 ~ 다음해 1월
startDate = LocalDateTime.of(year, 8, 1, 0, 0);
endDate = LocalDateTime.of(year + 1, 1, 31, 23, 59, 59);
} else { // month == 1
// 전년도 8월 ~ 해당 연도 1월
startDate = LocalDateTime.of(year - 1, 8, 1, 0, 0);
endDate = LocalDateTime.of(year, 1, 31, 23, 59, 59);
}

String jpql = "SELECT s FROM ScheduleEntity s " +
"WHERE s.eventStartDate BETWEEN :startDate AND :endDate";

TypedQuery<ScheduleEntity> query = em.createQuery(jpql, ScheduleEntity.class);
query.setParameter("startDate", startDate);
query.setParameter("endDate", endDate);

return query.getResultList();
}




public List<ScheduleEntity> findWeekPublic(LocalDateTime startDate, LocalDateTime endDate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public ApiResponse<SuccessBody<List<AllPrivateCalendarResponse>>> getPrivate() {
return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.GETALL);
}

@GetMapping("semester")
public ApiResponse<SuccessBody<List<SemesterScheduleResponse>>> getSemesterSchedule() {
List<SemesterScheduleResponse> response = scheduleService.getSemesterSchedule();
return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.GET);
}

@GetMapping("slack/test")
@Scheduled(cron = "0 0 9 * * MON")
public void sendSlackMessage() {
Expand Down

0 comments on commit 855b809

Please sign in to comment.