Class AthleteService
java.lang.Object
fr.utc.miage.sporttrack.service.user.AthleteService
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 Summary
ConstructorsConstructorDescriptionAthleteService(AthleteRepository athleteRepository, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder) Constructs a newAthleteServicewith the required dependencies. -
Method Summary
Modifier and TypeMethodDescriptionvoidCreates a new athlete profile from a registration form DTO.Returns all registered athletes.getCurrentAthlete(String email) Retrieves the current athlete's profile by their email address.searchAthletesByName(String query) Searches for athletes whose username contains the given query string, ignoring case.voidupdateProfile(String email, AthleteProfileUpdateDTO updatedData) Updates an athlete's profile with the data provided in the DTO.
-
Constructor Details
-
AthleteService
public AthleteService(AthleteRepository athleteRepository, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder) Constructs a newAthleteServicewith the required dependencies.- Parameters:
athleteRepository- the repository for athlete data accesspasswordEncoder- the encoder for hashing passwords
-
-
Method Details
-
createProfile
Creates a new athlete profile from a registration form DTO. Maps the DTO fields to a newAthleteentity before persisting.- Parameters:
dto- the registration form data containing email, username, and password- Throws:
IllegalArgumentException- if the email is already in use
-
getCurrentAthlete
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
Updates an athlete's profile with the data provided in the DTO. Only the fields present inAthleteProfileUpdateDTOare modified.- Parameters:
email- the email address identifying the athlete to updateupdatedData- the DTO containing the new profile field values
-
getAllAthletes
Returns all registered athletes.- Returns:
- a list of all athletes in the database
-
searchAthletesByName
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
-