Couldnt request by friendcode, because it was in controller and therefore not transactional
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
This commit is contained in:
@@ -73,9 +73,7 @@ public class FriendshipController {
|
||||
@PostMapping("/request/by-friendcode/{friendCode}")
|
||||
public ResponseEntity<Void> requestFriendshipByFriendcode(@PathVariable String friendCode) {
|
||||
User user = currentUserService.get();
|
||||
User requestedFriend = userRepository.findByFriendCode(friendCode).orElseThrow();
|
||||
checkSelfAction(user.getId(), requestedFriend.getId());
|
||||
friendshipService.requestFriendship(user, requestedFriend.getId());
|
||||
friendshipService.requestFriendshipByFriendcode(user, friendCode);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,9 @@ import SuMoC.backend.user.repository.UserRepository;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jspecify.annotations.NonNull;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -344,6 +346,17 @@ public class FriendshipService {
|
||||
return friends;
|
||||
}
|
||||
|
||||
public void requestFriendshipByFriendcode(User sender, String friendCode) {
|
||||
User requestedFriend = userRepository.findByFriendCode(friendCode)
|
||||
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "User not found"));
|
||||
|
||||
if (sender.getId().equals(requestedFriend.getId())) {
|
||||
throw new IllegalArgumentException("Action cannot be performed on oneself.");
|
||||
}
|
||||
|
||||
requestFriendship(sender, requestedFriend.getId());
|
||||
}
|
||||
|
||||
public record NameWithFriendship(
|
||||
Long id,
|
||||
String name,
|
||||
|
||||
Reference in New Issue
Block a user