update de la route "http://url:8080/api/authors/{id}/posts"
This commit is contained in:
parent
9fa9630e5d
commit
559446c64d
@ -71,9 +71,9 @@ public class AuthorController {
|
||||
}
|
||||
|
||||
@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);
|
||||
authorService.insertPublications(author.getId(), postIds);
|
||||
authorService.insertPublications(author.getId(), postId);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/posts")
|
||||
|
@ -47,12 +47,9 @@ public class AuthorService implements UserDetailsService
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void insertPublications(UUID authorId, List<Long> postIds) {
|
||||
for (Long postId : postIds) {
|
||||
authorRepository.deletePublication(authorId, postId);
|
||||
public void insertPublications(UUID authorId, Long postId) {
|
||||
if (postRepository.findById(postId).isPresent()) {
|
||||
authorRepository.insertPublication(authorId, postId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user