This commit is contained in:
Guams 2024-12-25 22:18:04 +01:00
parent 9fa9630e5d
commit 559446c64d
2 changed files with 3 additions and 6 deletions

View File

@ -71,9 +71,9 @@ public class AuthorController {
} }
@PutMapping("/{id}/posts") @PutMapping("/{id}/posts")
public void updateUserPosts(@PathVariable("id") UUID authorId, @RequestBody List<Long> postIds, Authentication authentication) { public void updateUserPosts(@PathVariable("id") UUID authorId, @RequestBody Long postId, Authentication authentication) {
Author author = authorService.verifyIfUserIsAuthorized(authentication, authorId); Author author = authorService.verifyIfUserIsAuthorized(authentication, authorId);
authorService.insertPublications(author.getId(), postIds); authorService.insertPublications(author.getId(), postId);
} }
@GetMapping("/{id}/posts") @GetMapping("/{id}/posts")

View File

@ -47,14 +47,11 @@ public class AuthorService implements UserDetailsService
} }
@Transactional @Transactional
public void insertPublications(UUID authorId, List<Long> postIds) { public void insertPublications(UUID authorId, Long postId) {
for (Long postId : postIds) {
authorRepository.deletePublication(authorId, postId);
if (postRepository.findById(postId).isPresent()) { if (postRepository.findById(postId).isPresent()) {
authorRepository.insertPublication(authorId, postId); authorRepository.insertPublication(authorId, postId);
} }
} }
}
public Author verifyIfUserIsAuthorized(Authentication authentication, UUID id) { public Author verifyIfUserIsAuthorized(Authentication authentication, UUID id) {
if (authentication == null || !authentication.isAuthenticated()) { if (authentication == null || !authentication.isAuthenticated()) {