implement endpoint to request friendships by friendcode
This commit is contained in:
@@ -66,6 +66,16 @@ public class FriendshipController {
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Request a friendship with another user by friend code.", description = "Sends a friendship request to another user identified by their friend code from the logged in user.")
|
||||
@PostMapping("/request/by-friendcode/{friendCode}")
|
||||
public ResponseEntity<Void> requestFriendshipByFriendcode(@PathVariable String friendCode) {
|
||||
User user = getAuthenticatedUser();
|
||||
User requestedFriend = userRepository.findByFriendCode(friendCode).orElseThrow();
|
||||
checkSelfAction(user.getId(), requestedFriend.getId());
|
||||
friendshipService.requestFriendship(user, requestedFriend.getId());
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@Operation(summary = "Accept a friendship request.", description = "Accepts a pending friendship request for the logged in user from user with friendId.")
|
||||
@PostMapping("/accept/{friendId}")
|
||||
public ResponseEntity<Void> acceptFriendship(@PathVariable Long friendId) {
|
||||
|
||||
@@ -41,7 +41,7 @@ public class User {
|
||||
@Column(nullable = false)
|
||||
private VisibilityPrivacy visibilityPrivacy;
|
||||
|
||||
@Column(nullable = false)
|
||||
@Column(nullable = false, unique = true)
|
||||
private String friendCode;
|
||||
|
||||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
|
||||
@@ -10,6 +10,8 @@ public interface UserRepository extends JpaRepository<User, Long> {
|
||||
|
||||
Optional<User> findByEmail(String email);
|
||||
|
||||
Optional<User> findByFriendCode(String friendCode);
|
||||
|
||||
boolean existsByPublicName(String username);
|
||||
|
||||
boolean existsByEmail(String email);
|
||||
|
||||
Reference in New Issue
Block a user