Archived
Implementation of post deletion.
This commit is contained in:
@@ -77,4 +77,23 @@ public class PostService {
|
||||
pResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
|
||||
}
|
||||
}
|
||||
|
||||
public void delete(final String pPostKey, final HttpServletRequest pRequest,
|
||||
final HttpServletResponse pResponse) throws IOException {
|
||||
final Optional<Post> postToDelete = postRepository.getByKey(pPostKey);
|
||||
if(postToDelete.isPresent()) {
|
||||
final Optional<User> connectedUser = tokenService.getAuthenticatedUserByToken(pRequest);
|
||||
if(connectedUser.isPresent()) {
|
||||
if(connectedUser.get().getKey().equals(postToDelete.get().getAuthor().getKey())) {
|
||||
postRepository.delete(postToDelete.get());
|
||||
} else {
|
||||
pResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
|
||||
}
|
||||
} else {
|
||||
pResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
}
|
||||
} else {
|
||||
pResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user