Class AthleteService

java.lang.Object
fr.utc.miage.sporttrack.service.user.AthleteService

@Service public class AthleteService extends Object
Service layer component responsible for managing Athlete entities within the SportTrack application.

Provides business logic for athlete registration, profile retrieval, profile updates, and athlete search functionality. Password hashing is performed during registration using the injected PasswordEncoder.

Author:
SportTrack Team
  • Constructor Details

    • AthleteService

      public AthleteService(AthleteRepository athleteRepository, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder)
      Constructs a new AthleteService with the required dependencies.
      Parameters:
      athleteRepository - the repository for athlete data access
      passwordEncoder - the encoder for hashing passwords
  • Method Details

    • createProfile

      public void createProfile(AthleteRegisterFormDTO dto)
      Creates a new athlete profile from a registration form DTO. Maps the DTO fields to a new Athlete entity before persisting.
      Parameters:
      dto - the registration form data containing email, username, and password
      Throws:
      IllegalArgumentException - if the email is already in use
    • getCurrentAthlete

      public Athlete getCurrentAthlete(String email)
      Retrieves the current athlete's profile by their email address.
      Parameters:
      email - the email address used as login identifier
      Returns:
      the matching Athlete
      Throws:
      IllegalArgumentException - if no athlete is found with the given email
    • updateProfile

      public void updateProfile(String email, AthleteProfileUpdateDTO updatedData)
      Updates an athlete's profile with the data provided in the DTO. Only the fields present in AthleteProfileUpdateDTO are modified.
      Parameters:
      email - the email address identifying the athlete to update
      updatedData - the DTO containing the new profile field values
    • getAllAthletes

      public List<Athlete> getAllAthletes()
      Returns all registered athletes.
      Returns:
      a list of all athletes in the database
    • searchAthletesByName

      public List<Athlete> searchAthletesByName(String query)
      Searches for athletes whose username contains the given query string, ignoring case.
      Parameters:
      query - the search keyword to match against usernames
      Returns:
      a list of athletes whose usernames contain the query string