The goal of this issue is to implement a UserService class that provides methods for user registration and login. This service will interact with our Cassandra database through the UserRepository interface.
Tasks:
Create UserService Class: Create a UserService class in the 'service' folder. This class should have a UserRepository field that is autowired in its constructor.
Implement Register Method: Implement a register(User user) method in UserService. This method should:
Check if a user with the same username already exists in the database.
If the username is not taken, save the new user to the database.
Return the saved user.
Throw an exception if the username is already taken.
Implement Login Method: Implement a login(String username, String password) method in UserService. This method should:
Retrieve the user with the given username from the database.
Check if the provided password matches the user's password.
Return the user if the password matches.
Throw an exception if the password does not match or if the username does not exist.
Write Unit Tests: Write unit tests for the register and login methods using JUnit and Mockito. Make sure to test both the expected behavior and error conditions.
Acceptance Criteria:
The UserService class is implemented with register and login methods.
The register method correctly creates a new user in the database if the username is not taken, and throws an exception if the username is already taken.
The login method correctly retrieves a user from the database and checks the password, throwing an exception if the password does not match or if the username does not exist.
Description:
The goal of this issue is to implement a
UserService
class that provides methods for user registration and login. This service will interact with our Cassandra database through theUserRepository
interface.Tasks:
Create UserService Class: Create a
UserService
class in the 'service' folder. This class should have aUserRepository
field that is autowired in its constructor.Implement Register Method: Implement a
register(User user)
method inUserService
. This method should:Implement Login Method: Implement a
login(String username, String password)
method inUserService
. This method should:Write Unit Tests: Write unit tests for the
register
andlogin
methods using JUnit and Mockito. Make sure to test both the expected behavior and error conditions.Acceptance Criteria:
UserService
class is implemented withregister
andlogin
methods.register
method correctly creates a new user in the database if the username is not taken, and throws an exception if the username is already taken.login
method correctly retrieves a user from the database and checks the password, throwing an exception if the password does not match or if the username does not exist.register
andlogin
methods pass.