Service Layer Documentation
The service layer contains business logic and orchestrates interactions between controllers and repositories.Authentication & User Management
AuthService
Location:es.duit.app.service.AuthService
Purpose: Manages user authentication and retrieval of authenticated users.
Key Methods:
IllegalStateException if user is not authenticated.
AppUserService
Location:es.duit.app.service.AppUserService
Purpose: Handles user profile operations including updates and account deactivation.
Key Methods:
RegistroService
Location:es.duit.app.service.RegistroService
Purpose: Handles new user registration with validation.
Key Methods:
- Email uniqueness
- DNI uniqueness
- Role assignment (USER or PROFESSIONAL)
AccessLogService
Location:es.duit.app.service.AccessLogService
Purpose: Logs successful and failed login attempts.
Key Methods:
Service Request Management
RequestService
Location:es.duit.app.service.RequestService
Purpose: Manages service requests (creation, editing, state changes).
Key Methods:
SearchService
Location:es.duit.app.service.SearchService
Purpose: Handles searching and filtering of published service requests.
Key Methods:
- Text search (title and description)
- Category filter
- Postal code filter
- Excludes requests where user has already applied
Job Application Management
JobApplicationService
Location:es.duit.app.service.JobApplicationService
Purpose: Manages professional applications to service requests.
Key Methods:
- User has professional profile
- User has address configured
- Offer is published
- User is not the offer owner
- User hasn’t applied before
- Price is valid
JobService
Location:es.duit.app.service.JobService
Purpose: Manages job lifecycle and state transitions.
Key Methods:
Rating Management
RatingService
Location:es.duit.app.service.RatingService
Purpose: Manages ratings between clients and professionals for completed jobs.
Key Methods:
- Score between 1 and 5
- User has permission (is client or professional)
- Job is completed
- No existing rating of the same type
CLIENT_TO_PROFESSIONAL: Client rates professionalPROFESSIONAL_TO_CLIENT: Professional rates client
Category Management
CategoryService
Location:es.duit.app.service.CategoryService
Purpose: CRUD operations for service categories.
Key Methods:
History & Reporting
HistoryService
Location:es.duit.app.service.HistoryService
Purpose: Provides job history for users (as client and professional).
Key Methods:
- Jobs where user was the client
- Jobs where user was the professional
- Sorted by start date (most recent first)
- Job details (status, price, dates)
- Request information (title, description, category)
- Application data (proposed price, status)
- Client information
- Professional information
Service Dependencies
Common dependencies used across services:- Repositories: Data access layer (JPA repositories)
- PasswordEncoder: For password hashing (BCrypt)
- Authentication: Spring Security context
- @Transactional: Transaction management
- @RequiredArgsConstructor: Lombok for constructor injection
Error Handling
Services commonly throw:IllegalArgumentException: For validation errorsIllegalStateException: For state-related errorsRuntimeException: For unexpected errors
