mirror of
https://github.com/usatiuk/y.git
synced 2025-10-28 18:37:47 +01:00
update posts
This commit is contained in:
@@ -64,6 +64,15 @@ public class PostController {
|
||||
return PostMapper.makeDto(post.get());
|
||||
}
|
||||
|
||||
@PatchMapping(path = "/{id}")
|
||||
public PostTo update(Principal principal, @PathVariable long id, @RequestBody PostCreateTo postCreateTo) {
|
||||
var post = postService.readById(id).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
|
||||
if (!Objects.equals(post.getAuthor().getUuid(), principal.getName()))
|
||||
throw new ResponseStatusException(HttpStatus.FORBIDDEN);
|
||||
post.setText(postCreateTo.text());
|
||||
postService.update(post);
|
||||
return PostMapper.makeDto(post);
|
||||
}
|
||||
|
||||
@DeleteMapping(path = "/{id}")
|
||||
@ResponseStatus(HttpStatus.NO_CONTENT)
|
||||
|
||||
@@ -12,7 +12,7 @@ public interface CrudService<T extends EntityWithId<ID>, ID extends Serializable
|
||||
|
||||
Iterable<T> readAll();
|
||||
|
||||
void update(ID id, T e);
|
||||
void update(T e);
|
||||
|
||||
void deleteById(ID id);
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ public abstract class CrudServiceImpl<T extends EntityWithId<ID>, ID extends Ser
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(ID id, T e) {
|
||||
|
||||
public void update(T e) {
|
||||
getRepository().save(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user