Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV TO MAIN #1717

Merged
merged 14 commits into from
Dec 26, 2024
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
42 changes: 42 additions & 0 deletions backend/database/cabi_local.sql
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,48 @@ CREATE TABLE `section_alarm`
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci;

DROP TABLE IF EXISTS `presentation`;
CREATE TABLE `presentation`
(
`id` BIGINT AUTO_INCREMENT PRIMARY KEY,
`category` VARCHAR(255) NULL,
`date_time` DATETIME(6) NULL,
`detail` VARCHAR(500) NULL,
`presentation_location` VARCHAR(255) NULL,
`presentation_status` VARCHAR(255) NULL,
`presentation_time` VARCHAR(255) NULL,
`subject` VARCHAR(25) NULL,
`summary` VARCHAR(40) NULL,
`user_id` BIGINT NULL,
CONSTRAINT `presentation_user_id`
FOREIGN KEY (`user_id`) REFERENCES `user` (`id`)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci;

LOCK TABLES `presentation` WRITE;
/*!40000 ALTER TABLE `presentation`
DISABLE KEYS */;
INSERT INTO `presentation`
VALUES (1, 'JOB', '2024-10-09 14:00:00', 'dummy', 'BASEMENT', 'EXPECTED', 'HALF', 'dummy', 'dummy', NULL),
(2, NULL, '2024-10-23 14:00:00', 'dummy', 'BASEMENT', 'CANCEL', 'HALF', 'dummy', 'dummy', NULL),
(3, NULL, '2024-11-05 14:00:00', 'dummy', 'BASEMENT', 'EXPECTED', 'HALF', 'dummy', 'dummy', NULL),
(4, 'JOB', '2024-11-19 14:00:00', 'dummy', 'BASEMENT', 'EXPECTED', 'HALF', 'dummy', 'dummy', NULL),
(5, NULL, '2024-12-11 14:00:00', 'dummy', 'BASEMENT', 'EXPECTED', 'HALF', 'dummy', 'dummy', NULL),
(6, 'JOB', '2024-12-25 14:00:00', 'dummy', 'BASEMENT', 'EXPECTED', 'HALF', 'dummy', 'dummy', NULL),
(7, NULL, '2025-01-08 14:00:00', 'dummy', 'BASEMENT', 'EXPECTED', 'HALF', 'dummy', 'dummy', NULL),
(8, NULL, '2025-01-22 14:00:00', 'dummy', 'BASEMENT', 'EXPECTED', 'HALF', 'dummy', 'dummy', NULL),
(9, NULL, '2025-02-12 14:00:00', 'dummy', 'BASEMENT', 'EXPECTED', 'HALF', 'dummy', 'dummy', NULL),
(10, NULL, '2025-02-26 14:00:00', 'dummy', 'BASEMENT', 'EXPECTED', 'HALF', 'dummy', 'dummy', NULL),
(11, NULL, '2025-03-12 14:00:00', 'dummy', 'BASEMENT', 'EXPECTED', 'HALF', 'dummy', 'dummy', NULL),
(12, NULL, '2025-03-26 14:00:00', 'dummy', 'BASEMENT', 'EXPECTED', 'HALF', 'dummy', 'dummy', NULL);
(13, NULL, '2025-04-09 14:00:00', 'dummy', 'BASEMENT', 'EXPECTED', 'HALF', 'dummy', 'dummy', NULL);
(14, NULL, '2025-04-23 14:00:00', 'dummy', 'BASEMENT', 'EXPECTED', 'HALF', 'dummy', 'dummy', NULL);
(15, NULL, '2025-05-07 14:00:00', 'dummy', 'BASEMENT', 'EXPECTED', 'HALF', 'dummy', 'dummy', NULL);
(16, NULL, '2025-05-21 14:00:00', 'dummy', 'BASEMENT', 'EXPECTED', 'HALF', 'dummy', 'dummy', NULL);
/*!40000 ALTER TABLE `presentation`
ENABLE KEYS */;
UNLOCK TABLES;

/*!40103 SET TIME_ZONE = @OLD_TIME_ZONE */;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.ftclub.cabinet.dto;

import java.time.LocalDateTime;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class AbleDateResponseDto {

private List<LocalDateTime> results;
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public enum ExceptionStatus {
INVALID_CLUB_MASTER(HttpStatus.BAD_REQUEST, "동아리에 동아리 장이 없습니다."),
NOT_FOUND_CLUB_LENT_HISTORY(HttpStatus.NOT_FOUND, "동아리가 대여한 사물함이 없습니다."),
INVALID_PRESENTATION_CATEGORY(HttpStatus.BAD_REQUEST, "발표회에 정의된 카테고리가 아닙니다."),
INVALID_PRESENTATION_DATE(HttpStatus.BAD_REQUEST, "가능한 발표 날짜가 아닙니다"),
INVALID_DATE(HttpStatus.BAD_REQUEST, "잘못된 날짜입니다."),
PRESENTATION_ALREADY_EXISTED(HttpStatus.CONFLICT, "이미 예약된 발표 날짜입니다"),
NOT_FOUND_FORM(HttpStatus.NOT_FOUND, "신청서가 존재하지 않습니다."),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.ftclub.cabinet.mapper;

import java.time.LocalDate;
import java.util.List;
import org.ftclub.cabinet.dto.PresentationFormData;
import org.ftclub.cabinet.dto.PresentationFormRequestDto;
import org.ftclub.cabinet.dto.PresentationMainData;
import org.ftclub.cabinet.dto.PresentationMyPageDto;
import org.ftclub.cabinet.presentation.domain.Presentation;
Expand All @@ -19,5 +21,4 @@ public interface PresentationMapper {

PresentationMainData toPresentationMainData(List<PresentationFormData> past,
List<PresentationFormData> upcoming);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.RequiredArgsConstructor;
import org.ftclub.cabinet.auth.domain.AuthGuard;
import org.ftclub.cabinet.auth.domain.AuthLevel;
import org.ftclub.cabinet.dto.AbleDateResponseDto;
import org.ftclub.cabinet.dto.InvalidDateResponseDto;
import org.ftclub.cabinet.dto.PresentationFormRequestDto;
import org.ftclub.cabinet.dto.PresentationFormResponseDto;
Expand Down Expand Up @@ -39,6 +40,11 @@ public void createPresentationForm(
presentationService.createPresentationForm(user.getUserId(), dto);
}

@GetMapping("/able-date")
public AbleDateResponseDto getAbleDate() {
return presentationService.getAbleDate();
}

@GetMapping("/form/invalid-date")
public InvalidDateResponseDto getInvalidDate() {
return presentationService.getInvalidDate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -19,6 +20,7 @@

@Entity
@Getter
@Table(name = "PRESENTATION")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Presentation {

Expand Down Expand Up @@ -56,12 +58,11 @@ public class Presentation {

@Setter
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "USER_ID")
@JoinColumn(name = "USER_ID", nullable = true)
private User user;

protected Presentation(Category category, LocalDateTime dateTime,
protected Presentation(LocalDateTime dateTime,
PresentationTime presentationTime, String subject, String summary, String detail) {
this.category = category;
this.dateTime = dateTime;
this.presentationTime = presentationTime;
this.subject = subject;
Expand All @@ -71,10 +72,10 @@ protected Presentation(Category category, LocalDateTime dateTime,
this.presentationLocation = PresentationLocation.BASEMENT;
}

public static Presentation of(Category category, LocalDateTime dateTime,
public static Presentation of(LocalDateTime dateTime,
PresentationTime presentationTime, String subject, String summary, String detail) {

return new Presentation(category, dateTime, presentationTime, subject, summary, detail);
return new Presentation(dateTime, presentationTime, subject, summary, detail);
}

public void adminUpdate(PresentationStatus newStatus, LocalDateTime newDateTime,
Expand All @@ -83,4 +84,16 @@ public void adminUpdate(PresentationStatus newStatus, LocalDateTime newDateTime,
this.dateTime = newDateTime;
this.presentationLocation = newLocation;
}

public void updateDummyToUserForm(Category category,
PresentationTime presentationTime, LocalDateTime presentationDateTime,
String subject, String summary, String detail) {
this.category = category;
this.presentationTime = presentationTime;
this.dateTime = presentationDateTime;
this.subject = subject;
this.summary = summary;
this.detail = detail;
this.presentationStatus = PresentationStatus.EXPECTED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ public interface PresentationRepository extends JpaRepository<Presentation, Long

@EntityGraph(attributePaths = "user")
List<Presentation> findAllByDateTimeBetweenOrderByDateTime(LocalDateTime start,
LocalDateTime end);
LocalDateTime end);

List<Presentation> findAllByDateTimeBetween(LocalDateTime start, LocalDateTime end);

@EntityGraph(attributePaths = "user")
List<Presentation> findByDateTimeBetween(@Param("start") LocalDateTime start,
@Param("end") LocalDateTime end, Pageable pageable);

@Query("SELECT p "
+ "FROM Presentation p "
+ "WHERE p.user.id = :userId")
+ "FROM Presentation p "
+ "WHERE p.user.id = :userId")
Page<Presentation> findPaginationById(@Param("userId") Long userId, Pageable pageable);

@Query("SELECT p "
+ "FROM Presentation p "
+ "WHERE p.user IS NOT NULL "
+ "AND p.dateTime BETWEEN :start AND :end")
List<Presentation> findAllBetweenAndNotNullUser(
@Param("start") LocalDateTime start,
@Param("end") LocalDateTime end,
Pageable pageable
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import lombok.RequiredArgsConstructor;
import org.ftclub.cabinet.exception.ExceptionStatus;
import org.ftclub.cabinet.presentation.domain.Presentation;
import org.ftclub.cabinet.presentation.domain.PresentationLocation;
import org.ftclub.cabinet.presentation.domain.PresentationStatus;
import org.ftclub.cabinet.presentation.repository.PresentationRepository;
import org.springframework.stereotype.Service;
Expand All @@ -33,23 +32,23 @@ public void verifyReservationDate(LocalDateTime localDateTime) {
LocalDateTime endOfDay = startOfDay.plusDays(1);

if (isOverRangeDate(reservationDate, now)
|| isAlreadyRegisteredDate(startOfDay,
endOfDay)) {
|| isAlreadyRegisteredDate(startOfDay, endOfDay)) {
throw ExceptionStatus.INVALID_DATE.asServiceException();
}
}

private boolean isAlreadyRegisteredDate(LocalDateTime startOfDay, LocalDateTime endOfDay) {
List<Presentation> presentations =
presentationRepository.findAllByDateTimeBetween(startOfDay, endOfDay);
presentationRepository.findAllByDateTimeBetween(startOfDay, endOfDay);

return presentations.stream()
.anyMatch(presentation ->
!presentation.getPresentationStatus().equals(PresentationStatus.CANCEL));
.anyMatch(presentation -> presentation.getUser() != null
&& presentation.getPresentationStatus()
.equals(PresentationStatus.EXPECTED));
}

private boolean isOverRangeDate(LocalDate reservationDate, LocalDate now) {
return reservationDate.isBefore(now) ||
reservationDate.isAfter(now.plusMonths(MAXIMUM_MONTH));
reservationDate.isAfter(now.plusMonths(MAXIMUM_MONTH));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.ftclub.cabinet.exception.ExceptionStatus;
import org.ftclub.cabinet.presentation.domain.Presentation;
import org.ftclub.cabinet.presentation.domain.PresentationStatus;
import org.ftclub.cabinet.presentation.repository.PresentationRepository;
Expand All @@ -23,30 +24,54 @@ public class PresentationQueryService {

public List<Presentation> getRegisteredPresentations(LocalDateTime start, LocalDateTime end) {
List<Presentation> presentations =
presentationRepository.findAllByDateTimeBetween(start, end);
presentationRepository.findAllByDateTimeBetween(start, end);

return presentations.stream()
.filter(presentation ->
!presentation.getPresentationStatus().equals(PresentationStatus.CANCEL))
.collect(Collectors.toList());
}

public List<Presentation> getPresentationsBetweenWithPageRequest(LocalDateTime start,
LocalDateTime end,
PageRequest pageRequest) {
return presentationRepository.findByDateTimeBetween(start, end, pageRequest);
.filter(presentation ->
presentation.getPresentationStatus().equals(PresentationStatus.EXPECTED)
&& presentation.getUser() != null
)
.collect(Collectors.toList());
}

public List<Presentation> getPresentationsByYearMonth(YearMonth yearMonth) {
LocalDateTime startDate = yearMonth.atDay(START_DAY).atStartOfDay();
LocalDateTime endDayDate = yearMonth.atEndOfMonth().atTime(23, 59, 59);

return presentationRepository.findAllByDateTimeBetweenOrderByDateTime(startDate,
endDayDate);
endDayDate);
}

public Presentation getOneDummyByDate(LocalDateTime dateTime) {
LocalDateTime startOfDate = dateTime.withHour(0).withMinute(0).withSecond(0);
LocalDateTime endOfDate = dateTime.withHour(23).withMinute(59).withSecond(59);
return presentationRepository.findAllByDateTimeBetween(startOfDate, endOfDate)
.stream()
.filter(p -> p.getUser() == null)
.findFirst()
.orElseThrow(ExceptionStatus.INVALID_PRESENTATION_DATE::asServiceException);
}

public Page<Presentation> getPresentationsById(Long id, Pageable pageable) {
return presentationRepository.findPaginationById(id, pageable);
}

public List<Presentation> getDummyDateBetweenMonth(
LocalDateTime now,
LocalDateTime localDateTime) {

List<Presentation> presentations =
presentationRepository.findAllByDateTimeBetweenOrderByDateTime(now, localDateTime);

return presentations.stream()
.filter(presentation -> presentation.getUser() == null)
.collect(Collectors.toList());
}

public List<Presentation> findUserFormsWithinPeriod(
LocalDateTime start,
LocalDateTime end,
PageRequest pageRequest) {
return presentationRepository.findAllBetweenAndNotNullUser(start, end, pageRequest);
}
}
Loading
Loading