Class UserService
java.lang.Object
com.needleandstitch.pavuk.service.UserService
Service layer for managing users.
This class provides business logic for operations related to users, such as retrieving, creating, updating, and deleting users.
Usage:
- Retrieve roles by ID or email
- Create new users
- Update existing users
- Delete users
- Handle user authentication
- Since:
- 15.12.2024
- Version:
- 1.0.0
- Author:
- Needle & Stitch
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateUser
(String firstName, String lastName, LocalDate dateOfBirth, String phone, String email, Boolean newsletterSubscription, String password, Role role) Creates a new user.void
deleteUser
(Long id) Deletes a user by their ID.findAll()
Retrieves all users from the database.findByEmail
(String email) Finds a user by their email address.Finds a user by their ID.signInUser
(String email, String password) Authenticates a user by email and password.void
updateUser
(Long id, String email) Updates the email address of a user.
-
Constructor Details
-
UserService
public UserService()
-
-
Method Details
-
findById
-
findByEmail
-
findAll
-
createUser
@Transactional public User createUser(String firstName, String lastName, LocalDate dateOfBirth, String phone, String email, Boolean newsletterSubscription, String password, Role role) Creates a new user.- Parameters:
firstName
- The first name of the userlastName
- The last name of the userdateOfBirth
- The date of birth of the userphone
- The phone number of the useremail
- The email address of the usernewsletterSubscription
- Whether the user is subscribed to the newsletterpassword
- The password of the userrole
- The role assigned to the user- Returns:
- The newly created user
-
signInUser
Authenticates a user by email and password.- Parameters:
email
- The email address of the userpassword
- The password of the user- Returns:
- The authenticated user
- Throws:
jakarta.persistence.EntityNotFoundException
- if the user with the specified email is not foundIllegalArgumentException
- if the password does not match the stored password
-
updateUser
-
deleteUser
Deletes a user by their ID.- Parameters:
id
- The ID of the user to delete- Throws:
jakarta.persistence.EntityNotFoundException
- if the user with the specified ID does not exist
-