Skip to content

Commit 4835cb1

Browse files
authored
feat/KD-41-domain Schedule 도메인 엔티티 설계 (#277)
* feature/KD-41: Schedule도메인 이름 수정민 jpa baseTime상속 추가 * feature/KD-41-domain: Schedule 도메인 엔티티 설계 * feature/KD-41-domain: ScheduleService 예외 참조 수정 * feature/KD-41-domain: schedule statusAt->determineStatusAt로 변경 findBySubmissionTyp 오타 수정 , entity,repository 패키지 생성하여 분리 작업 * feature/KD-41-domain: schedule의 db 스키마를 추가했습니다.
1 parent 8cc5c42 commit 4835cb1

File tree

14 files changed

+386
-0
lines changed

14 files changed

+386
-0
lines changed

aics-api/src/main/resources/db/data.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,18 @@ VALUES
140140
('박민수', '[email protected]', '정약용', '논문', '2029-02-28', 3, NULL, NULL, '202512347', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
141141
('정수진', '[email protected]', '김이박', '논문', '2030-02-28', 4, 5, NULL, '202512349', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
142142
('최동욱', '[email protected]', '이교수', '자격증', '2027-08-31', NULL, NULL, 2, '202512348', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
143+
144+
-- schedule
145+
INSERT INTO schedule (submission_type, title, content, start_date, end_date, created_at, updated_at)
146+
VALUES ('SUBMITTED', '신청 접수', '학부생 졸업 논문 신청을 접수합니다.', '2025-02-24 09:00:00', '2025-03-10 18:00:00',
147+
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
148+
('MIDTHESIS', '중간 보고서', '중간 논문 제출 및 심사 기간입니다.', '2025-04-01 09:00:00', '2025-04-12 18:00:00',
149+
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
150+
('FINALTHESIS', '최종 보고서', '최종 논문 제출 및 심사 기간입니다.', '2025-05-20 09:00:00', '2025-06-05 18:00:00',
151+
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
152+
('CERTIFICATE', '제안서', '취득한 자격증 제출 및 심사 기간입니다.', '2025-03-15 09:00:00', '2025-03-29 18:00:00',
153+
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
154+
('APPROVED', '최종 통과', '최종 승인 기간입니다.', '2025-06-10 09:00:00', '2025-06-14 18:00:00',
155+
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
156+
('OTHER', '기타 일정 안내', '기타 일정 입니다.', '2025-03-01 09:00:00', '2025-12-31 18:00:00',
157+
CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);

aics-api/src/main/resources/db/schema.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,21 @@ CREATE TABLE graduation_user
171171
ON DELETE CASCADE,
172172
CONSTRAINT fk_graduation_user_certificate FOREIGN KEY (certificate_id) REFERENCES "certificate" (id)
173173
ON DELETE CASCADE,
174+
);
175+
176+
-- schedule
177+
CREATE TABLE schedule
178+
(
179+
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
180+
submission_type VARCHAR(20) NOT NULL UNIQUE
181+
CONSTRAINT schedule_submission_type_check
182+
CHECK ((submission_type)::TEXT = ANY
183+
(ARRAY ['SUBMITTED', 'MIDTHESIS', 'FINALTHESIS', 'CERTIFICATE', 'APPROVED', 'OTHER'])),
184+
title VARCHAR(100) NOT NULL,
185+
content TEXT NOT NULL,
186+
start_date TIMESTAMP(6) NOT NULL,
187+
end_date TIMESTAMP(6) NOT NULL,
188+
created_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
189+
updated_at TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
190+
deleted_at TIMESTAMP(6) DEFAULT NULL
174191
);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package kgu.developers.domain.schedule.application.command;
2+
3+
4+
import kgu.developers.domain.schedule.domain.Schedule;
5+
import kgu.developers.domain.schedule.domain.ScheduleRepository;
6+
import kgu.developers.domain.schedule.domain.SubmissionType;
7+
import kgu.developers.domain.schedule.exception.DuplicateScheduleTypeException;
8+
import lombok.RequiredArgsConstructor;
9+
import org.springframework.stereotype.Service;
10+
import org.springframework.transaction.annotation.Transactional;
11+
12+
import java.time.LocalDateTime;
13+
14+
@Service
15+
@RequiredArgsConstructor
16+
public class ScheduleService {
17+
private final ScheduleRepository scheduleRepository;
18+
19+
public Long createSchedule(SubmissionType submissionType, String title, String content , LocalDateTime startDate, LocalDateTime endDate) {
20+
scheduleRepository.findBySubmissionType(submissionType).ifPresent(existing -> {
21+
throw new DuplicateScheduleTypeException();
22+
});
23+
Schedule schedule = Schedule.create(submissionType,title,content,startDate,endDate);
24+
25+
return scheduleRepository.save(schedule).getId();
26+
}
27+
@Transactional
28+
public void updateSchedule(Schedule schedule, SubmissionType submissionType , String title, LocalDateTime startDate, LocalDateTime endDate) {
29+
schedule.updateSubmissionType(submissionType);
30+
schedule.updateTitle(title);
31+
schedule.updateStartDate(startDate);
32+
schedule.updateEndDate(endDate);
33+
34+
scheduleRepository.save(schedule);
35+
}
36+
@Transactional
37+
public void updateScheduleContent(Schedule schedule, String content) {
38+
schedule.updateContent(content);
39+
scheduleRepository.save(schedule);
40+
}
41+
public void deleteSchedule(Long id) {
42+
scheduleRepository.deleteById(id);
43+
}
44+
45+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package kgu.developers.domain.schedule.application.query;
2+
3+
import kgu.developers.domain.schedule.domain.Schedule;
4+
import kgu.developers.domain.schedule.domain.ScheduleRepository;
5+
import kgu.developers.domain.schedule.domain.SubmissionType;
6+
import kgu.developers.domain.schedule.exception.ScheduleNotFoundException;
7+
import lombok.RequiredArgsConstructor;
8+
import org.springframework.stereotype.Service;
9+
10+
import java.util.List;
11+
12+
@Service
13+
@RequiredArgsConstructor
14+
public class ScheduleQueryService {
15+
private final ScheduleRepository scheduleRepository;
16+
17+
public List<Schedule> getAllScheduleManagements() {
18+
return scheduleRepository.findAll();
19+
}
20+
21+
public Schedule getScheduleManagement(Long id) {
22+
return scheduleRepository
23+
.findById(id)
24+
.orElseThrow(ScheduleNotFoundException::new);
25+
}
26+
public Schedule getBySubmissionType(SubmissionType submissionType) {
27+
return scheduleRepository.findBySubmissionType(submissionType)
28+
.orElseThrow(ScheduleNotFoundException::new);
29+
}
30+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package kgu.developers.domain.schedule.domain;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Builder;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
8+
import java.time.LocalDateTime;
9+
10+
@Getter
11+
@Builder
12+
@NoArgsConstructor
13+
@AllArgsConstructor
14+
public class Schedule {
15+
16+
private Long id;
17+
private SubmissionType submissionType;
18+
private String title;
19+
private String content;
20+
private LocalDateTime startDate;
21+
private LocalDateTime endDate;
22+
23+
private LocalDateTime createdAt;
24+
private LocalDateTime updatedAt;
25+
private LocalDateTime deletedAt;
26+
27+
28+
public static Schedule create(SubmissionType submissionType, String title,String content, LocalDateTime startDate, LocalDateTime endDate) {
29+
return Schedule.builder()
30+
.submissionType(submissionType)
31+
.title(title)
32+
.content(content)
33+
.startDate(startDate)
34+
.endDate(endDate)
35+
.build();
36+
}
37+
public ScheduleStatus determineStatusAt(LocalDateTime referenceTime) {
38+
if (referenceTime.isBefore(startDate)) {
39+
return ScheduleStatus.PENDING;
40+
}
41+
if (referenceTime.isAfter(endDate)) {
42+
return ScheduleStatus.CLOSED;
43+
}
44+
return ScheduleStatus.IN_PROGRESS;
45+
}
46+
public void updateSubmissionType(SubmissionType submissionType) {
47+
this.submissionType = submissionType;
48+
}
49+
public void updateTitle(String title) {
50+
this.title = title;
51+
}
52+
public void updateContent(String content) {this.content = content;}
53+
public void updateStartDate(LocalDateTime startDate) {
54+
this.startDate = startDate;
55+
}
56+
public void updateEndDate(LocalDateTime endDate) {
57+
this.endDate = endDate;
58+
}
59+
60+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package kgu.developers.domain.schedule.domain;
2+
3+
import java.util.List;
4+
import java.util.Optional;
5+
6+
public interface ScheduleRepository {
7+
Schedule save(Schedule schedule);
8+
void deleteById(Long id);
9+
Optional<Schedule> findById(Long id);
10+
List<Schedule> findAll();
11+
Optional<Schedule> findBySubmissionType(SubmissionType submissionType);
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package kgu.developers.domain.schedule.domain;
2+
3+
import lombok.Getter;
4+
import lombok.RequiredArgsConstructor;
5+
6+
@Getter
7+
@RequiredArgsConstructor
8+
public enum ScheduleStatus {
9+
PENDING("대기"),
10+
IN_PROGRESS("진행 중"),
11+
CLOSED("마감")
12+
;
13+
private final String label;
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package kgu.developers.domain.schedule.domain;
2+
3+
import lombok.Getter;
4+
import lombok.RequiredArgsConstructor;
5+
6+
@Getter
7+
@RequiredArgsConstructor
8+
public enum SubmissionType {
9+
SUBMITTED("신청접수"),
10+
MIDTHESIS("중간논문"),
11+
FINALTHESIS("최종논문"),
12+
CERTIFICATE("자격증"),
13+
APPROVED("최종 통과"),
14+
OTHER("기타")
15+
;
16+
private final String label;
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package kgu.developers.domain.schedule.exception;
2+
3+
import kgu.developers.common.exception.CustomException;
4+
5+
import static kgu.developers.domain.schedule.exception.ScheduleDomainExceptionCode.DUPLICATE_SCHEDULE_TYPE;
6+
7+
public class DuplicateScheduleTypeException extends CustomException {
8+
public DuplicateScheduleTypeException() {super(DUPLICATE_SCHEDULE_TYPE);}
9+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package kgu.developers.domain.schedule.exception;
2+
3+
import kgu.developers.common.exception.ExceptionCode;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
import org.springframework.http.HttpStatus;
7+
8+
import static org.springframework.http.HttpStatus.BAD_REQUEST;
9+
import static org.springframework.http.HttpStatus.NOT_FOUND;
10+
11+
@Getter
12+
@AllArgsConstructor
13+
public enum ScheduleDomainExceptionCode implements ExceptionCode {
14+
DUPLICATE_SCHEDULE_TYPE(BAD_REQUEST, "동일 제출 유형의 일정이 이미 존재합 니다."),
15+
SCHEDULE_MANAGEMENT_NOT_FOUND(NOT_FOUND,"해당 일정을 찾을 수 없습니다.");
16+
17+
private final HttpStatus status;
18+
private final String message;
19+
20+
@Override
21+
public String getCode() {return this.name();}
22+
23+
24+
}

0 commit comments

Comments
 (0)