diff --git a/src/main/java/ua/nure/englishcards/api/UserController.java b/src/main/java/ua/nure/englishcards/api/UserController.java index d5f22a4..2b5a931 100644 --- a/src/main/java/ua/nure/englishcards/api/UserController.java +++ b/src/main/java/ua/nure/englishcards/api/UserController.java @@ -9,6 +9,9 @@ import ua.nure.englishcards.service.model.NewUserModel; import ua.nure.englishcards.service.model.UserModel; +/** + * This class is responsible for the CRUD operation on the {@code User} model. + */ @RequiredArgsConstructor @RestController @RequestMapping("/users") @@ -16,6 +19,12 @@ public class UserController { private final UserService userService; + /** + * Saves a new user to the english card system. + * + * @param newUserModel is a new user + * @return saved user + */ @PostMapping public ResponseEntity addNewUser(NewUserModel newUserModel) { UserModel userModel = userService.addNewUser(newUserModel); diff --git a/src/main/java/ua/nure/englishcards/persistence/entity/EntityWithUUID.java b/src/main/java/ua/nure/englishcards/persistence/entity/EntityWithUuid.java similarity index 69% rename from src/main/java/ua/nure/englishcards/persistence/entity/EntityWithUUID.java rename to src/main/java/ua/nure/englishcards/persistence/entity/EntityWithUuid.java index 5699ec4..91227d0 100644 --- a/src/main/java/ua/nure/englishcards/persistence/entity/EntityWithUUID.java +++ b/src/main/java/ua/nure/englishcards/persistence/entity/EntityWithUuid.java @@ -5,14 +5,17 @@ import java.util.UUID; import lombok.Data; +/** + * This entity represents a super class with uuid. + */ @Data @MappedSuperclass -public class EntityWithUUID { +public class EntityWithUuid { @Id private UUID id; - public EntityWithUUID() { + public EntityWithUuid() { this.id = UUID.randomUUID(); } diff --git a/src/main/java/ua/nure/englishcards/persistence/entity/User.java b/src/main/java/ua/nure/englishcards/persistence/entity/User.java index 4cf3715..558a96f 100644 --- a/src/main/java/ua/nure/englishcards/persistence/entity/User.java +++ b/src/main/java/ua/nure/englishcards/persistence/entity/User.java @@ -8,13 +8,17 @@ import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +/** + * The entity represents the table users in DB + * that contains fields id, email, nickname and password. + */ @EqualsAndHashCode(callSuper = true) @Entity @Data @AllArgsConstructor @NoArgsConstructor @Table(name = "users") -public class User extends EntityWithUUID { +public class User extends EntityWithUuid { @Column(name = "email", nullable = false) private String email; diff --git a/src/main/java/ua/nure/englishcards/persistence/repository/UserRepository.java b/src/main/java/ua/nure/englishcards/persistence/repository/UserRepository.java index 1077283..36b947c 100644 --- a/src/main/java/ua/nure/englishcards/persistence/repository/UserRepository.java +++ b/src/main/java/ua/nure/englishcards/persistence/repository/UserRepository.java @@ -4,5 +4,8 @@ import org.springframework.data.jpa.repository.JpaRepository; import ua.nure.englishcards.persistence.entity.User; +/** + * The class represents the repository for the {@code User} entity that has the CRUD operation. + */ public interface UserRepository extends JpaRepository { } diff --git a/src/main/java/ua/nure/englishcards/service/UserService.java b/src/main/java/ua/nure/englishcards/service/UserService.java index 789e4dd..fa20267 100644 --- a/src/main/java/ua/nure/englishcards/service/UserService.java +++ b/src/main/java/ua/nure/englishcards/service/UserService.java @@ -9,6 +9,10 @@ import ua.nure.englishcards.service.model.NewUserModel; import ua.nure.englishcards.service.model.UserModel; +/** + * This service is responsible for handling user actions. + * It can be adding, updating, deleting, receiving users. + */ @Service @RequiredArgsConstructor public class UserService { @@ -16,6 +20,12 @@ public class UserService { private final UserRepository userRepository; private final PasswordEncoder passwordEncoder; + /** + * Adds a new user to the DB. + * + * @param user is a new user with the model {@code NewUserModel}. + * @return saved user in DB with the model {@code UserModel} + */ @Transactional public UserModel addNewUser(NewUserModel user) { User newUser = new User(); diff --git a/src/main/java/ua/nure/englishcards/service/model/NewUserModel.java b/src/main/java/ua/nure/englishcards/service/model/NewUserModel.java index 9123f76..c3066ed 100644 --- a/src/main/java/ua/nure/englishcards/service/model/NewUserModel.java +++ b/src/main/java/ua/nure/englishcards/service/model/NewUserModel.java @@ -4,6 +4,13 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; +/** + * This record contains fields email, nickname and password that are required for a new user. + * + * @param email is user email + * @param nickname is a nickname that should be more or equals 5 length and less than 32 length + * @param password is a user password + */ public record NewUserModel( @NotBlank @Email diff --git a/src/main/java/ua/nure/englishcards/service/model/UserModel.java b/src/main/java/ua/nure/englishcards/service/model/UserModel.java index 5bcd31c..6e8513e 100644 --- a/src/main/java/ua/nure/englishcards/service/model/UserModel.java +++ b/src/main/java/ua/nure/englishcards/service/model/UserModel.java @@ -2,5 +2,12 @@ import java.util.UUID; +/** + * This record contains fields that are required for registered user. + * + * @param id is a user id + * @param email is a email id + * @param nickname is a user nickname + */ public record UserModel(UUID id, String email, String nickname) { } diff --git a/src/main/java/ua/nure/englishcards/service/util/PasswordConfig.java b/src/main/java/ua/nure/englishcards/service/util/PasswordConfig.java index 23a6b1b..136df97 100644 --- a/src/main/java/ua/nure/englishcards/service/util/PasswordConfig.java +++ b/src/main/java/ua/nure/englishcards/service/util/PasswordConfig.java @@ -5,9 +5,17 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; +/** + * This class contains configuration methods that receive beans. + */ @Configuration public class PasswordConfig { + /** + * Receives the PasswordEncoder object. + * + * @return the password encoder + */ @Bean public PasswordEncoder encoder() { return new BCryptPasswordEncoder();