7import lombok.RequiredArgsConstructor;
8import org.springframework.stereotype.Service;
9
10@Service11@RequiredArgsConstructor12public class AdminService {13 private final UserRepository userRepository;14 private final PostRepository postRepository;15 public final CommentRepository commentRepository;1617 /**18 * Deletes a user and all of its posts and comments.19 *20 * @param id the UUID of the user to be deleted21 */22 public void recursiveUserDelete(UUID id) {23 userRepository24 .findById(id)25 .ifPresent(26 user -> {27 postRepository28 .findAllByUser(user)29 .forEach(30 post -> {31 commentRepository.deleteAll(commentRepository.findAllByPost(post));32 postRepository.delete(post);33 });34 commentRepository.deleteAll(commentRepository.findAllByUser(user));35 userRepository.delete(user);36 });37 }3839 /**40 * Deletes a post and all of its comments.41 *42 * @param id the UUID of the post to be deleted43 */44 public void recursivePostDelete(UUID id) {45 postRepository46 .findById(id)47 .ifPresent(48 post -> {49 commentRepository.deleteAll(commentRepository.findAllByPost(post));50 postRepository.delete(post);51 });52 }5354 /**55 * Deletes a comment.56 *57 * @param id the UUID of the comment to be deleted58 */59 public void deleteComment(UUID id) {60 commentRepository.deleteById(id);61 }62}
This class does not have any documentation.
Consider adding a documentation comment to explain its use.
While it may seem like the functionality of a class is perfectly obvious, any consumers of your API may not be able to pick up on certain details.
Consider a case where the class given below can be instantiated and provides certain functionalities within each instance in a thread-safe manner, perhaps it is a rest API client.
If there is no documentation comment on the class, it is not immediately obvious that the class is thread safe. Thus, multiple instances of the class may be created to perform operations concurrently, using up both memory as well as OS resources like sockets. If it were known from the beginning that the class were thread safe, the user would not need to create unnecessary extra instances of SomeClass
.
class SomeClass {
// ...
}
Make sure to add useful information regarding the usage or implementation of a particular declaration, so that anything about it which can't be understood from the name or some other cue is correctly conveyed.
/**
* Instances of this class are used to perform xyz action.
*
* This class is thread safe and the same instance can be used over multiple threads.
*/
class SomeClass {
// ...
}
This issue will not be reported for model entity classes. If there is any non-obvious behavior associated with a particular class however, do consider documenting it.