syncstream-dev / syncstream-backend

Java + SpringBoot backend for SyncStream Application
GNU General Public License v2.0
2 stars 2 forks source link

Implement UserService with Register and Login Methods #14

Open Xu-Gavin opened 8 months ago

Xu-Gavin commented 8 months ago

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 the UserRepository interface.

Tasks:

  1. Create UserService Class: Create a UserService class in the 'service' folder. This class should have a UserRepository field that is autowired in its constructor.

  2. 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.
  3. 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.
  4. 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: