Skip to content

Commit e9ad039

Browse files
committed
feat(recruit-board): RecruitBoard 엔티티 수정
- 필드 추가 및 수정 - 메서드 추가
1 parent 32ca631 commit e9ad039

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

src/main/java/com/somemore/recruitboard/domain/RecruitBoard.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import jakarta.persistence.Id;
1414
import jakarta.persistence.Lob;
1515
import jakarta.persistence.Table;
16+
import java.time.Duration;
1617
import java.time.LocalDateTime;
1718
import java.time.LocalTime;
1819
import java.util.UUID;
@@ -56,33 +57,51 @@ public class RecruitBoard extends BaseEntity {
5657
@Column(name = "recruit_status", nullable = false, length = 20)
5758
private RecruitStatus recruitStatus = RECRUITING;
5859

59-
@Column(name = "volunteer_date", nullable = false)
60-
private LocalDateTime volunteerDate;
60+
@Column(name = "volunteer_start_date_time", nullable = false)
61+
private LocalDateTime volunteerStartDateTime;
62+
63+
@Column(name = "volunteer_end_date_time", nullable = false)
64+
private LocalDateTime volunteerEndDateTime;
6165

6266
@Enumerated(value = STRING)
6367
@Column(name = "volunteer_type", nullable = false, length = 30)
6468
private VolunteerType volunteerType;
6569

66-
@Column(name = "volunteer_hours", nullable = false)
67-
private LocalTime volunteerHours;
68-
6970
@Column(name = "admitted", nullable = false)
7071
private Boolean admitted;
7172

7273
@Builder
7374
public RecruitBoard(UUID centerId, Long locationId, String title, String content, String region,
74-
Integer recruitmentCount, String imgUrl, LocalDateTime volunteerDate,
75-
VolunteerType volunteerType, LocalTime volunteerHours, Boolean admitted) {
75+
Integer recruitmentCount, String imgUrl, LocalDateTime volunteerStartDateTime,
76+
LocalDateTime volunteerEndDateTime, VolunteerType volunteerType, Boolean admitted) {
77+
78+
validateVolunteerDateTime(volunteerStartDateTime, volunteerEndDateTime);
79+
7680
this.centerId = centerId;
7781
this.locationId = locationId;
7882
this.title = title;
7983
this.content = content;
8084
this.region = region;
8185
this.recruitmentCount = recruitmentCount;
8286
this.imgUrl = imgUrl;
83-
this.volunteerDate = volunteerDate;
87+
this.volunteerStartDateTime = volunteerStartDateTime;
88+
this.volunteerEndDateTime = volunteerEndDateTime;
8489
this.volunteerType = volunteerType;
85-
this.volunteerHours = volunteerHours;
8690
this.admitted = admitted;
8791
}
92+
93+
public LocalTime calculateVolunteerTime() {
94+
Duration duration = Duration.between(volunteerStartDateTime, volunteerEndDateTime);
95+
96+
long hours = duration.toHours();
97+
long minutes = duration.toMinutes() % 60;
98+
99+
return LocalTime.of((int) hours, (int) minutes);
100+
}
101+
102+
private void validateVolunteerDateTime(LocalDateTime startDateTime, LocalDateTime endDateTime) {
103+
if (endDateTime.isEqual(startDateTime) || endDateTime.isBefore(startDateTime)) {
104+
throw new IllegalArgumentException("종료 시간은 시작 시간보다 이후여야 합니다.");
105+
}
106+
}
88107
}

0 commit comments

Comments
 (0)