Package restapi.controllers
Class RequestController
java.lang.Object
restapi.controllers.RequestController
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final @NonNull RequestService
private final @NonNull UserService
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<RestResponse>
acceptRequest
(LoggedUser user, String username) Accepts the received friendship request from the user matching the given username, if and only if the friendship request exists and the user is the receiver.org.springframework.http.ResponseEntity<RestResponse>
cancelRequest
(LoggedUser user, String username) Deletes the send friendship request to the user matching the given username, if and only if the friendship request exists and the user is the sender.org.springframework.http.ResponseEntity<RestResponse>
Returns a list of accepted friendship requests and a list of received friendship requests.private org.springframework.http.ResponseEntity<RestResponse>
getRequests
(String username, int option) org.springframework.http.ResponseEntity<RestResponse>
getRequests
(LoggedUser user) Returns a list of sent friendship requests and a list of received friendship requests.org.springframework.http.ResponseEntity<RestResponse>
newRequest
(LoggedUser user, String username) Creates a friendship request between logged user and user matching username.org.springframework.http.ResponseEntity<RestResponse>
rejectRequest
(LoggedUser user, String username) Rejects the received friendship request from the user matching the given username, if and only if the friendship request exists and the user is the receiver endpoint /requests/reject
-
Field Details
-
requestService
-
userService
-
-
Constructor Details
-
RequestController
public RequestController()
-
-
Method Details
-
getRequests
private org.springframework.http.ResponseEntity<RestResponse> getRequests(String username, int option) - Parameters:
username
-option
-- Returns:
-
getRequests
@GetMapping("/mine") public org.springframework.http.ResponseEntity<RestResponse> getRequests(@AuthenticationPrincipal LoggedUser user) Returns a list of sent friendship requests and a list of received friendship requests. The requests that have been rejected by the other user are currently included in the sent list. endpoint /requests/mine- Parameters:
user
- Authenticated LoggedUser from token- Returns:
- List of friendship request in form of Request DTO
-
getAcceptedRequests
@GetMapping("/accepted") public org.springframework.http.ResponseEntity<RestResponse> getAcceptedRequests(@AuthenticationPrincipal LoggedUser user) Returns a list of accepted friendship requests and a list of received friendship requests. The requests that have been rejected by the other user are currently included in the sent list, but the rejected received requests are not returned. endpoint /requests/accepted- Parameters:
user
- Authenticated LoggedUser from token- Returns:
- List of friendship request in form of Request DTO
-
newRequest
@PostMapping("/new") public org.springframework.http.ResponseEntity<RestResponse> newRequest(@AuthenticationPrincipal LoggedUser user, @RequestParam String username) Creates a friendship request between logged user and user matching username. endpoint /requests/new- Parameters:
user
- Authenticated LoggedUser from tokenusername
- Username of the user we want to send the friendship request to- Returns:
- Rest Message OK or Error 404, 409 or 500
-
acceptRequest
@PutMapping("/accept") public org.springframework.http.ResponseEntity<RestResponse> acceptRequest(@AuthenticationPrincipal LoggedUser user, @RequestParam String username) Accepts the received friendship request from the user matching the given username, if and only if the friendship request exists and the user is the receiver. Then Creates the Contact relation between both users. endpoint /requests/accept- Parameters:
user
- Authenticated LoggedUser from tokenusername
- Username of the user who send the friendship request we want to accept- Returns:
- Rest Message OK or Error 404, 409 or 500
-
rejectRequest
@PutMapping("/reject") public org.springframework.http.ResponseEntity<RestResponse> rejectRequest(@AuthenticationPrincipal LoggedUser user, @RequestParam String username) Rejects the received friendship request from the user matching the given username, if and only if the friendship request exists and the user is the receiver endpoint /requests/reject- Parameters:
user
- Authenticated LoggedUser from tokenusername
- Username of the user who send the friendship request we want to reject- Returns:
- Rest Message OK or Error 404, 409 or 500
-
cancelRequest
@DeleteMapping("/cancel") public org.springframework.http.ResponseEntity<RestResponse> cancelRequest(@AuthenticationPrincipal LoggedUser user, @RequestParam String username) Deletes the send friendship request to the user matching the given username, if and only if the friendship request exists and the user is the sender. endpoint /requests/cancel- Parameters:
user
- Authenticated LoggedUser from tokenusername
- Username of the user who the friendship request we want to reject was sent to- Returns:
- Rest Message OK or Error 404, 409 or 500
-