1313import jakarta .persistence .Id ;
1414import jakarta .persistence .Lob ;
1515import jakarta .persistence .Table ;
16+ import java .time .Duration ;
1617import java .time .LocalDateTime ;
1718import java .time .LocalTime ;
1819import 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