1919@ RequestMapping ()
2020public class RoomApiController {
2121
22- private static final String SMOKETEST_ROOM_NAME = "testroom-310a9c47-515c-4ad7-a229-ae8efbab7387" ;
2322 private static final Logger log = LoggerFactory .getLogger (RoomApiController .class );
2423 private final RoomRepository roomRepository ;
2524 private final Clock clock ;
@@ -84,7 +83,7 @@ public void publishEvent(@PathVariable String roomId, @RequestBody PutTimerReque
8483 timerRequest .timer ,
8584 timerRequest .user ,
8685 room .name ());
87- incrementTimerStatsExceptForTestRoom (room , timer );
86+ stats . incrementTimer (room . name () , timer );
8887 } else if (timerRequest .breaktimer () != null ) {
8988 long breaktimer = truncateTooLongTimers (timerRequest .breaktimer ());
9089 room .addBreaktimer (breaktimer , timerRequest .user ());
@@ -93,7 +92,7 @@ public void publishEvent(@PathVariable String roomId, @RequestBody PutTimerReque
9392 timerRequest .breaktimer (),
9493 timerRequest .user ,
9594 room .name ());
96- incrementBreakTimerStatsExceptForTestRoom (room , breaktimer );
95+ stats . incrementBreaktimer (room . name () , breaktimer );
9796 } else {
9897 log .warn ("Could not understand PUT request for room {}" , roomId );
9998 }
@@ -112,35 +111,27 @@ public void putGoal(@PathVariable String roomId, @RequestBody PutGoalRequest goa
112111 goalRequest .goal (),
113112 goalRequest .user (),
114113 room .name ());
114+ stats .incrementGoalCount (room .name ());
115115 } else {
116116 log .warn ("Could not understand PUT goal request for room {}" , roomId );
117117 }
118118 }
119119
120120 @ DeleteMapping ("/{roomId:[A-Za-z0-9-_]+}/goal" )
121121 @ ResponseStatus (HttpStatus .ACCEPTED )
122- public void putGoal (@ PathVariable String roomId , @ RequestBody DeleteGoalRequest deleteGoalRequest ) {
122+ public void deleteGoal (@ PathVariable String roomId , @ RequestBody DeleteGoalRequest deleteGoalRequest ) {
123123 var room = roomRepository .get (roomId );
124- room .deleteGoal (deleteGoalRequest .user ());
124+ room .deleteGoal (deleteGoalRequest .user (), Instant . now ( clock ) );
125125 }
126126
127127 @ GetMapping ("/{roomId:[A-Za-z0-9-_]+}/goal" )
128- @ ResponseStatus (HttpStatus .ACCEPTED )
128+ @ ResponseStatus (HttpStatus .NO_CONTENT )
129129 public ResponseEntity <GoalResponse > getGoal (@ PathVariable String roomId ) {
130130 var room = roomRepository .get (roomId );
131- return ResponseEntity .ofNullable (GoalResponse .of (room .currentGoal ()));
132- }
133-
134- private void incrementBreakTimerStatsExceptForTestRoom (Room room , long breaktimer ) {
135- if (!Objects .equals (room .name (), SMOKETEST_ROOM_NAME )) {
136- stats .incrementBreaktimer (breaktimer );
137- }
138- }
139-
140- private void incrementTimerStatsExceptForTestRoom (Room room , long timer ) {
141- if (!Objects .equals (room .name (), SMOKETEST_ROOM_NAME )) {
142- stats .incrementTimer (timer );
131+ if (!room .hasGoal ()){
132+ return ResponseEntity .noContent ().build ();
143133 }
134+ return ResponseEntity .ofNullable (GoalResponse .of (room .currentGoal ()));
144135 }
145136
146137 private static long truncateTooLongTimers (Long timer ) {
@@ -159,69 +150,5 @@ public static GoalResponse of(Room.Goal goal){
159150
160151 public record PutGoalRequest (String goal , String user ){}
161152 public record DeleteGoalRequest (String user ){}
162- static final class PutTimerRequest {
163-
164- private final Long timer ;
165- private final Long breaktimer ;
166- private final String user ;
167-
168- PutTimerRequest (Long timer , Long breaktimer , String user ) {
169- this .timer = timer ;
170- this .user = user ;
171- this .breaktimer = breaktimer ;
172- }
173-
174- public Long timer () {
175- return timer ;
176- }
177-
178- public Long breaktimer () {
179- return breaktimer ;
180- }
181-
182- public String user () {
183- return user ;
184- }
185-
186- public Long getTimer () {
187- return timer ;
188- }
189-
190- public Long getBreaktimer () {
191- return breaktimer ;
192- }
193-
194- public String getUser () {
195- return user ;
196- }
197-
198- @ Override
199- public boolean equals (Object obj ) {
200- if (obj == this ) return true ;
201- if (obj == null || obj .getClass () != this .getClass ()) return false ;
202- var that = (PutTimerRequest ) obj ;
203- return Objects .equals (this .timer , that .timer )
204- && Objects .equals (this .breaktimer , that .breaktimer )
205- && Objects .equals (this .user , that .user );
206- }
207-
208- @ Override
209- public int hashCode () {
210- return Objects .hash (timer , breaktimer , user );
211- }
212-
213- @ Override
214- public String toString () {
215- return "PutTimerRequest["
216- + "timer="
217- + timer
218- + ", "
219- + "breaktimer="
220- + breaktimer
221- + ", "
222- + "user="
223- + user
224- + ']' ;
225- }
226- }
153+ public record PutTimerRequest (Long timer , Long breaktimer , String user ){}
227154}
0 commit comments