implement endpoint to request friendships by friendcode

This commit is contained in:
2026-01-22 14:24:48 +01:00
parent 3a1752573e
commit abb8211e16
3 changed files with 13 additions and 1 deletions
@@ -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);