Skip to content

Commit

Permalink
Add a javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Pan14ek committed Mar 19, 2024
1 parent bbb3210 commit d898ce1
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/main/java/ua/nure/englishcards/api/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@
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")
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<UserModel> addNewUser(NewUserModel newUserModel) {
UserModel userModel = userService.addNewUser(newUserModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<User, UUID> {
}
10 changes: 10 additions & 0 deletions src/main/java/ua/nure/englishcards/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@
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 {

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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit d898ce1

Please sign in to comment.