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")
|
@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")
|
||||||
|
@ -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()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user