11package meet_at_mensa .matching .controller ;
22
33import org .springframework .beans .factory .annotation .Autowired ;
4+ import org .springframework .http .HttpStatus ;
45import org .springframework .http .ResponseEntity ;
56import org .springframework .web .bind .annotation .RestController ;
67
78import jakarta .validation .Valid ;
9+ import meet_at_mensa .matching .exception .MatchNotFoundException ;
10+ import meet_at_mensa .matching .exception .RequestNotFoundException ;
11+ import meet_at_mensa .matching .exception .RequestOverlapException ;
812import meet_at_mensa .matching .service .MatchRequestService ;
913import meet_at_mensa .matching .service .MatchService ;
1014import meet_at_mensa .matching .service .MatchingService ;
@@ -29,24 +33,89 @@ public class MatchingController implements MatchingApi {
2933 // DELETE @ api/v2/matching/request/{requestID}
3034 @ Override
3135 public ResponseEntity <Void > deleteApiV2MatchingRequestRequestId (UUID requestId ) {
32- // TODO: Implement deletion logic using requestId
33- return ResponseEntity .ok ().build ();
36+
37+ // 200
38+ try {
39+
40+ // attempt to remove request
41+ requestService .removeRequest (requestId );
42+
43+ // if ok, return 200
44+ return ResponseEntity .ok ().build ();
45+
46+
47+ // 404
48+ } catch (RequestNotFoundException e ) {
49+
50+ // if request not found return 404
51+ return ResponseEntity .notFound ().build ();
52+
53+ // 500
54+ } catch (Exception e ) {
55+
56+ // if some other exception occurs
57+ return ResponseEntity .internalServerError ().build ();
58+
59+ }
3460 }
3561
3662 // GET @ api/v2/matching/matches/{userID}
3763 @ Override
3864 public ResponseEntity <MatchCollection > getApiV2MatchingMatchesUserID (UUID userId ) {
39- // TODO: Fetch matches for userId
40- MatchCollection collection = new MatchCollection ();
41- return ResponseEntity .ok (collection );
65+
66+
67+ // 200
68+ try {
69+
70+ // attempt to get matches
71+ MatchCollection matches = matchService .getMatches (userId );
72+
73+ // return 200 with MatchCollection if found
74+ return ResponseEntity .ok (matches );
75+
76+ // 404
77+ } catch (MatchNotFoundException e ) {
78+
79+ // return 404 if no matches are found
80+ return ResponseEntity .notFound ().build ();
81+
82+ // 500
83+ } catch (Exception e ) {
84+
85+ // return 500 if another exception occurs
86+ return ResponseEntity .internalServerError ().build ();
87+
88+ }
89+
4290 }
4391
4492 // GET @ api/v2/matching/requests/{userID}
4593 @ Override
4694 public ResponseEntity <MatchRequestCollection > getApiV2MatchingRequestsUserID (UUID userId ) {
47- // TODO: Fetch match requests for userId
48- MatchRequestCollection collection = new MatchRequestCollection ();
49- return ResponseEntity .ok (collection );
95+
96+ // 200
97+ try {
98+
99+ // attempt to get MatchRequests
100+ MatchRequestCollection requests = requestService .getUserRequests (userId );
101+
102+ // return 200 with MatchRequestCollection if found
103+ return ResponseEntity .ok (requests );
104+
105+ // 404
106+ } catch (RequestNotFoundException e ) {
107+
108+ // return 404 if no MatchRequests are found
109+ return ResponseEntity .notFound ().build ();
110+
111+ // 500
112+ } catch (Exception e ) {
113+
114+ // return 500 if another exception occurs
115+ return ResponseEntity .internalServerError ().build ();
116+
117+ }
118+
50119 }
51120
52121 // GET @ api/v2/matching/rsvp/{matchID}/accept
@@ -65,19 +134,58 @@ public ResponseEntity<Void> getApiV2MatchingRsvpMatchIdReject(UUID matchId) {
65134
66135 // POST @ api/v2/matching/request/submit
67136 @ Override
68- public ResponseEntity <Void > postApiV2MatchingRequestSubmit (@ Valid MatchRequestNew matchRequestNew ) {
69- // TODO: Handle new match request submission
70- return ResponseEntity .ok ().build ();
137+ public ResponseEntity <MatchRequest > postApiV2MatchingRequestSubmit (@ Valid MatchRequestNew matchRequestNew ) {
138+
139+ // 200
140+ try {
141+
142+ // attempt to register a new matchRequset
143+ MatchRequest request = requestService .registerRequests (matchRequestNew );
144+
145+ // return 200 if successful
146+ return ResponseEntity .ok (request );
147+
148+ // 409
149+ } catch (RequestOverlapException e ) {
150+
151+ // return 409 if user already has a request on that day
152+ return ResponseEntity .status (HttpStatus .CONFLICT ).build ();
153+
154+ // 500
155+ } catch (Exception e ) {
156+
157+ // return 500 if another exception occurs
158+ return ResponseEntity .internalServerError ().build ();
159+
160+ }
71161 }
72162
73163 // PUT @ api/v2/matching/request/{requestID}
74164 @ Override
75- public ResponseEntity <MatchRequest > putApiV2MatchingRequestRequestId (
76- UUID requestId ,
77- @ Valid MatchRequestUpdate matchRequestUpdate ) {
78- // TODO: Handle updating match request
79- MatchRequest updated = new MatchRequest (); // Fill with updated data
80- return ResponseEntity .ok (updated );
165+ public ResponseEntity <MatchRequest > putApiV2MatchingRequestRequestId (UUID requestId , @ Valid MatchRequestUpdate matchRequestUpdate ) {
166+
167+ // 200
168+ try {
169+
170+ // attempt to update match request
171+ MatchRequest request = requestService .updateRequest (requestId , matchRequestUpdate );
172+
173+ // return 200 with MatchRequestCollection if found
174+ return ResponseEntity .ok (request );
175+
176+ // 404
177+ } catch (RequestNotFoundException e ) {
178+
179+ // return 404 if no MatchRequests are found
180+ return ResponseEntity .notFound ().build ();
181+
182+ // 500
183+ } catch (Exception e ) {
184+
185+ // return 500 if another exception occurs
186+ return ResponseEntity .internalServerError ().build ();
187+
188+ }
81189 }
82190
83191}
0 commit comments