File tree Expand file tree Collapse file tree 3 files changed +31
-8
lines changed
src/main/java/com/example/wini Expand file tree Collapse file tree 3 files changed +31
-8
lines changed Original file line number Diff line number Diff line change 11package com .example .wini .domain .member .dto .common ;
22
3+ import static com .example .wini .global .common .constant .StatusReserveTimeConstants .INDEFINITE_HOUR ;
4+ import static com .example .wini .global .common .constant .StatusReserveTimeConstants .INDEFINITE_MINUTE ;
5+ import static com .example .wini .global .common .constant .StatusReserveTimeConstants .INDEFINITE_SECONDS ;
6+ import static com .example .wini .global .common .constant .StatusReserveTimeConstants .SECONDS_PER_HOUR ;
7+ import static com .example .wini .global .common .constant .StatusReserveTimeConstants .SECONDS_PER_MINUTE ;
8+
39import jakarta .validation .constraints .Max ;
410import jakarta .validation .constraints .Min ;
511import jakarta .validation .constraints .NotNull ;
6- import java .time .Duration ;
712
813public record ReservedTimeInfo (
914 @ NotNull @ Min (value = -1 ) @ Max (value = 12 ) Long hour , @ NotNull @ Min (value = -1 ) @ Max (value = 59 ) Long minute ) {
1015 public static ReservedTimeInfo of (long hour , long minute ) {
1116 return new ReservedTimeInfo (hour , minute );
1217 }
1318
14- public Duration toDuration () {
15- if (this .hour == - 1 && this .minute == - 1 ) {
16- return Duration . ofDays ( 365L * 100 ) ;
19+ public long toSeconds () {
20+ if (this .hour == INDEFINITE_HOUR && this .minute == INDEFINITE_MINUTE ) {
21+ return INDEFINITE_SECONDS ;
1722 }
18-
19- return Duration .ofHours (this .hour ).plusMinutes (this .minute );
23+ return this .hour * SECONDS_PER_HOUR + this .minute * SECONDS_PER_MINUTE ;
2024 }
2125}
Original file line number Diff line number Diff line change 11package com .example .wini .domain .member .service ;
22
3+ import static com .example .wini .global .common .constant .StatusReserveTimeConstants .INDEFINITE_HOUR ;
4+ import static com .example .wini .global .common .constant .StatusReserveTimeConstants .INDEFINITE_MINUTE ;
5+ import static com .example .wini .global .common .constant .StatusReserveTimeConstants .INDEFINITE_SECONDS ;
36import static com .example .wini .global .error .exception .ErrorCode .MATE_NOT_FOUND ;
47import static com .example .wini .global .error .exception .ErrorCode .STATUS_NOT_FOUND ;
58
@@ -72,6 +75,10 @@ private boolean isStatusValid(Member member) {
7275 }
7376
7477 private ReservedTimeInfo createReservedTimeInfo (long durationSeconds ) {
78+ if (durationSeconds == INDEFINITE_SECONDS ) {
79+ return ReservedTimeInfo .of (INDEFINITE_HOUR , INDEFINITE_MINUTE );
80+ }
81+
7582 Duration duration = Duration .ofSeconds (durationSeconds );
7683 return ReservedTimeInfo .of (duration .toHours (), duration .toMinutes () % 60 );
7784 }
@@ -83,8 +90,7 @@ public MemberStatusResponse updateStatus(MemberStatusUpdateRequest request) {
8390 Status status =
8491 statusRepository .findById (request .statusId ()).orElseThrow (() -> new CustomException (STATUS_NOT_FOUND ));
8592
86- Duration statusDuration = request .reservedTimeInfo ().toDuration ();
87- Long statusDurationSeconds = statusDuration .getSeconds ();
93+ Long statusDurationSeconds = request .reservedTimeInfo ().toSeconds ();
8894
8995 member .updateStatus (status , request .startedAt (), statusDurationSeconds );
9096 notifyRoommateOfStatusUpdate (member .getId ());
Original file line number Diff line number Diff line change 1+ package com .example .wini .global .common .constant ;
2+
3+ public class StatusReserveTimeConstants {
4+
5+ public static final int SECONDS_PER_HOUR = 3600 ;
6+ public static final int SECONDS_PER_MINUTE = 60 ;
7+
8+ public static final long INDEFINITE_SECONDS = 365L * 100 * 24 * 60 * 60 ;
9+ public static final long INDEFINITE_HOUR = -1L ;
10+ public static final long INDEFINITE_MINUTE = -1L ;
11+
12+ private StatusReserveTimeConstants () {}
13+ }
You canβt perform that action at this time.
0 commit comments