Added and revised javadoc
This commit is contained in:
parent
c59d9cb1be
commit
ea38bf0f0b
|
|
@ -45,13 +45,3 @@ services:
|
||||||
- backend
|
- backend
|
||||||
ports:
|
ports:
|
||||||
- "3000:80"
|
- "3000:80"
|
||||||
|
|
||||||
db-restore:
|
|
||||||
image: mysql:8.0
|
|
||||||
depends_on:
|
|
||||||
mysql:
|
|
||||||
condition: service_healthy
|
|
||||||
volumes:
|
|
||||||
- ./backup.sql:/backup.sql
|
|
||||||
- ./docker/initdb.sh:/docker-entrypoint-initdb.d/initdb.sh
|
|
||||||
entrypoint: ["/bin/bash", "/docker-entrypoint-initdb.d/initdb.sh"]
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -3,6 +3,9 @@ package com.denniseckerskorn;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main application class for the MemberFlow application.
|
||||||
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class MemberFlowApplication {
|
public class MemberFlowApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
||||||
|
|
@ -14,27 +14,53 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Security configuration class for the application.
|
||||||
|
*/
|
||||||
@EnableMethodSecurity
|
@EnableMethodSecurity
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SecurityConfig {
|
public class SecurityConfig {
|
||||||
private final JwtAuthFilter jwtAuthFilter;
|
private final JwtAuthFilter jwtAuthFilter;
|
||||||
private final CustomUserDetailsService customUserDetailsService;
|
private final CustomUserDetailsService customUserDetailsService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for SecurityConfig.
|
||||||
|
*
|
||||||
|
* @param jwtAuthFilter the JWT authentication filter
|
||||||
|
* @param customUserDetailsService the custom user details service
|
||||||
|
*/
|
||||||
public SecurityConfig(JwtAuthFilter jwtAuthFilter, CustomUserDetailsService customUserDetailsService) {
|
public SecurityConfig(JwtAuthFilter jwtAuthFilter, CustomUserDetailsService customUserDetailsService) {
|
||||||
this.jwtAuthFilter = jwtAuthFilter;
|
this.jwtAuthFilter = jwtAuthFilter;
|
||||||
this.customUserDetailsService = customUserDetailsService;
|
this.customUserDetailsService = customUserDetailsService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bean for PasswordEncoder.
|
||||||
|
*
|
||||||
|
* @return a BCryptPasswordEncoder instance
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public PasswordEncoder passwordEncoder() {
|
public PasswordEncoder passwordEncoder() {
|
||||||
return new BCryptPasswordEncoder();
|
return new BCryptPasswordEncoder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bean for CustomUserDetailsService.
|
||||||
|
*
|
||||||
|
* @return the custom user details service
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception {
|
public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception {
|
||||||
return config.getAuthenticationManager();
|
return config.getAuthenticationManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bean for SecurityFilterChain.
|
||||||
|
*
|
||||||
|
* @param http the HttpSecurity object
|
||||||
|
* @return a SecurityFilterChain instance
|
||||||
|
* @throws Exception if an error occurs during configuration
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||||
return http
|
return http
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,18 @@ import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swagger configuration class for the MemberFlow API.
|
||||||
|
* This class sets up the OpenAPI documentation for the API, including security schemes and metadata.
|
||||||
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SwaggerConfig {
|
public class SwaggerConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configures the OpenAPI documentation for the MemberFlow API.
|
||||||
|
*
|
||||||
|
* @return an OpenAPI instance with the API information and security scheme.
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public OpenAPI customOpenAPI() {
|
public OpenAPI customOpenAPI() {
|
||||||
final String securitySchemeName = "bearerAuth";
|
final String securitySchemeName = "bearerAuth";
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,10 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Web configuration class for setting up CORS mappings.
|
||||||
|
* This class allows cross-origin requests from specified origins.
|
||||||
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class WebConfig implements WebMvcConfigurer {
|
public class WebConfig implements WebMvcConfigurer {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,10 @@ import org.springframework.security.authentication.UsernamePasswordAuthenticatio
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AuthController handles user authentication requests.
|
||||||
|
* It provides an endpoint for user login, which returns a JWT token upon successful authentication.
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/auth")
|
@RequestMapping("/api/v1/auth")
|
||||||
@Tag(name = "Authentication", description = "Operations related to user authentication")
|
@Tag(name = "Authentication", description = "Operations related to user authentication")
|
||||||
|
|
@ -23,12 +27,25 @@ public class AuthController {
|
||||||
private final JwtUtil jwtUtil;
|
private final JwtUtil jwtUtil;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for AuthController.
|
||||||
|
*
|
||||||
|
* @param authenticationManager Authentication manager for handling authentication requests.
|
||||||
|
* @param jwtUtil Utility class for generating JWT tokens.
|
||||||
|
* @param userService Service for handling user-related operations.
|
||||||
|
*/
|
||||||
public AuthController(AuthenticationManager authenticationManager, JwtUtil jwtUtil, UserService userService) {
|
public AuthController(AuthenticationManager authenticationManager, JwtUtil jwtUtil, UserService userService) {
|
||||||
this.authenticationManager = authenticationManager;
|
this.authenticationManager = authenticationManager;
|
||||||
this.jwtUtil = jwtUtil;
|
this.jwtUtil = jwtUtil;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API response codes for the login endpoint.
|
||||||
|
*
|
||||||
|
* @param loginRequest The login request containing user credentials.
|
||||||
|
* @return ResponseEntity containing the JWT token or an error message.
|
||||||
|
*/
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(responseCode = "200", description = "Successful login"),
|
@ApiResponse(responseCode = "200", description = "Successful login"),
|
||||||
@ApiResponse(responseCode = "401", description = "Unauthorized"),
|
@ApiResponse(responseCode = "401", description = "Unauthorized"),
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,10 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AssistanceController handles requests related to assistance management.
|
||||||
|
* It provides endpoints for creating, updating, retrieving, and deleting assistance records.
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/assistances")
|
@RequestMapping("/api/v1/assistances")
|
||||||
@Tag(name = "Assistance Management", description = "Operations related to assistance management")
|
@Tag(name = "Assistance Management", description = "Operations related to assistance management")
|
||||||
|
|
@ -26,6 +30,13 @@ public class AssistanceController {
|
||||||
private final StudentService studentService;
|
private final StudentService studentService;
|
||||||
private final TrainingSessionService trainingSessionService;
|
private final TrainingSessionService trainingSessionService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for AssistanceController.
|
||||||
|
*
|
||||||
|
* @param assistanceService Service for handling assistance records.
|
||||||
|
* @param studentService Service for handling student records.
|
||||||
|
* @param trainingSessionService Service for handling training session records.
|
||||||
|
*/
|
||||||
public AssistanceController(
|
public AssistanceController(
|
||||||
AssistanceService assistanceService,
|
AssistanceService assistanceService,
|
||||||
StudentService studentService,
|
StudentService studentService,
|
||||||
|
|
@ -36,6 +47,12 @@ public class AssistanceController {
|
||||||
this.trainingSessionService = trainingSessionService;
|
this.trainingSessionService = trainingSessionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new assistance record.
|
||||||
|
*
|
||||||
|
* @param dto The AssistanceDTO containing the details of the assistance to be created.
|
||||||
|
* @return ResponseEntity containing the created AssistanceDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Create a new assistance record")
|
@Operation(summary = "Create a new assistance record")
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public ResponseEntity<AssistanceDTO> create(@RequestBody AssistanceDTO dto) {
|
public ResponseEntity<AssistanceDTO> create(@RequestBody AssistanceDTO dto) {
|
||||||
|
|
@ -52,7 +69,12 @@ public class AssistanceController {
|
||||||
return ResponseEntity.ok(AssistanceDTO.fromEntity(saved));
|
return ResponseEntity.ok(AssistanceDTO.fromEntity(saved));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing assistance record.
|
||||||
|
*
|
||||||
|
* @param dto The AssistanceDTO containing the updated details of the assistance.
|
||||||
|
* @return ResponseEntity containing the updated AssistanceDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Update an existing assistance record", description = "Update an existing assistance record")
|
@Operation(summary = "Update an existing assistance record", description = "Update an existing assistance record")
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
public ResponseEntity<AssistanceDTO> update(@RequestBody AssistanceDTO dto) {
|
public ResponseEntity<AssistanceDTO> update(@RequestBody AssistanceDTO dto) {
|
||||||
|
|
@ -64,6 +86,11 @@ public class AssistanceController {
|
||||||
return ResponseEntity.ok(AssistanceDTO.fromEntity(updated));
|
return ResponseEntity.ok(AssistanceDTO.fromEntity(updated));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all assistance records.
|
||||||
|
*
|
||||||
|
* @return ResponseEntity containing a list of AssistanceDTOs.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get all assistance records", description = "Retrieve a list of all assistance records")
|
@Operation(summary = "Get all assistance records", description = "Retrieve a list of all assistance records")
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
public ResponseEntity<List<AssistanceDTO>> getAll() {
|
public ResponseEntity<List<AssistanceDTO>> getAll() {
|
||||||
|
|
@ -74,6 +101,12 @@ public class AssistanceController {
|
||||||
return ResponseEntity.ok(list);
|
return ResponseEntity.ok(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves assistance records by student ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the student whose assistance records are to be retrieved.
|
||||||
|
* @return ResponseEntity containing a list of AssistanceDTOs for the specified student.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get assistance records by student ID", description = "Retrieve assistance records for a specific student")
|
@Operation(summary = "Get assistance records by student ID", description = "Retrieve assistance records for a specific student")
|
||||||
@GetMapping("/getById/{id}")
|
@GetMapping("/getById/{id}")
|
||||||
public ResponseEntity<AssistanceDTO> getAssistanceById(@PathVariable Integer id) {
|
public ResponseEntity<AssistanceDTO> getAssistanceById(@PathVariable Integer id) {
|
||||||
|
|
@ -81,6 +114,12 @@ public class AssistanceController {
|
||||||
return ResponseEntity.ok(AssistanceDTO.fromEntity(assistance));
|
return ResponseEntity.ok(AssistanceDTO.fromEntity(assistance));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an assistance record by ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the assistance record to be deleted.
|
||||||
|
* @return ResponseEntity indicating the result of the deletion operation.
|
||||||
|
*/
|
||||||
@Operation(summary = "Delete an assistance record by ID")
|
@Operation(summary = "Delete an assistance record by ID")
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
public ResponseEntity<Void> delete(@PathVariable Integer id) {
|
public ResponseEntity<Void> delete(@PathVariable Integer id) {
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,21 @@ public class MembershipController {
|
||||||
|
|
||||||
private final MembershipService membershipService;
|
private final MembershipService membershipService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for MembershipController.
|
||||||
|
*
|
||||||
|
* @param membershipService Service for handling membership records.
|
||||||
|
*/
|
||||||
public MembershipController(MembershipService membershipService) {
|
public MembershipController(MembershipService membershipService) {
|
||||||
this.membershipService = membershipService;
|
this.membershipService = membershipService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new membership.
|
||||||
|
*
|
||||||
|
* @param membershipDTO The MembershipDTO containing the details of the membership to be created.
|
||||||
|
* @return ResponseEntity containing the created MembershipDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Create a new membership")
|
@Operation(summary = "Create a new membership")
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public ResponseEntity<MembershipDTO> createMembership(@RequestBody MembershipDTO membershipDTO) {
|
public ResponseEntity<MembershipDTO> createMembership(@RequestBody MembershipDTO membershipDTO) {
|
||||||
|
|
@ -36,6 +47,11 @@ public class MembershipController {
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(MembershipDTO.fromEntity(savedMembership));
|
return ResponseEntity.status(HttpStatus.CREATED).body(MembershipDTO.fromEntity(savedMembership));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all memberships.
|
||||||
|
*
|
||||||
|
* @return ResponseEntity containing a list of MembershipDTOs.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get all memberships", description = "Retrieve a list of all memberships")
|
@Operation(summary = "Get all memberships", description = "Retrieve a list of all memberships")
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
public ResponseEntity<List<MembershipDTO>> getAllMemberships() {
|
public ResponseEntity<List<MembershipDTO>> getAllMemberships() {
|
||||||
|
|
@ -49,6 +65,12 @@ public class MembershipController {
|
||||||
return ResponseEntity.ok(dtos);
|
return ResponseEntity.ok(dtos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a membership by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the membership to retrieve.
|
||||||
|
* @return ResponseEntity containing the MembershipDTO if found, or 404 Not Found if not found.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get a membership by ID", description = "Retrieve a membership by its ID")
|
@Operation(summary = "Get a membership by ID", description = "Retrieve a membership by its ID")
|
||||||
@GetMapping("/getById/{id}")
|
@GetMapping("/getById/{id}")
|
||||||
public ResponseEntity<MembershipDTO> getMembershipById(@PathVariable Integer id) {
|
public ResponseEntity<MembershipDTO> getMembershipById(@PathVariable Integer id) {
|
||||||
|
|
@ -56,6 +78,13 @@ public class MembershipController {
|
||||||
return ResponseEntity.ok(MembershipDTO.fromEntity(membership));
|
return ResponseEntity.ok(MembershipDTO.fromEntity(membership));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing membership.
|
||||||
|
*
|
||||||
|
* @param id The ID of the membership to update.
|
||||||
|
* @param dto The MembershipDTO containing the updated details of the membership.
|
||||||
|
* @return ResponseEntity containing the updated MembershipDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Update a membership", description = "Update an existing membership")
|
@Operation(summary = "Update a membership", description = "Update an existing membership")
|
||||||
@Transactional
|
@Transactional
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
|
|
@ -65,6 +94,12 @@ public class MembershipController {
|
||||||
return ResponseEntity.ok(MembershipDTO.fromEntity(updated));
|
return ResponseEntity.ok(MembershipDTO.fromEntity(updated));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a membership by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the membership to delete.
|
||||||
|
* @return ResponseEntity indicating the result of the deletion operation.
|
||||||
|
*/
|
||||||
@Operation(summary = "Delete a membership", description = "Delete a membership by its ID")
|
@Operation(summary = "Delete a membership", description = "Delete a membership by its ID")
|
||||||
@Transactional
|
@Transactional
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ import java.util.stream.Collectors;
|
||||||
* Controller for managing training groups.
|
* Controller for managing training groups.
|
||||||
* Provides endpoints for creating, updating, retrieving, and deleting training groups.
|
* Provides endpoints for creating, updating, retrieving, and deleting training groups.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/training-groups")
|
@RequestMapping("/api/v1/training-groups")
|
||||||
@Tag(name = "Training Group Management", description = "Operations related to training group management")
|
@Tag(name = "Training Group Management", description = "Operations related to training group management")
|
||||||
|
|
@ -40,7 +39,14 @@ public class TrainingGroupController {
|
||||||
private final StudentService studentService;
|
private final StudentService studentService;
|
||||||
private final TrainingSessionService trainingSessionService;
|
private final TrainingSessionService trainingSessionService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for TrainingGroupController.
|
||||||
|
*
|
||||||
|
* @param trainingGroupService Service for handling training group records.
|
||||||
|
* @param teacherService Service for handling teacher records.
|
||||||
|
* @param studentService Service for handling student records.
|
||||||
|
* @param trainingSessionService Service for handling training session records.
|
||||||
|
*/
|
||||||
public TrainingGroupController(TrainingGroupService trainingGroupService, TeacherService teacherService, StudentService studentService, TrainingSessionService trainingSessionService) {
|
public TrainingGroupController(TrainingGroupService trainingGroupService, TeacherService teacherService, StudentService studentService, TrainingSessionService trainingSessionService) {
|
||||||
this.trainingGroupService = trainingGroupService;
|
this.trainingGroupService = trainingGroupService;
|
||||||
this.teacherService = teacherService;
|
this.teacherService = teacherService;
|
||||||
|
|
@ -48,6 +54,12 @@ public class TrainingGroupController {
|
||||||
this.trainingSessionService = trainingSessionService;
|
this.trainingSessionService = trainingSessionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new training group with a teacher.
|
||||||
|
*
|
||||||
|
* @param dto The TrainingGroupDTO containing the details of the group to be created.
|
||||||
|
* @return ResponseEntity containing the created TrainingGroupDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Create a training group with a teacher")
|
@Operation(summary = "Create a training group with a teacher")
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public ResponseEntity<TrainingGroupDTO> createGroup(@RequestBody TrainingGroupDTO dto) {
|
public ResponseEntity<TrainingGroupDTO> createGroup(@RequestBody TrainingGroupDTO dto) {
|
||||||
|
|
@ -68,7 +80,13 @@ public class TrainingGroupController {
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(new TrainingGroupDTO(createdGroup));
|
return ResponseEntity.status(HttpStatus.CREATED).body(new TrainingGroupDTO(createdGroup));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assigns a student to a training group.
|
||||||
|
*
|
||||||
|
* @param groupId The ID of the training group.
|
||||||
|
* @param studentId The ID of the student to be assigned.
|
||||||
|
* @return ResponseEntity indicating the result of the operation.
|
||||||
|
*/
|
||||||
@Operation(summary = "Assign a student to a group")
|
@Operation(summary = "Assign a student to a group")
|
||||||
@PutMapping("/assign-student")
|
@PutMapping("/assign-student")
|
||||||
public ResponseEntity<Void> assignStudent(@RequestParam Integer groupId, @RequestParam Integer studentId) {
|
public ResponseEntity<Void> assignStudent(@RequestParam Integer groupId, @RequestParam Integer studentId) {
|
||||||
|
|
@ -79,6 +97,13 @@ public class TrainingGroupController {
|
||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a student from a training group.
|
||||||
|
*
|
||||||
|
* @param groupId The ID of the training group.
|
||||||
|
* @param studentId The ID of the student to be removed.
|
||||||
|
* @return ResponseEntity indicating the result of the operation.
|
||||||
|
*/
|
||||||
@Operation(summary = "Remove a student from a group")
|
@Operation(summary = "Remove a student from a group")
|
||||||
@PutMapping("/remove-student")
|
@PutMapping("/remove-student")
|
||||||
public ResponseEntity<Void> removeStudent(@RequestParam Integer groupId, @RequestParam Integer studentId) {
|
public ResponseEntity<Void> removeStudent(@RequestParam Integer groupId, @RequestParam Integer studentId) {
|
||||||
|
|
@ -89,7 +114,14 @@ public class TrainingGroupController {
|
||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "Actualizar un grupo de entrenamiento existente", description = "Actualiza un grupo de entrenamiento por su ID")
|
/**
|
||||||
|
* Updates an existing training group.
|
||||||
|
*
|
||||||
|
* @param id The ID of the training group to update.
|
||||||
|
* @param dto The TrainingGroupDTO containing the updated details of the group.
|
||||||
|
* @return ResponseEntity containing the updated TrainingGroupDTO.
|
||||||
|
*/
|
||||||
|
@Operation(summary = "Updates a training-group by its ID", description = "Update a training group with the specified ID")
|
||||||
@Transactional
|
@Transactional
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
public ResponseEntity<TrainingGroupDTO> update(@PathVariable Integer id, @RequestBody TrainingGroupDTO dto) {
|
public ResponseEntity<TrainingGroupDTO> update(@PathVariable Integer id, @RequestBody TrainingGroupDTO dto) {
|
||||||
|
|
@ -113,13 +145,23 @@ public class TrainingGroupController {
|
||||||
return ResponseEntity.ok(new TrainingGroupDTO(updatedGroup));
|
return ResponseEntity.ok(new TrainingGroupDTO(updatedGroup));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a training group by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the training group to retrieve.
|
||||||
|
* @return ResponseEntity containing the TrainingGroupDTO if found, or 404 Not Found if not found.
|
||||||
|
*/
|
||||||
@Operation(summary = "Find a training group by ID", description = "Retrieve a training group with the specified ID")
|
@Operation(summary = "Find a training group by ID", description = "Retrieve a training group with the specified ID")
|
||||||
@GetMapping("findById/{id}")
|
@GetMapping("findById/{id}")
|
||||||
public ResponseEntity<TrainingGroupDTO> findGroupById(@PathVariable Integer id) {
|
public ResponseEntity<TrainingGroupDTO> findGroupById(@PathVariable Integer id) {
|
||||||
return ResponseEntity.ok(new TrainingGroupDTO(trainingGroupService.findById(id)));
|
return ResponseEntity.ok(new TrainingGroupDTO(trainingGroupService.findById(id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all training groups.
|
||||||
|
*
|
||||||
|
* @return ResponseEntity containing a list of TrainingGroupDTOs.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get all training groups", description = "Retrieve a list of all training groups")
|
@Operation(summary = "Get all training groups", description = "Retrieve a list of all training groups")
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
public ResponseEntity<List<TrainingGroupDTO>> getAll() {
|
public ResponseEntity<List<TrainingGroupDTO>> getAll() {
|
||||||
|
|
@ -130,13 +172,19 @@ public class TrainingGroupController {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a training group by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the training group to delete.
|
||||||
|
* @return ResponseEntity indicating the result of the deletion.
|
||||||
|
*/
|
||||||
@Operation(summary = "Delete a training group by ID", description = "Delete a training group with the specified ID")
|
@Operation(summary = "Delete a training group by ID", description = "Delete a training group with the specified ID")
|
||||||
@Transactional
|
@Transactional
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
public ResponseEntity<Void> delete(@PathVariable Integer id) {
|
public ResponseEntity<Void> delete(@PathVariable Integer id) {
|
||||||
TrainingGroup group = trainingGroupService.findById(id);
|
TrainingGroup group = trainingGroupService.findById(id);
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
throw new EntityNotFoundException("Group not found");
|
throw new EntityNotFoundException("Training group not found with ID: " + id);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (TrainingSession session : group.getTrainingSessions()) {
|
for (TrainingSession session : group.getTrainingSessions()) {
|
||||||
|
|
@ -162,6 +210,12 @@ public class TrainingGroupController {
|
||||||
return ResponseEntity.noContent().build();
|
return ResponseEntity.noContent().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates recurring training sessions for a group.
|
||||||
|
*
|
||||||
|
* @param dto The TrainingGroupDTO containing the group ID and recurrence details.
|
||||||
|
* @return ResponseEntity containing the updated TrainingGroupDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Generate recurring training sessions for a group", description = "Generates recurring training sessions for a specified number of months")
|
@Operation(summary = "Generate recurring training sessions for a group", description = "Generates recurring training sessions for a specified number of months")
|
||||||
@Transactional
|
@Transactional
|
||||||
@PostMapping("/generate-recurring-sessions")
|
@PostMapping("/generate-recurring-sessions")
|
||||||
|
|
@ -176,5 +230,4 @@ public class TrainingGroupController {
|
||||||
|
|
||||||
return ResponseEntity.ok(new TrainingGroupDTO(group));
|
return ResponseEntity.ok(new TrainingGroupDTO(group));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,10 @@ import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller for managing training sessions.
|
||||||
|
* Provides endpoints for creating, retrieving, and deleting training sessions.
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/training-sessions")
|
@RequestMapping("/api/v1/training-sessions")
|
||||||
@Tag(name = "Training Session Management", description = "Operations related to training session management")
|
@Tag(name = "Training Session Management", description = "Operations related to training session management")
|
||||||
|
|
@ -23,17 +27,34 @@ public class TrainingSessionController {
|
||||||
private final TrainingSessionService trainingSessionService;
|
private final TrainingSessionService trainingSessionService;
|
||||||
private final TrainingGroupService trainingGroupService;
|
private final TrainingGroupService trainingGroupService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for TrainingSessionController.
|
||||||
|
*
|
||||||
|
* @param trainingSessionService Service for handling training session records.
|
||||||
|
* @param trainingGroupService Service for handling training group records.
|
||||||
|
*/
|
||||||
public TrainingSessionController(TrainingSessionService trainingSessionService, TrainingGroupService trainingGroupService) {
|
public TrainingSessionController(TrainingSessionService trainingSessionService, TrainingGroupService trainingGroupService) {
|
||||||
this.trainingSessionService = trainingSessionService;
|
this.trainingSessionService = trainingSessionService;
|
||||||
this.trainingGroupService = trainingGroupService;
|
this.trainingGroupService = trainingGroupService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a training session by its ID and returns it as a DTO.
|
||||||
|
*
|
||||||
|
* @param id The ID of the training session to find.
|
||||||
|
* @return TrainingSessionDTO containing the details of the found training session.
|
||||||
|
*/
|
||||||
@Operation(summary = "Find a training session by ID", description = "Retrieve a training session by its ID")
|
@Operation(summary = "Find a training session by ID", description = "Retrieve a training session by its ID")
|
||||||
@GetMapping("findById/{id}")
|
@GetMapping("findById/{id}")
|
||||||
public TrainingSessionDTO findTrainingSessionById(@PathVariable Integer id) {
|
public TrainingSessionDTO findTrainingSessionById(@PathVariable Integer id) {
|
||||||
return TrainingSessionDTO.fromEntity(trainingSessionService.findById(id));
|
return TrainingSessionDTO.fromEntity(trainingSessionService.findById(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all training sessions and returns them as a list of DTOs.
|
||||||
|
*
|
||||||
|
* @return List of TrainingSessionDTOs containing all training sessions.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get all training sessions", description = "Retrieve a list of all training sessions")
|
@Operation(summary = "Get all training sessions", description = "Retrieve a list of all training sessions")
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
public List<TrainingSessionDTO> getAll() {
|
public List<TrainingSessionDTO> getAll() {
|
||||||
|
|
@ -43,6 +64,11 @@ public class TrainingSessionController {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all training sessions by group ID and returns them as a list of DTOs.
|
||||||
|
*
|
||||||
|
* @param id The ID of the training group to find sessions for.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get all training sessions by group ID", description = "Retrieve a list of all training sessions by group ID")
|
@Operation(summary = "Get all training sessions by group ID", description = "Retrieve a list of all training sessions by group ID")
|
||||||
@DeleteMapping("delete/{id}")
|
@DeleteMapping("delete/{id}")
|
||||||
public void delete(@PathVariable Integer id) {
|
public void delete(@PathVariable Integer id) {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,10 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller for managing IVA types.
|
||||||
|
* Provides endpoints for creating, retrieving, updating, and deleting IVA types.
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/iva-types")
|
@RequestMapping("/api/v1/iva-types")
|
||||||
@Tag(name = "IVA Types", description = "Operations related to IVA type management")
|
@Tag(name = "IVA Types", description = "Operations related to IVA type management")
|
||||||
|
|
@ -23,10 +27,22 @@ public class IVATypeController {
|
||||||
|
|
||||||
private final IVATypeService ivaTypeService;
|
private final IVATypeService ivaTypeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for IVATypeController.
|
||||||
|
*
|
||||||
|
* @param ivaTypeService Service for handling IVA type records.
|
||||||
|
*/
|
||||||
public IVATypeController(IVATypeService ivaTypeService) {
|
public IVATypeController(IVATypeService ivaTypeService) {
|
||||||
this.ivaTypeService = ivaTypeService;
|
this.ivaTypeService = ivaTypeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new IVA type.
|
||||||
|
*
|
||||||
|
* @param dto The IVATypeDTO containing the details of the IVA type to be created.
|
||||||
|
* @return ResponseEntity containing the created IVATypeDTO.
|
||||||
|
* @throws DuplicateEntityException if an IVA type with the same name already exists.
|
||||||
|
*/
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "Create a new IVA type")
|
@Operation(summary = "Create a new IVA type")
|
||||||
public ResponseEntity<IVATypeDTO> create(@Valid @RequestBody IVATypeDTO dto) throws DuplicateEntityException {
|
public ResponseEntity<IVATypeDTO> create(@Valid @RequestBody IVATypeDTO dto) throws DuplicateEntityException {
|
||||||
|
|
@ -34,6 +50,14 @@ public class IVATypeController {
|
||||||
return new ResponseEntity<>(new IVATypeDTO(saved), HttpStatus.CREATED);
|
return new ResponseEntity<>(new IVATypeDTO(saved), HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing IVA type.
|
||||||
|
*
|
||||||
|
* @param dto The IVATypeDTO containing the updated details of the IVA type.
|
||||||
|
* @return ResponseEntity containing the updated IVATypeDTO.
|
||||||
|
* @throws EntityNotFoundException if the IVA type to update does not exist.
|
||||||
|
* @throws InvalidDataException if the provided data is invalid.
|
||||||
|
*/
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@Operation(summary = "Update an existing IVA type")
|
@Operation(summary = "Update an existing IVA type")
|
||||||
public ResponseEntity<IVATypeDTO> update(@Valid @RequestBody IVATypeDTO dto) throws EntityNotFoundException, InvalidDataException {
|
public ResponseEntity<IVATypeDTO> update(@Valid @RequestBody IVATypeDTO dto) throws EntityNotFoundException, InvalidDataException {
|
||||||
|
|
@ -41,6 +65,14 @@ public class IVATypeController {
|
||||||
return new ResponseEntity<>(new IVATypeDTO(updated), HttpStatus.OK);
|
return new ResponseEntity<>(new IVATypeDTO(updated), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an IVA type by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the IVA type to retrieve.
|
||||||
|
* @return ResponseEntity containing the IVATypeDTO if found.
|
||||||
|
* @throws EntityNotFoundException if the IVA type with the specified ID does not exist.
|
||||||
|
* @throws InvalidDataException if the provided ID is invalid.
|
||||||
|
*/
|
||||||
@GetMapping("/getById/{id}")
|
@GetMapping("/getById/{id}")
|
||||||
@Operation(summary = "Get IVA type by ID")
|
@Operation(summary = "Get IVA type by ID")
|
||||||
public ResponseEntity<IVATypeDTO> getById(@PathVariable Integer id) throws EntityNotFoundException, InvalidDataException {
|
public ResponseEntity<IVATypeDTO> getById(@PathVariable Integer id) throws EntityNotFoundException, InvalidDataException {
|
||||||
|
|
@ -48,6 +80,11 @@ public class IVATypeController {
|
||||||
return new ResponseEntity<>(new IVATypeDTO(entity), HttpStatus.OK);
|
return new ResponseEntity<>(new IVATypeDTO(entity), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all IVA types.
|
||||||
|
*
|
||||||
|
* @return ResponseEntity containing a list of IVATypeDTOs.
|
||||||
|
*/
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
@Operation(summary = "Get all IVA types")
|
@Operation(summary = "Get all IVA types")
|
||||||
public ResponseEntity<List<IVATypeDTO>> getAll() {
|
public ResponseEntity<List<IVATypeDTO>> getAll() {
|
||||||
|
|
@ -56,6 +93,14 @@ public class IVATypeController {
|
||||||
return new ResponseEntity<>(dtos, HttpStatus.OK);
|
return new ResponseEntity<>(dtos, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an IVA type by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the IVA type to delete.
|
||||||
|
* @return ResponseEntity with no content if deletion is successful.
|
||||||
|
* @throws EntityNotFoundException if the IVA type with the specified ID does not exist.
|
||||||
|
* @throws InvalidDataException if the IVA type is in use and cannot be deleted.
|
||||||
|
*/
|
||||||
@DeleteMapping("/deleteById/{id}")
|
@DeleteMapping("/deleteById/{id}")
|
||||||
@Operation(summary = "Delete IVA type by ID (if not in use)")
|
@Operation(summary = "Delete IVA type by ID (if not in use)")
|
||||||
public ResponseEntity<Void> delete(@PathVariable Integer id) throws EntityNotFoundException, InvalidDataException {
|
public ResponseEntity<Void> delete(@PathVariable Integer id) throws EntityNotFoundException, InvalidDataException {
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,10 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller for managing invoices.
|
||||||
|
* Provides endpoints for creating, retrieving, updating, and deleting invoices,
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/invoices")
|
@RequestMapping("/api/v1/invoices")
|
||||||
@Tag(name = "Invoices", description = "Operations related to invoice management")
|
@Tag(name = "Invoices", description = "Operations related to invoice management")
|
||||||
|
|
@ -37,6 +41,14 @@ public class InvoiceController {
|
||||||
private final ProductServiceService productServiceService;
|
private final ProductServiceService productServiceService;
|
||||||
private final InvoicePdfGenerator invoicePdfGenerator;
|
private final InvoicePdfGenerator invoicePdfGenerator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for InvoiceController.
|
||||||
|
*
|
||||||
|
* @param invoiceService Service for handling invoice records.
|
||||||
|
* @param userService Service for handling user records.
|
||||||
|
* @param productServiceService Service for handling product/service records.
|
||||||
|
* @param invoicePdfGenerator Service for generating PDF invoices.
|
||||||
|
*/
|
||||||
public InvoiceController(InvoiceService invoiceService, UserService userService, ProductServiceService productServiceService, InvoicePdfGenerator invoicePdfGenerator) {
|
public InvoiceController(InvoiceService invoiceService, UserService userService, ProductServiceService productServiceService, InvoicePdfGenerator invoicePdfGenerator) {
|
||||||
this.invoiceService = invoiceService;
|
this.invoiceService = invoiceService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
|
|
@ -44,6 +56,14 @@ public class InvoiceController {
|
||||||
this.invoicePdfGenerator = invoicePdfGenerator;
|
this.invoicePdfGenerator = invoicePdfGenerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new invoice with lines.
|
||||||
|
*
|
||||||
|
* @param dto The CreateInvoiceRequestDTO containing the details of the invoice and its lines.
|
||||||
|
* @return ResponseEntity containing the created InvoiceDTO.
|
||||||
|
* @throws EntityNotFoundException If the user or product/service is not found.
|
||||||
|
* @throws InvalidDataException If the provided data is invalid.
|
||||||
|
*/
|
||||||
@PostMapping("/createInvoiceWithLines")
|
@PostMapping("/createInvoiceWithLines")
|
||||||
@Operation(summary = "Create a new invoice with lines")
|
@Operation(summary = "Create a new invoice with lines")
|
||||||
public ResponseEntity<InvoiceDTO> createInvoiceWithLines(@Valid @RequestBody CreateInvoiceRequestDTO dto) throws EntityNotFoundException, InvalidDataException {
|
public ResponseEntity<InvoiceDTO> createInvoiceWithLines(@Valid @RequestBody CreateInvoiceRequestDTO dto) throws EntityNotFoundException, InvalidDataException {
|
||||||
|
|
@ -59,7 +79,7 @@ public class InvoiceController {
|
||||||
for (CreateInvoiceLineDTO lineDTO : dto.getLines()) {
|
for (CreateInvoiceLineDTO lineDTO : dto.getLines()) {
|
||||||
ProductService product = productServiceService.findById(lineDTO.getProductServiceId());
|
ProductService product = productServiceService.findById(lineDTO.getProductServiceId());
|
||||||
if (product == null) {
|
if (product == null) {
|
||||||
throw new EntityNotFoundException("Product/Service not found");
|
throw new EntityNotFoundException("Product/Service not found with ID: " + lineDTO.getProductServiceId());
|
||||||
}
|
}
|
||||||
InvoiceLine line = lineDTO.toEntity(invoice, product);
|
InvoiceLine line = lineDTO.toEntity(invoice, product);
|
||||||
invoiceService.addLineToInvoiceById(invoice.getId(), line);
|
invoiceService.addLineToInvoiceById(invoice.getId(), line);
|
||||||
|
|
@ -69,6 +89,13 @@ public class InvoiceController {
|
||||||
return new ResponseEntity<>(new InvoiceDTO(invoice), HttpStatus.CREATED);
|
return new ResponseEntity<>(new InvoiceDTO(invoice), HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a PDF for an invoice by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the invoice to generate the PDF for.
|
||||||
|
* @return ResponseEntity containing the PDF file as a byte array.
|
||||||
|
* @throws EntityNotFoundException If the invoice is not found.
|
||||||
|
*/
|
||||||
@GetMapping("/generatePDFById/{id}")
|
@GetMapping("/generatePDFById/{id}")
|
||||||
@Operation(summary = "Generate PDF for invoice by ID")
|
@Operation(summary = "Generate PDF for invoice by ID")
|
||||||
public ResponseEntity<byte[]> downloadInvoicePdf(@PathVariable Integer id) throws EntityNotFoundException {
|
public ResponseEntity<byte[]> downloadInvoicePdf(@PathVariable Integer id) throws EntityNotFoundException {
|
||||||
|
|
@ -82,7 +109,13 @@ public class InvoiceController {
|
||||||
.body(pdf);
|
.body(pdf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new invoice.
|
||||||
|
*
|
||||||
|
* @param dto The InvoiceDTO containing the details of the invoice to be created.
|
||||||
|
* @return ResponseEntity containing the created InvoiceDTO.
|
||||||
|
* @throws DuplicateEntityException If an invoice with the same details already exists.
|
||||||
|
*/
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "Create a new invoice")
|
@Operation(summary = "Create a new invoice")
|
||||||
public ResponseEntity<InvoiceDTO> createInvoice(@Valid @RequestBody InvoiceDTO dto) throws DuplicateEntityException {
|
public ResponseEntity<InvoiceDTO> createInvoice(@Valid @RequestBody InvoiceDTO dto) throws DuplicateEntityException {
|
||||||
|
|
@ -90,6 +123,14 @@ public class InvoiceController {
|
||||||
return new ResponseEntity<>(new InvoiceDTO(saved), HttpStatus.CREATED);
|
return new ResponseEntity<>(new InvoiceDTO(saved), HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing invoice.
|
||||||
|
*
|
||||||
|
* @param dto The InvoiceDTO containing the updated details of the invoice.
|
||||||
|
* @return ResponseEntity containing the updated InvoiceDTO.
|
||||||
|
* @throws EntityNotFoundException If the invoice to update is not found.
|
||||||
|
* @throws InvalidDataException If the provided data is invalid.
|
||||||
|
*/
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@Operation(summary = "Update an existing invoice")
|
@Operation(summary = "Update an existing invoice")
|
||||||
public ResponseEntity<InvoiceDTO> updateInvoice(@Valid @RequestBody InvoiceDTO dto) throws EntityNotFoundException, InvalidDataException {
|
public ResponseEntity<InvoiceDTO> updateInvoice(@Valid @RequestBody InvoiceDTO dto) throws EntityNotFoundException, InvalidDataException {
|
||||||
|
|
@ -97,6 +138,14 @@ public class InvoiceController {
|
||||||
return new ResponseEntity<>(new InvoiceDTO(updated), HttpStatus.OK);
|
return new ResponseEntity<>(new InvoiceDTO(updated), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an invoice by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the invoice to retrieve.
|
||||||
|
* @return ResponseEntity containing the InvoiceDTO if found, or 404 Not Found if not found.
|
||||||
|
* @throws EntityNotFoundException If the invoice is not found.
|
||||||
|
* @throws InvalidDataException If the provided data is invalid.
|
||||||
|
*/
|
||||||
@GetMapping("/getById/{id}")
|
@GetMapping("/getById/{id}")
|
||||||
@Operation(summary = "Get invoice by ID")
|
@Operation(summary = "Get invoice by ID")
|
||||||
public ResponseEntity<InvoiceDTO> getInvoiceById(@PathVariable Integer id) throws EntityNotFoundException, InvalidDataException {
|
public ResponseEntity<InvoiceDTO> getInvoiceById(@PathVariable Integer id) throws EntityNotFoundException, InvalidDataException {
|
||||||
|
|
@ -104,6 +153,11 @@ public class InvoiceController {
|
||||||
return new ResponseEntity<>(new InvoiceDTO(invoice), HttpStatus.OK);
|
return new ResponseEntity<>(new InvoiceDTO(invoice), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all invoices.
|
||||||
|
*
|
||||||
|
* @return ResponseEntity containing a list of InvoiceDTOs.
|
||||||
|
*/
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
@Operation(summary = "Get all invoices")
|
@Operation(summary = "Get all invoices")
|
||||||
public ResponseEntity<List<InvoiceDTO>> getAllInvoices() {
|
public ResponseEntity<List<InvoiceDTO>> getAllInvoices() {
|
||||||
|
|
@ -112,6 +166,14 @@ public class InvoiceController {
|
||||||
return new ResponseEntity<>(dtos, HttpStatus.OK);
|
return new ResponseEntity<>(dtos, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an invoice by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the invoice to delete.
|
||||||
|
* @return ResponseEntity with status NO_CONTENT if successful.
|
||||||
|
* @throws EntityNotFoundException If the invoice to delete is not found.
|
||||||
|
* @throws InvalidDataException If the provided data is invalid.
|
||||||
|
*/
|
||||||
@DeleteMapping("/deleteById/{id}")
|
@DeleteMapping("/deleteById/{id}")
|
||||||
@Operation(summary = "Delete invoice by ID")
|
@Operation(summary = "Delete invoice by ID")
|
||||||
public ResponseEntity<Void> deleteInvoice(@PathVariable Integer id) throws EntityNotFoundException, InvalidDataException {
|
public ResponseEntity<Void> deleteInvoice(@PathVariable Integer id) throws EntityNotFoundException, InvalidDataException {
|
||||||
|
|
@ -119,6 +181,13 @@ public class InvoiceController {
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all invoices associated with a specific user ID.
|
||||||
|
*
|
||||||
|
* @param userId The ID of the user whose invoices are to be retrieved.
|
||||||
|
* @return ResponseEntity containing a list of InvoiceDTOs for the specified user.
|
||||||
|
* @throws InvalidDataException If the provided data is invalid.
|
||||||
|
*/
|
||||||
@GetMapping("/getAllInvoicesByUserId/{userId}")
|
@GetMapping("/getAllInvoicesByUserId/{userId}")
|
||||||
@Operation(summary = "Get all invoices by user ID")
|
@Operation(summary = "Get all invoices by user ID")
|
||||||
public ResponseEntity<List<InvoiceDTO>> getInvoicesByUserId(@PathVariable Integer userId) throws InvalidDataException {
|
public ResponseEntity<List<InvoiceDTO>> getInvoicesByUserId(@PathVariable Integer userId) throws InvalidDataException {
|
||||||
|
|
@ -127,6 +196,13 @@ public class InvoiceController {
|
||||||
return new ResponseEntity<>(dtos, HttpStatus.OK);
|
return new ResponseEntity<>(dtos, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a line to an invoice by its ID.
|
||||||
|
*
|
||||||
|
* @param invoiceId The ID of the invoice to add the line to.
|
||||||
|
* @param line The InvoiceLine to be added to the invoice.
|
||||||
|
* @return ResponseEntity with status OK if successful.
|
||||||
|
*/
|
||||||
@PostMapping("/addLinesByInvoiceId/{invoiceId}")
|
@PostMapping("/addLinesByInvoiceId/{invoiceId}")
|
||||||
@Operation(summary = "Add a line to an invoice by invoice ID")
|
@Operation(summary = "Add a line to an invoice by invoice ID")
|
||||||
public ResponseEntity<Void> addLineToInvoice(@PathVariable Integer invoiceId, @RequestBody @Valid InvoiceLine line) {
|
public ResponseEntity<Void> addLineToInvoice(@PathVariable Integer invoiceId, @RequestBody @Valid InvoiceLine line) {
|
||||||
|
|
@ -134,6 +210,14 @@ public class InvoiceController {
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a line from an invoice by its ID.
|
||||||
|
*
|
||||||
|
* @param invoiceId The ID of the invoice to remove the line from.
|
||||||
|
* @param lineId The ID of the line to be removed.
|
||||||
|
* @return ResponseEntity with status NO_CONTENT if successful.
|
||||||
|
* @throws EntityNotFoundException If the invoice or line is not found.
|
||||||
|
*/
|
||||||
@DeleteMapping("/removeLineFromInvoiceById/{invoiceId}")
|
@DeleteMapping("/removeLineFromInvoiceById/{invoiceId}")
|
||||||
@Operation(summary = "Remove a line from an invoice by IDs")
|
@Operation(summary = "Remove a line from an invoice by IDs")
|
||||||
public ResponseEntity<Void> removeLineFromInvoice(@PathVariable Integer invoiceId, @PathVariable Integer lineId) {
|
public ResponseEntity<Void> removeLineFromInvoice(@PathVariable Integer invoiceId, @PathVariable Integer lineId) {
|
||||||
|
|
@ -141,6 +225,14 @@ public class InvoiceController {
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recalculates the total of an invoice by its ID.
|
||||||
|
*
|
||||||
|
* @param invoiceId The ID of the invoice to recalculate the total for.
|
||||||
|
* @return ResponseEntity with status OK if successful.
|
||||||
|
* @throws EntityNotFoundException If the invoice is not found.
|
||||||
|
* @throws InvalidDataException If the provided data is invalid.
|
||||||
|
*/
|
||||||
@PutMapping("/recalculateTotalOfInvoiceById/{invoiceId}")
|
@PutMapping("/recalculateTotalOfInvoiceById/{invoiceId}")
|
||||||
@Operation(summary = "Recalculate the total of an invoice")
|
@Operation(summary = "Recalculate the total of an invoice")
|
||||||
public ResponseEntity<Void> recalculateTotal(@PathVariable Integer invoiceId) throws EntityNotFoundException, InvalidDataException {
|
public ResponseEntity<Void> recalculateTotal(@PathVariable Integer invoiceId) throws EntityNotFoundException, InvalidDataException {
|
||||||
|
|
@ -149,6 +241,14 @@ public class InvoiceController {
|
||||||
return new ResponseEntity<>(HttpStatus.OK);
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears all lines from an invoice by its ID.
|
||||||
|
*
|
||||||
|
* @param invoiceId The ID of the invoice to clear lines from.
|
||||||
|
* @return ResponseEntity with status NO_CONTENT if successful.
|
||||||
|
* @throws EntityNotFoundException If the invoice is not found.
|
||||||
|
* @throws InvalidDataException If the provided data is invalid.
|
||||||
|
*/
|
||||||
@DeleteMapping("/clearAllLinesFromInvoiceById/{invoiceId}")
|
@DeleteMapping("/clearAllLinesFromInvoiceById/{invoiceId}")
|
||||||
@Operation(summary = "Clear all invoice lines from an invoice")
|
@Operation(summary = "Clear all invoice lines from an invoice")
|
||||||
public ResponseEntity<Void> clearInvoiceLines(@PathVariable Integer invoiceId) throws EntityNotFoundException, InvalidDataException {
|
public ResponseEntity<Void> clearInvoiceLines(@PathVariable Integer invoiceId) throws EntityNotFoundException, InvalidDataException {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* InvoiceLineController handles operations related to invoice lines (items in invoices).
|
* Controller for managing invoice lines.
|
||||||
|
* Provides endpoints for creating, retrieving, updating, and deleting invoice lines.
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/invoice-lines")
|
@RequestMapping("/api/v1/invoice-lines")
|
||||||
|
|
@ -26,10 +27,22 @@ public class InvoiceLineController {
|
||||||
|
|
||||||
private final InvoiceLineService invoiceLineService;
|
private final InvoiceLineService invoiceLineService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for InvoiceLineController.
|
||||||
|
*
|
||||||
|
* @param invoiceLineService Service for handling invoice line records.
|
||||||
|
*/
|
||||||
public InvoiceLineController(InvoiceLineService invoiceLineService) {
|
public InvoiceLineController(InvoiceLineService invoiceLineService) {
|
||||||
this.invoiceLineService = invoiceLineService;
|
this.invoiceLineService = invoiceLineService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new invoice line.
|
||||||
|
*
|
||||||
|
* @param dto The InvoiceLineDTO containing the details of the invoice line to be created.
|
||||||
|
* @return ResponseEntity containing the created InvoiceLineDTO.
|
||||||
|
* @throws DuplicateEntityException if an invoice line with the same details already exists.
|
||||||
|
*/
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "Create a new invoice line")
|
@Operation(summary = "Create a new invoice line")
|
||||||
public ResponseEntity<InvoiceLineDTO> create(@Valid @RequestBody InvoiceLineDTO dto) throws DuplicateEntityException {
|
public ResponseEntity<InvoiceLineDTO> create(@Valid @RequestBody InvoiceLineDTO dto) throws DuplicateEntityException {
|
||||||
|
|
@ -37,6 +50,14 @@ public class InvoiceLineController {
|
||||||
return new ResponseEntity<>(new InvoiceLineDTO(saved), HttpStatus.CREATED);
|
return new ResponseEntity<>(new InvoiceLineDTO(saved), HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing invoice line.
|
||||||
|
*
|
||||||
|
* @param dto The InvoiceLineDTO containing the updated details of the invoice line.
|
||||||
|
* @return ResponseEntity containing the updated InvoiceLineDTO.
|
||||||
|
* @throws InvalidDataException if the provided data is invalid.
|
||||||
|
* @throws EntityNotFoundException if the invoice line to update does not exist.
|
||||||
|
*/
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@Operation(summary = "Update an existing invoice line")
|
@Operation(summary = "Update an existing invoice line")
|
||||||
public ResponseEntity<InvoiceLineDTO> update(@Valid @RequestBody InvoiceLineDTO dto) throws InvalidDataException, EntityNotFoundException {
|
public ResponseEntity<InvoiceLineDTO> update(@Valid @RequestBody InvoiceLineDTO dto) throws InvalidDataException, EntityNotFoundException {
|
||||||
|
|
@ -44,6 +65,14 @@ public class InvoiceLineController {
|
||||||
return new ResponseEntity<>(new InvoiceLineDTO(updated), HttpStatus.OK);
|
return new ResponseEntity<>(new InvoiceLineDTO(updated), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an invoice line by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the invoice line to retrieve.
|
||||||
|
* @return ResponseEntity containing the InvoiceLineDTO of the found invoice line.
|
||||||
|
* @throws InvalidDataException if the provided ID is invalid.
|
||||||
|
* @throws EntityNotFoundException if the invoice line with the given ID does not exist.
|
||||||
|
*/
|
||||||
@GetMapping("/getById/{id}")
|
@GetMapping("/getById/{id}")
|
||||||
@Operation(summary = "Get invoice line by ID")
|
@Operation(summary = "Get invoice line by ID")
|
||||||
public ResponseEntity<InvoiceLineDTO> getById(@PathVariable Integer id) throws InvalidDataException, EntityNotFoundException {
|
public ResponseEntity<InvoiceLineDTO> getById(@PathVariable Integer id) throws InvalidDataException, EntityNotFoundException {
|
||||||
|
|
@ -51,6 +80,11 @@ public class InvoiceLineController {
|
||||||
return new ResponseEntity<>(new InvoiceLineDTO(line), HttpStatus.OK);
|
return new ResponseEntity<>(new InvoiceLineDTO(line), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all invoice lines.
|
||||||
|
*
|
||||||
|
* @return ResponseEntity containing a list of InvoiceLineDTOs representing all invoice lines.
|
||||||
|
*/
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
@Operation(summary = "Get all invoice lines")
|
@Operation(summary = "Get all invoice lines")
|
||||||
public ResponseEntity<List<InvoiceLineDTO>> getAll() {
|
public ResponseEntity<List<InvoiceLineDTO>> getAll() {
|
||||||
|
|
@ -59,6 +93,14 @@ public class InvoiceLineController {
|
||||||
return new ResponseEntity<>(dtos, HttpStatus.OK);
|
return new ResponseEntity<>(dtos, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an invoice line by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the invoice line to delete.
|
||||||
|
* @return ResponseEntity with no content status.
|
||||||
|
* @throws InvalidDataException if the provided ID is invalid.
|
||||||
|
* @throws EntityNotFoundException if the invoice line with the given ID does not exist.
|
||||||
|
*/
|
||||||
@DeleteMapping("/deleteById/{id}")
|
@DeleteMapping("/deleteById/{id}")
|
||||||
@Operation(summary = "Delete invoice line by ID")
|
@Operation(summary = "Delete invoice line by ID")
|
||||||
public ResponseEntity<Void> delete(@PathVariable Integer id) throws InvalidDataException, EntityNotFoundException {
|
public ResponseEntity<Void> delete(@PathVariable Integer id) throws InvalidDataException, EntityNotFoundException {
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,10 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PaymentController handles requests related to payment management.
|
||||||
|
* It provides endpoints for creating, updating, retrieving, and deleting payments.
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/payments")
|
@RequestMapping("/api/v1/payments")
|
||||||
@Tag(name = "Payments", description = "Operations related to payment management")
|
@Tag(name = "Payments", description = "Operations related to payment management")
|
||||||
|
|
@ -24,10 +28,23 @@ public class PaymentController {
|
||||||
|
|
||||||
private final PaymentService paymentService;
|
private final PaymentService paymentService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for PaymentController.
|
||||||
|
*
|
||||||
|
* @param paymentService Service for handling payment records.
|
||||||
|
*/
|
||||||
public PaymentController(PaymentService paymentService) {
|
public PaymentController(PaymentService paymentService) {
|
||||||
this.paymentService = paymentService;
|
this.paymentService = paymentService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new payment and marks the associated invoice as PAID.
|
||||||
|
*
|
||||||
|
* @param dto The PaymentDTO containing the details of the payment to be created.
|
||||||
|
* @return ResponseEntity containing the created PaymentDTO.
|
||||||
|
* @throws DuplicateEntityException if a payment already exists for the given invoice ID.
|
||||||
|
* @throws EntityNotFoundException if the invoice with the given ID does not exist.
|
||||||
|
*/
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "Create a new payment and mark invoice as PAID")
|
@Operation(summary = "Create a new payment and mark invoice as PAID")
|
||||||
public ResponseEntity<PaymentDTO> create(@Valid @RequestBody PaymentDTO dto)
|
public ResponseEntity<PaymentDTO> create(@Valid @RequestBody PaymentDTO dto)
|
||||||
|
|
@ -46,7 +63,14 @@ public class PaymentController {
|
||||||
return new ResponseEntity<>(new PaymentDTO(saved), HttpStatus.CREATED);
|
return new ResponseEntity<>(new PaymentDTO(saved), HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing payment and adjusts the invoice status accordingly.
|
||||||
|
*
|
||||||
|
* @param dto The PaymentDTO containing the updated details of the payment.
|
||||||
|
* @return ResponseEntity containing the updated PaymentDTO.
|
||||||
|
* @throws EntityNotFoundException if the invoice with the given ID does not exist.
|
||||||
|
* @throws InvalidDataException if the provided data is invalid.
|
||||||
|
*/
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@Operation(summary = "Update an existing payment and adjust invoice status")
|
@Operation(summary = "Update an existing payment and adjust invoice status")
|
||||||
public ResponseEntity<PaymentDTO> update(@Valid @RequestBody PaymentDTO dto)
|
public ResponseEntity<PaymentDTO> update(@Valid @RequestBody PaymentDTO dto)
|
||||||
|
|
@ -65,7 +89,14 @@ public class PaymentController {
|
||||||
return new ResponseEntity<>(new PaymentDTO(updated), HttpStatus.OK);
|
return new ResponseEntity<>(new PaymentDTO(updated), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a payment by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the payment to retrieve.
|
||||||
|
* @return ResponseEntity containing the PaymentDTO if found.
|
||||||
|
* @throws EntityNotFoundException if the payment with the given ID does not exist.
|
||||||
|
* @throws InvalidDataException if the provided ID is invalid.
|
||||||
|
*/
|
||||||
@GetMapping("/getById/{id}")
|
@GetMapping("/getById/{id}")
|
||||||
@Operation(summary = "Get payment by ID")
|
@Operation(summary = "Get payment by ID")
|
||||||
public ResponseEntity<PaymentDTO> getById(@PathVariable Integer id) throws EntityNotFoundException, InvalidDataException {
|
public ResponseEntity<PaymentDTO> getById(@PathVariable Integer id) throws EntityNotFoundException, InvalidDataException {
|
||||||
|
|
@ -73,6 +104,11 @@ public class PaymentController {
|
||||||
return new ResponseEntity<>(new PaymentDTO(payment), HttpStatus.OK);
|
return new ResponseEntity<>(new PaymentDTO(payment), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all payments.
|
||||||
|
*
|
||||||
|
* @return ResponseEntity containing a list of PaymentDTOs.
|
||||||
|
*/
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
@Operation(summary = "Get all payments")
|
@Operation(summary = "Get all payments")
|
||||||
public ResponseEntity<List<PaymentDTO>> getAll() {
|
public ResponseEntity<List<PaymentDTO>> getAll() {
|
||||||
|
|
@ -81,6 +117,14 @@ public class PaymentController {
|
||||||
return new ResponseEntity<>(dtos, HttpStatus.OK);
|
return new ResponseEntity<>(dtos, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a payment by its ID and sets the associated invoice status to NOT_PAID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the payment to delete.
|
||||||
|
* @return ResponseEntity with no content status.
|
||||||
|
* @throws EntityNotFoundException if the payment with the given ID does not exist.
|
||||||
|
* @throws InvalidDataException if the provided ID is invalid.
|
||||||
|
*/
|
||||||
@DeleteMapping("/deleteById/{id}")
|
@DeleteMapping("/deleteById/{id}")
|
||||||
@Operation(summary = "Remove a payment and set invoice status to NOT_PAID")
|
@Operation(summary = "Remove a payment and set invoice status to NOT_PAID")
|
||||||
public ResponseEntity<Void> removePayment(@PathVariable Integer id) throws EntityNotFoundException, InvalidDataException {
|
public ResponseEntity<Void> removePayment(@PathVariable Integer id) throws EntityNotFoundException, InvalidDataException {
|
||||||
|
|
@ -88,6 +132,12 @@ public class PaymentController {
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all payments made by a specific user.
|
||||||
|
*
|
||||||
|
* @param userId The ID of the user whose payments are to be retrieved.
|
||||||
|
* @return ResponseEntity containing a list of PaymentDTOs for the specified user.
|
||||||
|
*/
|
||||||
@GetMapping("/getAllByUserId/{userId}")
|
@GetMapping("/getAllByUserId/{userId}")
|
||||||
@Operation(summary = "Get all payments by user ID")
|
@Operation(summary = "Get all payments by user ID")
|
||||||
public ResponseEntity<List<PaymentDTO>> getAllByUserId(@PathVariable Integer userId) {
|
public ResponseEntity<List<PaymentDTO>> getAllByUserId(@PathVariable Integer userId) {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller for managing products and services.
|
||||||
|
* Provides endpoints for creating, updating, retrieving, and deleting products/services.
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/products-services")
|
@RequestMapping("/api/v1/products-services")
|
||||||
@Tag(name = "Product Services", description = "Operations related to product/service management")
|
@Tag(name = "Product Services", description = "Operations related to product/service management")
|
||||||
|
|
@ -26,11 +30,24 @@ public class ProductServiceController {
|
||||||
private final ProductServiceService productServiceService;
|
private final ProductServiceService productServiceService;
|
||||||
private final IVATypeService ivaTypeService;
|
private final IVATypeService ivaTypeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for ProductServiceController.
|
||||||
|
*
|
||||||
|
* @param productServiceService Service for handling product/service records.
|
||||||
|
* @param ivaTypeService Service for handling IVA type records.
|
||||||
|
*/
|
||||||
public ProductServiceController(ProductServiceService productServiceService, IVATypeService ivaTypeService) {
|
public ProductServiceController(ProductServiceService productServiceService, IVATypeService ivaTypeService) {
|
||||||
this.productServiceService = productServiceService;
|
this.productServiceService = productServiceService;
|
||||||
this.ivaTypeService = ivaTypeService;
|
this.ivaTypeService = ivaTypeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new product/service.
|
||||||
|
*
|
||||||
|
* @param dto The ProductServiceDTO containing the details of the product/service to be created.
|
||||||
|
* @return ResponseEntity containing the created ProductServiceDTO.
|
||||||
|
* @throws DuplicateEntityException if a product/service with the same name already exists.
|
||||||
|
*/
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@Operation(summary = "Create a new product/service")
|
@Operation(summary = "Create a new product/service")
|
||||||
public ResponseEntity<ProductServiceDTO> create(@Valid @RequestBody ProductServiceDTO dto) throws DuplicateEntityException {
|
public ResponseEntity<ProductServiceDTO> create(@Valid @RequestBody ProductServiceDTO dto) throws DuplicateEntityException {
|
||||||
|
|
@ -39,6 +56,14 @@ public class ProductServiceController {
|
||||||
return new ResponseEntity<>(new ProductServiceDTO(saved), HttpStatus.CREATED);
|
return new ResponseEntity<>(new ProductServiceDTO(saved), HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing product/service.
|
||||||
|
*
|
||||||
|
* @param dto The ProductServiceDTO containing the updated details of the product/service.
|
||||||
|
* @return ResponseEntity containing the updated ProductServiceDTO.
|
||||||
|
* @throws EntityNotFoundException if the product/service to update does not exist.
|
||||||
|
* @throws InvalidDataException if the provided data is invalid.
|
||||||
|
*/
|
||||||
@PutMapping("/update")
|
@PutMapping("/update")
|
||||||
@Operation(summary = "Update an existing product/service")
|
@Operation(summary = "Update an existing product/service")
|
||||||
public ResponseEntity<ProductServiceDTO> update(@Valid @RequestBody ProductServiceDTO dto) throws EntityNotFoundException, InvalidDataException {
|
public ResponseEntity<ProductServiceDTO> update(@Valid @RequestBody ProductServiceDTO dto) throws EntityNotFoundException, InvalidDataException {
|
||||||
|
|
@ -47,7 +72,14 @@ public class ProductServiceController {
|
||||||
return new ResponseEntity<>(new ProductServiceDTO(updated), HttpStatus.OK);
|
return new ResponseEntity<>(new ProductServiceDTO(updated), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a product/service by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the product/service to retrieve.
|
||||||
|
* @return ResponseEntity containing the ProductServiceDTO if found.
|
||||||
|
* @throws EntityNotFoundException if the product/service with the specified ID does not exist.
|
||||||
|
* @throws InvalidDataException if the provided ID is invalid.
|
||||||
|
*/
|
||||||
@GetMapping("/getById/{id}")
|
@GetMapping("/getById/{id}")
|
||||||
@Operation(summary = "Get product/service by ID")
|
@Operation(summary = "Get product/service by ID")
|
||||||
public ResponseEntity<ProductServiceDTO> getById(@PathVariable Integer id) throws EntityNotFoundException, InvalidDataException {
|
public ResponseEntity<ProductServiceDTO> getById(@PathVariable Integer id) throws EntityNotFoundException, InvalidDataException {
|
||||||
|
|
@ -55,6 +87,11 @@ public class ProductServiceController {
|
||||||
return new ResponseEntity<>(new ProductServiceDTO(entity), HttpStatus.OK);
|
return new ResponseEntity<>(new ProductServiceDTO(entity), HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all products/services.
|
||||||
|
*
|
||||||
|
* @return ResponseEntity containing a list of ProductServiceDTOs.
|
||||||
|
*/
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
@Operation(summary = "Get all products/services")
|
@Operation(summary = "Get all products/services")
|
||||||
public ResponseEntity<List<ProductServiceDTO>> getAll() {
|
public ResponseEntity<List<ProductServiceDTO>> getAll() {
|
||||||
|
|
@ -63,6 +100,14 @@ public class ProductServiceController {
|
||||||
return new ResponseEntity<>(dtos, HttpStatus.OK);
|
return new ResponseEntity<>(dtos, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a product/service by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the product/service to delete.
|
||||||
|
* @return ResponseEntity with no content if deletion is successful.
|
||||||
|
* @throws EntityNotFoundException if the product/service with the specified ID does not exist.
|
||||||
|
* @throws InvalidDataException if the provided ID is invalid.
|
||||||
|
*/
|
||||||
@DeleteMapping("/deleteById/{id}")
|
@DeleteMapping("/deleteById/{id}")
|
||||||
@Operation(summary = "Delete product/service by ID")
|
@Operation(summary = "Delete product/service by ID")
|
||||||
public ResponseEntity<Void> delete(@PathVariable Integer id) throws EntityNotFoundException, InvalidDataException {
|
public ResponseEntity<Void> delete(@PathVariable Integer id) throws EntityNotFoundException, InvalidDataException {
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@ import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller for managing administrators.
|
||||||
|
* Provides endpoints for creating, retrieving, updating, and deleting administrators.
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/admins")
|
@RequestMapping("/api/v1/admins")
|
||||||
@Tag(name = "Administrator Management", description = "Operations related to administrator management")
|
@Tag(name = "Administrator Management", description = "Operations related to administrator management")
|
||||||
|
|
@ -26,14 +30,28 @@ public class AdminController {
|
||||||
private final AdminService adminService;
|
private final AdminService adminService;
|
||||||
private final RoleService roleService;
|
private final RoleService roleService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password encoder for encoding passwords.
|
||||||
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
private PasswordEncoder passwordEncoder;
|
private PasswordEncoder passwordEncoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for AdminController.
|
||||||
|
*
|
||||||
|
* @param adminService Service for handling administrator records.
|
||||||
|
* @param roleService Service for handling roles.
|
||||||
|
*/
|
||||||
public AdminController(AdminService adminService, RoleService roleService) {
|
public AdminController(AdminService adminService, RoleService roleService) {
|
||||||
this.adminService = adminService;
|
this.adminService = adminService;
|
||||||
this.roleService = roleService;
|
this.roleService = roleService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all administrators and returns them as a list of DTOs.
|
||||||
|
*
|
||||||
|
* @return ResponseEntity containing a list of AdminDTOs or no content if none found.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get all administrators")
|
@Operation(summary = "Get all administrators")
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
public ResponseEntity<List<AdminDTO>> getAllAdmins() {
|
public ResponseEntity<List<AdminDTO>> getAllAdmins() {
|
||||||
|
|
@ -45,6 +63,12 @@ public class AdminController {
|
||||||
return dtos.isEmpty() ? ResponseEntity.noContent().build() : ResponseEntity.ok(dtos);
|
return dtos.isEmpty() ? ResponseEntity.noContent().build() : ResponseEntity.ok(dtos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets administrator by ID and returns it as a DTO.
|
||||||
|
*
|
||||||
|
* @param id The ID of the administrator to find.
|
||||||
|
* @return ResponseEntity containing the AdminDTO or not found if the ID does not exist.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get administrator by ID")
|
@Operation(summary = "Get administrator by ID")
|
||||||
@GetMapping("/getById/{id}")
|
@GetMapping("/getById/{id}")
|
||||||
public ResponseEntity<AdminDTO> getById(@PathVariable Integer id) {
|
public ResponseEntity<AdminDTO> getById(@PathVariable Integer id) {
|
||||||
|
|
@ -52,6 +76,12 @@ public class AdminController {
|
||||||
return ResponseEntity.ok(convertToDTO(admin));
|
return ResponseEntity.ok(convertToDTO(admin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new administrator.
|
||||||
|
*
|
||||||
|
* @param dto The AdminDTO containing the details of the administrator to be created.
|
||||||
|
* @return ResponseEntity containing the created AdminDTO with status 201 Created.
|
||||||
|
*/
|
||||||
@Operation(summary = "Create a new administrator")
|
@Operation(summary = "Create a new administrator")
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public ResponseEntity<AdminDTO> create(@RequestBody AdminDTO dto) {
|
public ResponseEntity<AdminDTO> create(@RequestBody AdminDTO dto) {
|
||||||
|
|
@ -60,6 +90,13 @@ public class AdminController {
|
||||||
return ResponseEntity.status(201).body(convertToDTO(saved));
|
return ResponseEntity.status(201).body(convertToDTO(saved));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing administrator.
|
||||||
|
*
|
||||||
|
* @param id The ID of the administrator to update.
|
||||||
|
* @param dto The AdminDTO containing the updated details of the administrator.
|
||||||
|
* @return ResponseEntity containing the updated AdminDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Update an existing administrator")
|
@Operation(summary = "Update an existing administrator")
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
public ResponseEntity<AdminDTO> update(@PathVariable Integer id, @RequestBody AdminDTO dto) {
|
public ResponseEntity<AdminDTO> update(@PathVariable Integer id, @RequestBody AdminDTO dto) {
|
||||||
|
|
@ -69,6 +106,12 @@ public class AdminController {
|
||||||
return ResponseEntity.ok(convertToDTO(updated));
|
return ResponseEntity.ok(convertToDTO(updated));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an administrator by ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the administrator to delete.
|
||||||
|
* @return ResponseEntity with a message indicating successful deletion.
|
||||||
|
*/
|
||||||
@Operation(summary = "Delete an administrator by ID")
|
@Operation(summary = "Delete an administrator by ID")
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
public ResponseEntity<String> delete(@PathVariable Integer id) {
|
public ResponseEntity<String> delete(@PathVariable Integer id) {
|
||||||
|
|
@ -76,12 +119,26 @@ public class AdminController {
|
||||||
return ResponseEntity.ok("Admin deleted");
|
return ResponseEntity.ok("Admin deleted");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------- Utils --------------------
|
/* -------------------- Utils -------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an Admin entity to an AdminDTO.
|
||||||
|
*
|
||||||
|
* @param admin The Admin entity to convert.
|
||||||
|
* @return The converted AdminDTO.
|
||||||
|
*/
|
||||||
private AdminDTO convertToDTO(Admin admin) {
|
private AdminDTO convertToDTO(Admin admin) {
|
||||||
return AdminDTO.fromEntity(admin);
|
return AdminDTO.fromEntity(admin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an AdminDTO to an Admin entity.
|
||||||
|
*
|
||||||
|
* @param dto The AdminDTO to convert.
|
||||||
|
* @param isCreate Indicates if the conversion is for creation (true) or update (false).
|
||||||
|
* @return The converted Admin entity.
|
||||||
|
* @throws InvalidDataException if the provided data is invalid.
|
||||||
|
*/
|
||||||
private Admin convertToEntity(AdminDTO dto, boolean isCreate) {
|
private Admin convertToEntity(AdminDTO dto, boolean isCreate) {
|
||||||
if (dto == null || dto.getUser() == null) {
|
if (dto == null || dto.getUser() == null) {
|
||||||
throw new InvalidDataException("Admin and User data are required");
|
throw new InvalidDataException("Admin and User data are required");
|
||||||
|
|
@ -118,5 +175,4 @@ public class AdminController {
|
||||||
admin.setUser(user);
|
admin.setUser(user);
|
||||||
return admin;
|
return admin;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,10 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* NotificationController handles requests related to notification management.
|
||||||
|
* It provides endpoints for creating, retrieving, updating, and deleting notifications.
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/notifications")
|
@RequestMapping("/api/v1/notifications")
|
||||||
@Tag(name = "Notification Management", description = "Operations related to notifications")
|
@Tag(name = "Notification Management", description = "Operations related to notifications")
|
||||||
|
|
@ -23,11 +27,22 @@ public class NotificationController {
|
||||||
private final NotificationService notificationService;
|
private final NotificationService notificationService;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for NotificationController.
|
||||||
|
*
|
||||||
|
* @param notificationService Service for handling notification records.
|
||||||
|
* @param userService Service for handling user records.
|
||||||
|
*/
|
||||||
public NotificationController(NotificationService notificationService, UserService userService) {
|
public NotificationController(NotificationService notificationService, UserService userService) {
|
||||||
this.notificationService = notificationService;
|
this.notificationService = notificationService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all notifications and returns them as a list of DTOs.
|
||||||
|
*
|
||||||
|
* @return ResponseEntity containing a list of NotificationDTOs or no content if none found.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get all notifications", description = "Retrieve a list of all notifications")
|
@Operation(summary = "Get all notifications", description = "Retrieve a list of all notifications")
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
public ResponseEntity<List<NotificationDTO>> getAll() {
|
public ResponseEntity<List<NotificationDTO>> getAll() {
|
||||||
|
|
@ -38,6 +53,12 @@ public class NotificationController {
|
||||||
return ResponseEntity.ok(dtos);
|
return ResponseEntity.ok(dtos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a notification by its ID and returns it as a DTO.
|
||||||
|
*
|
||||||
|
* @param id The ID of the notification to find.
|
||||||
|
* @return ResponseEntity containing the NotificationDTO or not found if it doesn't exist.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get a notification by ID", description = "Retrieve a notification by its ID")
|
@Operation(summary = "Get a notification by ID", description = "Retrieve a notification by its ID")
|
||||||
@GetMapping("/getById/{id}")
|
@GetMapping("/getById/{id}")
|
||||||
public ResponseEntity<NotificationDTO> getById(@PathVariable Integer id) {
|
public ResponseEntity<NotificationDTO> getById(@PathVariable Integer id) {
|
||||||
|
|
@ -45,6 +66,12 @@ public class NotificationController {
|
||||||
return ResponseEntity.ok(toDTO(notification));
|
return ResponseEntity.ok(toDTO(notification));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new notification.
|
||||||
|
*
|
||||||
|
* @param dto The NotificationDTO containing the details of the notification to be created.
|
||||||
|
* @return ResponseEntity containing the created NotificationDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Create a new notification", description = "Create a new notification")
|
@Operation(summary = "Create a new notification", description = "Create a new notification")
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public ResponseEntity<NotificationDTO> create(@RequestBody NotificationDTO dto) {
|
public ResponseEntity<NotificationDTO> create(@RequestBody NotificationDTO dto) {
|
||||||
|
|
@ -57,11 +84,16 @@ public class NotificationController {
|
||||||
notificationService.addNotificationToUser(saved, user);
|
notificationService.addNotificationToUser(saved, user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResponseEntity.status(201).body(toDTO(saved));
|
return ResponseEntity.status(201).body(toDTO(saved));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing notification by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the notification to update.
|
||||||
|
* @param dto The NotificationDTO containing the updated details of the notification.
|
||||||
|
* @return ResponseEntity containing the updated NotificationDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Update a notification by ID", description = "Update a notification by its ID")
|
@Operation(summary = "Update a notification by ID", description = "Update a notification by its ID")
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
public ResponseEntity<NotificationDTO> update(@PathVariable Integer id, @RequestBody NotificationDTO dto) {
|
public ResponseEntity<NotificationDTO> update(@PathVariable Integer id, @RequestBody NotificationDTO dto) {
|
||||||
|
|
@ -87,7 +119,12 @@ public class NotificationController {
|
||||||
return ResponseEntity.ok(toDTO(updated));
|
return ResponseEntity.ok(toDTO(updated));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a notification by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the notification to delete.
|
||||||
|
* @return ResponseEntity with a message indicating successful deletion.
|
||||||
|
*/
|
||||||
@Operation(summary = "Delete a notification by ID", description = "Delete a notification by its ID")
|
@Operation(summary = "Delete a notification by ID", description = "Delete a notification by its ID")
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
public ResponseEntity<String> delete(@PathVariable Integer id) {
|
public ResponseEntity<String> delete(@PathVariable Integer id) {
|
||||||
|
|
@ -95,8 +132,14 @@ public class NotificationController {
|
||||||
return ResponseEntity.ok("Notification deleted successfully.");
|
return ResponseEntity.ok("Notification deleted successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------- Mapping --------------------
|
/* -------------------- Utils -------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a Notification entity to a NotificationDTO.
|
||||||
|
*
|
||||||
|
* @param notification The Notification entity to convert.
|
||||||
|
* @return The converted NotificationDTO.
|
||||||
|
*/
|
||||||
private NotificationDTO toDTO(Notification notification) {
|
private NotificationDTO toDTO(Notification notification) {
|
||||||
Set<Integer> userIds = notification.getUsers() != null
|
Set<Integer> userIds = notification.getUsers() != null
|
||||||
? notification.getUsers().stream().map(User::getId).collect(Collectors.toSet())
|
? notification.getUsers().stream().map(User::getId).collect(Collectors.toSet())
|
||||||
|
|
@ -113,6 +156,13 @@ public class NotificationController {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a NotificationDTO to a Notification entity.
|
||||||
|
*
|
||||||
|
* @param dto The NotificationDTO to convert.
|
||||||
|
* @param includeUsers Whether to include users in the conversion.
|
||||||
|
* @return The converted Notification entity.
|
||||||
|
*/
|
||||||
private Notification toEntity(NotificationDTO dto, boolean includeUsers) {
|
private Notification toEntity(NotificationDTO dto, boolean includeUsers) {
|
||||||
Notification notification = (dto.getId() != null)
|
Notification notification = (dto.getId() != null)
|
||||||
? notificationService.findById(dto.getId())
|
? notificationService.findById(dto.getId())
|
||||||
|
|
@ -126,5 +176,4 @@ public class NotificationController {
|
||||||
|
|
||||||
return notification;
|
return notification;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PermissionController handles requests related to permission management.
|
||||||
|
* It provides endpoints for creating, retrieving, updating, and deleting permissions.
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/permissions")
|
@RequestMapping("/api/v1/permissions")
|
||||||
@Tag(name = "Permission Management", description = "Operations related to permissions")
|
@Tag(name = "Permission Management", description = "Operations related to permissions")
|
||||||
|
|
@ -18,10 +22,20 @@ public class PermissionController {
|
||||||
|
|
||||||
private final PermissionService permissionService;
|
private final PermissionService permissionService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for PermissionController.
|
||||||
|
*
|
||||||
|
* @param permissionService Service for handling permission records.
|
||||||
|
*/
|
||||||
public PermissionController(PermissionService permissionService) {
|
public PermissionController(PermissionService permissionService) {
|
||||||
this.permissionService = permissionService;
|
this.permissionService = permissionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all permissions and returns them as a list of DTOs.
|
||||||
|
*
|
||||||
|
* @return ResponseEntity containing a list of PermissionDTOs or no content if none found.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get all permissions", description = "Retrieve a list of all permissions")
|
@Operation(summary = "Get all permissions", description = "Retrieve a list of all permissions")
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
public ResponseEntity<List<PermissionDTO>> getAll() {
|
public ResponseEntity<List<PermissionDTO>> getAll() {
|
||||||
|
|
@ -34,6 +48,12 @@ public class PermissionController {
|
||||||
return ResponseEntity.ok(dtos);
|
return ResponseEntity.ok(dtos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a permission by its ID and returns it as a DTO.
|
||||||
|
*
|
||||||
|
* @param id The ID of the permission to find.
|
||||||
|
* @return ResponseEntity containing the PermissionDTO or not found if it doesn't exist.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get permission by ID", description = "Retrieve a permission by its ID")
|
@Operation(summary = "Get permission by ID", description = "Retrieve a permission by its ID")
|
||||||
@GetMapping("/getById/{id}")
|
@GetMapping("/getById/{id}")
|
||||||
public ResponseEntity<PermissionDTO> getById(@PathVariable Integer id) {
|
public ResponseEntity<PermissionDTO> getById(@PathVariable Integer id) {
|
||||||
|
|
@ -41,6 +61,12 @@ public class PermissionController {
|
||||||
return ResponseEntity.ok(toDTO(permission));
|
return ResponseEntity.ok(toDTO(permission));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new permission and returns the created permission as a DTO.
|
||||||
|
*
|
||||||
|
* @param dto The PermissionDTO containing the details of the permission to be created.
|
||||||
|
* @return ResponseEntity containing the created PermissionDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Create a new permission", description = "Create a new permission")
|
@Operation(summary = "Create a new permission", description = "Create a new permission")
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public ResponseEntity<PermissionDTO> create(@RequestBody PermissionDTO dto) {
|
public ResponseEntity<PermissionDTO> create(@RequestBody PermissionDTO dto) {
|
||||||
|
|
@ -49,6 +75,13 @@ public class PermissionController {
|
||||||
return ResponseEntity.status(201).body(toDTO(saved));
|
return ResponseEntity.status(201).body(toDTO(saved));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing permission and returns the updated permission as a DTO.
|
||||||
|
*
|
||||||
|
* @param id The ID of the permission to update.
|
||||||
|
* @param dto The PermissionDTO containing the updated details of the permission.
|
||||||
|
* @return ResponseEntity containing the updated PermissionDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Update an existing permission", description = "Update an existing permission")
|
@Operation(summary = "Update an existing permission", description = "Update an existing permission")
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
public ResponseEntity<PermissionDTO> update(@PathVariable Integer id, @RequestBody PermissionDTO dto) {
|
public ResponseEntity<PermissionDTO> update(@PathVariable Integer id, @RequestBody PermissionDTO dto) {
|
||||||
|
|
@ -57,6 +90,12 @@ public class PermissionController {
|
||||||
return ResponseEntity.ok(toDTO(updated));
|
return ResponseEntity.ok(toDTO(updated));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a permission by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the permission to delete.
|
||||||
|
* @return ResponseEntity with a success message.
|
||||||
|
*/
|
||||||
@Operation(summary = "Delete a permission", description = "Delete a permission by its ID")
|
@Operation(summary = "Delete a permission", description = "Delete a permission by its ID")
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
public ResponseEntity<String> delete(@PathVariable Integer id) {
|
public ResponseEntity<String> delete(@PathVariable Integer id) {
|
||||||
|
|
@ -64,12 +103,24 @@ public class PermissionController {
|
||||||
return ResponseEntity.ok("Permission deleted successfully.");
|
return ResponseEntity.ok("Permission deleted successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------- Mapping --------------------
|
/* -------------------- Utils -------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a Permission entity to a PermissionDTO.
|
||||||
|
*
|
||||||
|
* @param permission The Permission entity to convert.
|
||||||
|
* @return The converted PermissionDTO.
|
||||||
|
*/
|
||||||
private PermissionDTO toDTO(Permission permission) {
|
private PermissionDTO toDTO(Permission permission) {
|
||||||
return new PermissionDTO(permission.getId(), permission.getPermissionName());
|
return new PermissionDTO(permission.getId(), permission.getPermissionName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a PermissionDTO to a Permission entity.
|
||||||
|
*
|
||||||
|
* @param dto The PermissionDTO to convert.
|
||||||
|
* @return The converted Permission entity.
|
||||||
|
*/
|
||||||
private Permission toEntity(PermissionDTO dto) {
|
private Permission toEntity(PermissionDTO dto) {
|
||||||
Permission permission = (dto.getId() != null)
|
Permission permission = (dto.getId() != null)
|
||||||
? permissionService.findById(dto.getId())
|
? permissionService.findById(dto.getId())
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,10 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RoleController handles requests related to role management.
|
||||||
|
* It provides endpoints for creating, retrieving, updating, and deleting roles.
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/roles")
|
@RequestMapping("/api/v1/roles")
|
||||||
@Tag(name = "Role Management", description = "Operations related to roles")
|
@Tag(name = "Role Management", description = "Operations related to roles")
|
||||||
|
|
@ -22,11 +26,22 @@ public class RoleController {
|
||||||
private final RoleService roleService;
|
private final RoleService roleService;
|
||||||
private final PermissionService permissionService;
|
private final PermissionService permissionService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for RoleController.
|
||||||
|
*
|
||||||
|
* @param roleService Service for handling role records.
|
||||||
|
* @param permissionService Service for handling permission records.
|
||||||
|
*/
|
||||||
public RoleController(RoleService roleService, PermissionService permissionService) {
|
public RoleController(RoleService roleService, PermissionService permissionService) {
|
||||||
this.roleService = roleService;
|
this.roleService = roleService;
|
||||||
this.permissionService = permissionService;
|
this.permissionService = permissionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all roles and returns them as a list of DTOs.
|
||||||
|
*
|
||||||
|
* @return ResponseEntity containing a list of RoleDTOs or no content if none found.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get all roles", description = "Retrieve a list of all roles")
|
@Operation(summary = "Get all roles", description = "Retrieve a list of all roles")
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
public ResponseEntity<List<RoleDTO>> getAll() {
|
public ResponseEntity<List<RoleDTO>> getAll() {
|
||||||
|
|
@ -37,6 +52,12 @@ public class RoleController {
|
||||||
return ResponseEntity.ok(dtos);
|
return ResponseEntity.ok(dtos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a role by its ID and returns it as a DTO.
|
||||||
|
*
|
||||||
|
* @param id The ID of the role to find.
|
||||||
|
* @return ResponseEntity containing the RoleDTO or not found if it doesn't exist.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get role by ID", description = "Retrieve a role by its ID")
|
@Operation(summary = "Get role by ID", description = "Retrieve a role by its ID")
|
||||||
@GetMapping("/getById/{id}")
|
@GetMapping("/getById/{id}")
|
||||||
public ResponseEntity<RoleDTO> getById(@PathVariable Integer id) {
|
public ResponseEntity<RoleDTO> getById(@PathVariable Integer id) {
|
||||||
|
|
@ -44,6 +65,12 @@ public class RoleController {
|
||||||
return ResponseEntity.ok(toDTO(role));
|
return ResponseEntity.ok(toDTO(role));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new role and returns the created role as a DTO.
|
||||||
|
*
|
||||||
|
* @param dto The RoleDTO containing the details of the role to be created.
|
||||||
|
* @return ResponseEntity containing the created RoleDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Create a new role", description = "Create a new role")
|
@Operation(summary = "Create a new role", description = "Create a new role")
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public ResponseEntity<RoleDTO> create(@RequestBody RoleDTO dto) {
|
public ResponseEntity<RoleDTO> create(@RequestBody RoleDTO dto) {
|
||||||
|
|
@ -61,6 +88,13 @@ public class RoleController {
|
||||||
return ResponseEntity.status(201).body(toDTO(saved));
|
return ResponseEntity.status(201).body(toDTO(saved));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing role and returns the updated role as a DTO.
|
||||||
|
*
|
||||||
|
* @param id The ID of the role to update.
|
||||||
|
* @param dto The RoleDTO containing the updated details of the role.
|
||||||
|
* @return ResponseEntity containing the updated RoleDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Update a role", description = "Update an existing role")
|
@Operation(summary = "Update a role", description = "Update an existing role")
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
public ResponseEntity<RoleDTO> update(@PathVariable Integer id, @RequestBody RoleDTO dto) {
|
public ResponseEntity<RoleDTO> update(@PathVariable Integer id, @RequestBody RoleDTO dto) {
|
||||||
|
|
@ -79,6 +113,12 @@ public class RoleController {
|
||||||
return ResponseEntity.ok(toDTO(updated));
|
return ResponseEntity.ok(toDTO(updated));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a role by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the role to delete.
|
||||||
|
* @return ResponseEntity with a message indicating successful deletion.
|
||||||
|
*/
|
||||||
@Operation(summary = "Delete a role", description = "Delete a role by its ID")
|
@Operation(summary = "Delete a role", description = "Delete a role by its ID")
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
public ResponseEntity<String> delete(@PathVariable Integer id) {
|
public ResponseEntity<String> delete(@PathVariable Integer id) {
|
||||||
|
|
@ -86,6 +126,13 @@ public class RoleController {
|
||||||
return ResponseEntity.ok("Role deleted successfully.");
|
return ResponseEntity.ok("Role deleted successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a permission to a role.
|
||||||
|
*
|
||||||
|
* @param roleId The ID of the role to which the permission will be added.
|
||||||
|
* @param permissionId The ID of the permission to add to the role.
|
||||||
|
* @return ResponseEntity with a success message.
|
||||||
|
*/
|
||||||
@Operation(summary = "Add permission to role", description = "Add a permission to a role")
|
@Operation(summary = "Add permission to role", description = "Add a permission to a role")
|
||||||
@PostMapping("/permissions/add/{roleId}/{permissionId}")
|
@PostMapping("/permissions/add/{roleId}/{permissionId}")
|
||||||
public ResponseEntity<String> addPermissionToRole(@PathVariable Integer roleId, @PathVariable Integer permissionId) {
|
public ResponseEntity<String> addPermissionToRole(@PathVariable Integer roleId, @PathVariable Integer permissionId) {
|
||||||
|
|
@ -95,6 +142,13 @@ public class RoleController {
|
||||||
return ResponseEntity.ok("Permission added to role.");
|
return ResponseEntity.ok("Permission added to role.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a permission from a role.
|
||||||
|
*
|
||||||
|
* @param roleId The ID of the role from which the permission will be removed.
|
||||||
|
* @param permissionId The ID of the permission to remove from the role.
|
||||||
|
* @return ResponseEntity with a success message.
|
||||||
|
*/
|
||||||
@Operation(summary = "Remove permission from role", description = "Remove a permission from a role")
|
@Operation(summary = "Remove permission from role", description = "Remove a permission from a role")
|
||||||
@DeleteMapping("/permissions/remove/{permissionId}/{roleId}")
|
@DeleteMapping("/permissions/remove/{permissionId}/{roleId}")
|
||||||
public ResponseEntity<String> removePermissionFromRole(@PathVariable Integer roleId, @PathVariable Integer permissionId) {
|
public ResponseEntity<String> removePermissionFromRole(@PathVariable Integer roleId, @PathVariable Integer permissionId) {
|
||||||
|
|
@ -104,8 +158,14 @@ public class RoleController {
|
||||||
return ResponseEntity.ok("Permission removed from role.");
|
return ResponseEntity.ok("Permission removed from role.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------- Mapping --------------------
|
/* -------------------- Utils -------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a Role entity to a RoleDTO.
|
||||||
|
*
|
||||||
|
* @param role The Role entity to convert.
|
||||||
|
* @return The converted RoleDTO.
|
||||||
|
*/
|
||||||
private RoleDTO toDTO(Role role) {
|
private RoleDTO toDTO(Role role) {
|
||||||
Set<Integer> permissionIds = role.getPermissions().stream()
|
Set<Integer> permissionIds = role.getPermissions().stream()
|
||||||
.map(Permission::getId)
|
.map(Permission::getId)
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,10 @@ import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller for managing students.
|
||||||
|
* Provides endpoints for creating, retrieving, updating, and deleting students.
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/students")
|
@RequestMapping("/api/v1/students")
|
||||||
@Tag(name = "Student Management", description = "Operations related to student management")
|
@Tag(name = "Student Management", description = "Operations related to student management")
|
||||||
|
|
@ -42,9 +46,21 @@ public class StudentController {
|
||||||
private final MembershipService membershipService;
|
private final MembershipService membershipService;
|
||||||
private final TrainingSessionService trainingSessionService;
|
private final TrainingSessionService trainingSessionService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password encoder for encoding passwords.
|
||||||
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
private PasswordEncoder passwordEncoder;
|
private PasswordEncoder passwordEncoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for StudentController.
|
||||||
|
*
|
||||||
|
* @param studentService Service for handling student records.
|
||||||
|
* @param roleService Service for handling roles.
|
||||||
|
* @param userService Service for handling user records.
|
||||||
|
* @param membershipService Service for handling membership records.
|
||||||
|
* @param trainingSessionService Service for handling training session records.
|
||||||
|
*/
|
||||||
public StudentController(StudentService studentService, RoleService roleService, UserService userService, MembershipService membershipService, TrainingSessionService trainingSessionService) {
|
public StudentController(StudentService studentService, RoleService roleService, UserService userService, MembershipService membershipService, TrainingSessionService trainingSessionService) {
|
||||||
this.studentService = studentService;
|
this.studentService = studentService;
|
||||||
this.roleService = roleService;
|
this.roleService = roleService;
|
||||||
|
|
@ -53,6 +69,12 @@ public class StudentController {
|
||||||
this.trainingSessionService = trainingSessionService;
|
this.trainingSessionService = trainingSessionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a new student with the provided details.
|
||||||
|
*
|
||||||
|
* @param studentRegisterDTO The DTO containing the student's registration details.
|
||||||
|
* @return ResponseEntity containing the created StudentDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Register a new Student", description = "Registers a new student with the provided details.")
|
@Operation(summary = "Register a new Student", description = "Registers a new student with the provided details.")
|
||||||
@PostMapping("/register")
|
@PostMapping("/register")
|
||||||
public ResponseEntity<StudentDTO> registerStudent(@RequestBody @Valid StudentRegisterDTO studentRegisterDTO) {
|
public ResponseEntity<StudentDTO> registerStudent(@RequestBody @Valid StudentRegisterDTO studentRegisterDTO) {
|
||||||
|
|
@ -100,7 +122,11 @@ public class StudentController {
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(response);
|
return ResponseEntity.status(HttpStatus.CREATED).body(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all students.
|
||||||
|
*
|
||||||
|
* @return ResponseEntity containing a list of StudentDTOs.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get all Students", description = "Retrieves a list of all students.")
|
@Operation(summary = "Get all Students", description = "Retrieves a list of all students.")
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
public ResponseEntity<List<StudentDTO>> getAllStudents() {
|
public ResponseEntity<List<StudentDTO>> getAllStudents() {
|
||||||
|
|
@ -114,6 +140,12 @@ public class StudentController {
|
||||||
return ResponseEntity.ok(dtos);
|
return ResponseEntity.ok(dtos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new student with the provided details.
|
||||||
|
*
|
||||||
|
* @param dto The StudentDTO containing the details of the student to be created.
|
||||||
|
* @return ResponseEntity containing the created StudentDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Create a new Student", description = "Creates a new student with the provided details.")
|
@Operation(summary = "Create a new Student", description = "Creates a new student with the provided details.")
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public ResponseEntity<StudentDTO> createStudent(@RequestBody StudentDTO dto) {
|
public ResponseEntity<StudentDTO> createStudent(@RequestBody StudentDTO dto) {
|
||||||
|
|
@ -122,6 +154,13 @@ public class StudentController {
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(convertToDTO(saved));
|
return ResponseEntity.status(HttpStatus.CREATED).body(convertToDTO(saved));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing student with the provided details.
|
||||||
|
*
|
||||||
|
* @param id The ID of the student to update.
|
||||||
|
* @param dto The StudentDTO containing the updated details of the student.
|
||||||
|
* @return ResponseEntity containing the updated StudentDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Update an existing Student", description = "Updates the details of an existing student.")
|
@Operation(summary = "Update an existing Student", description = "Updates the details of an existing student.")
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
public ResponseEntity<StudentDTO> updateStudent(@PathVariable Integer id, @RequestBody StudentDTO dto) {
|
public ResponseEntity<StudentDTO> updateStudent(@PathVariable Integer id, @RequestBody StudentDTO dto) {
|
||||||
|
|
@ -131,6 +170,12 @@ public class StudentController {
|
||||||
return ResponseEntity.ok(convertToDTO(updated));
|
return ResponseEntity.ok(convertToDTO(updated));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a student by their ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the student to find.
|
||||||
|
* @return ResponseEntity containing the StudentDTO or not found if the ID does not exist.
|
||||||
|
*/
|
||||||
@Operation(summary = "Find a Student by ID", description = "Retrieves a student by their ID.")
|
@Operation(summary = "Find a Student by ID", description = "Retrieves a student by their ID.")
|
||||||
@GetMapping("/findById/{id}")
|
@GetMapping("/findById/{id}")
|
||||||
public ResponseEntity<StudentDTO> getStudentById(@PathVariable Integer id) {
|
public ResponseEntity<StudentDTO> getStudentById(@PathVariable Integer id) {
|
||||||
|
|
@ -138,6 +183,12 @@ public class StudentController {
|
||||||
return ResponseEntity.ok(convertToDTO(student));
|
return ResponseEntity.ok(convertToDTO(student));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a student by their ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the student to delete.
|
||||||
|
* @return ResponseEntity with a success message.
|
||||||
|
*/
|
||||||
@Operation(summary = "Delete a Student", description = "Deletes a student by their ID.")
|
@Operation(summary = "Delete a Student", description = "Deletes a student by their ID.")
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
public ResponseEntity<String> deleteStudent(@PathVariable Integer id) {
|
public ResponseEntity<String> deleteStudent(@PathVariable Integer id) {
|
||||||
|
|
@ -145,6 +196,13 @@ public class StudentController {
|
||||||
return ResponseEntity.ok("Student deleted successfully");
|
return ResponseEntity.ok("Student deleted successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a history record to a student by their ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the student to whom the history will be added.
|
||||||
|
* @param history The StudentHistory object containing the history details to be added.
|
||||||
|
* @return ResponseEntity with a success message.
|
||||||
|
*/
|
||||||
@Operation(summary = "Add a Student History", description = "Adds a history record to a student by their ID.")
|
@Operation(summary = "Add a Student History", description = "Adds a history record to a student by their ID.")
|
||||||
@PostMapping("/addStudentHistory/{id}")
|
@PostMapping("/addStudentHistory/{id}")
|
||||||
public ResponseEntity<String> addStudentHistory(@PathVariable Integer id, @RequestBody StudentHistory history) {
|
public ResponseEntity<String> addStudentHistory(@PathVariable Integer id, @RequestBody StudentHistory history) {
|
||||||
|
|
@ -153,6 +211,12 @@ public class StudentController {
|
||||||
return ResponseEntity.ok("Student history added successfully");
|
return ResponseEntity.ok("Student history added successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a history record from a student by their ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the history record to remove.
|
||||||
|
* @return ResponseEntity with a success message.
|
||||||
|
*/
|
||||||
@Operation(summary = "Remove a Student History", description = "Removes a history record from a student.")
|
@Operation(summary = "Remove a Student History", description = "Removes a history record from a student.")
|
||||||
@DeleteMapping("/removeStudentHistory/{id}")
|
@DeleteMapping("/removeStudentHistory/{id}")
|
||||||
public ResponseEntity<String> removeStudentHistory(@PathVariable Integer id) {
|
public ResponseEntity<String> removeStudentHistory(@PathVariable Integer id) {
|
||||||
|
|
@ -160,6 +224,13 @@ public class StudentController {
|
||||||
return ResponseEntity.ok("Student history removed successfully");
|
return ResponseEntity.ok("Student history removed successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a membership to a student by their ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the student to whom the membership will be added.
|
||||||
|
* @param membership The Membership object containing the membership details to be added.
|
||||||
|
* @return ResponseEntity with a success message.
|
||||||
|
*/
|
||||||
@Operation(summary = "Add a Membership to a Student", description = "Adds a membership to a student by their ID.")
|
@Operation(summary = "Add a Membership to a Student", description = "Adds a membership to a student by their ID.")
|
||||||
@PostMapping("/addMembershipToStudent/{id}")
|
@PostMapping("/addMembershipToStudent/{id}")
|
||||||
public ResponseEntity<String> addMembershipToStudent(@PathVariable Integer id, @RequestBody Membership membership) {
|
public ResponseEntity<String> addMembershipToStudent(@PathVariable Integer id, @RequestBody Membership membership) {
|
||||||
|
|
@ -168,6 +239,12 @@ public class StudentController {
|
||||||
return ResponseEntity.ok("Membership added to student successfully");
|
return ResponseEntity.ok("Membership added to student successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a membership from a student by their ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the student from whom the membership will be removed.
|
||||||
|
* @return ResponseEntity with a success message.
|
||||||
|
*/
|
||||||
@Operation(summary = "Remove a Membership from a Student", description = "Removes a membership from a student by their ID.")
|
@Operation(summary = "Remove a Membership from a Student", description = "Removes a membership from a student by their ID.")
|
||||||
@DeleteMapping("/removeMembershipFromStudent/{id}")
|
@DeleteMapping("/removeMembershipFromStudent/{id}")
|
||||||
public ResponseEntity<String> removeMembershipFromStudent(@PathVariable Integer id) {
|
public ResponseEntity<String> removeMembershipFromStudent(@PathVariable Integer id) {
|
||||||
|
|
@ -175,6 +252,13 @@ public class StudentController {
|
||||||
return ResponseEntity.ok("Membership removed from student successfully");
|
return ResponseEntity.ok("Membership removed from student successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an assistance record to a student by their ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the student to whom the assistance will be added.
|
||||||
|
* @param assistanceDTO The AssistanceDTO containing the details of the assistance to be added.
|
||||||
|
* @return ResponseEntity with a success message.
|
||||||
|
*/
|
||||||
@Operation(summary = "Add an Assistance to a Student", description = "Adds an assistance record to a student by their ID.")
|
@Operation(summary = "Add an Assistance to a Student", description = "Adds an assistance record to a student by their ID.")
|
||||||
@PostMapping("/addAssistanceToStudent/{id}")
|
@PostMapping("/addAssistanceToStudent/{id}")
|
||||||
public ResponseEntity<String> addAssistanceToStudent(@PathVariable Integer id, @RequestBody AssistanceDTO assistanceDTO) {
|
public ResponseEntity<String> addAssistanceToStudent(@PathVariable Integer id, @RequestBody AssistanceDTO assistanceDTO) {
|
||||||
|
|
@ -185,6 +269,13 @@ public class StudentController {
|
||||||
return ResponseEntity.ok("Assistance added to student successfully");
|
return ResponseEntity.ok("Assistance added to student successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes an assistance record from a student by their ID.
|
||||||
|
*
|
||||||
|
* @param studentId The ID of the student from whom the assistance will be removed.
|
||||||
|
* @param assistanceId The ID of the assistance record to remove.
|
||||||
|
* @return ResponseEntity with a success message.
|
||||||
|
*/
|
||||||
@Operation(summary = "Remove an Assistance from a Student", description = "Removes an assistance record from a student by their ID.")
|
@Operation(summary = "Remove an Assistance from a Student", description = "Removes an assistance record from a student by their ID.")
|
||||||
@DeleteMapping("/deleteAssistanceFromStudent/{id}")
|
@DeleteMapping("/deleteAssistanceFromStudent/{id}")
|
||||||
public ResponseEntity<String> deleteAssistanceFromStudent(@PathVariable Integer studentId, @PathVariable Integer assistanceId) {
|
public ResponseEntity<String> deleteAssistanceFromStudent(@PathVariable Integer studentId, @PathVariable Integer assistanceId) {
|
||||||
|
|
@ -192,6 +283,13 @@ public class StudentController {
|
||||||
return ResponseEntity.ok("Assistance removed from student successfully");
|
return ResponseEntity.ok("Assistance removed from student successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a training group to a student by their ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the student to whom the training group will be added.
|
||||||
|
* @param group The TrainingGroup object containing the details of the group to be added.
|
||||||
|
* @return ResponseEntity with a success message.
|
||||||
|
*/
|
||||||
@Operation(summary = "Add a Training Group to a Student", description = "Adds a training group to a student by their ID.")
|
@Operation(summary = "Add a Training Group to a Student", description = "Adds a training group to a student by their ID.")
|
||||||
@PostMapping("/addGroupToStudent/{id}")
|
@PostMapping("/addGroupToStudent/{id}")
|
||||||
public ResponseEntity<String> addGroupToStudent(@PathVariable Integer id, @RequestBody TrainingGroup group) {
|
public ResponseEntity<String> addGroupToStudent(@PathVariable Integer id, @RequestBody TrainingGroup group) {
|
||||||
|
|
@ -199,6 +297,13 @@ public class StudentController {
|
||||||
return ResponseEntity.ok("Training group added to student successfully");
|
return ResponseEntity.ok("Training group added to student successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates a student's membership by their ID.
|
||||||
|
*
|
||||||
|
* @param studentId The ID of the student whose membership will be updated.
|
||||||
|
* @param membershipId The ID of the membership to assign to the student.
|
||||||
|
* @return ResponseEntity indicating the result of the operation.
|
||||||
|
*/
|
||||||
@Operation(summary = "Update a student's membership")
|
@Operation(summary = "Update a student's membership")
|
||||||
@PutMapping("/updateMembership/{studentId}")
|
@PutMapping("/updateMembership/{studentId}")
|
||||||
public ResponseEntity<Void> updateMembership(
|
public ResponseEntity<Void> updateMembership(
|
||||||
|
|
@ -216,13 +321,26 @@ public class StudentController {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------- Mapping Methods ------------------ */
|
/* ----------------- Utils ------------------ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a Student entity to a StudentDTO.
|
||||||
|
*
|
||||||
|
* @param student The Student entity to convert.
|
||||||
|
* @return The converted StudentDTO.
|
||||||
|
*/
|
||||||
private StudentDTO convertToDTO(Student student) {
|
private StudentDTO convertToDTO(Student student) {
|
||||||
return StudentDTO.fromEntity(student);
|
return StudentDTO.fromEntity(student);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a StudentDTO to a Student entity.
|
||||||
|
*
|
||||||
|
* @param dto The StudentDTO to convert.
|
||||||
|
* @param isCreate Indicates if the conversion is for creating a new student.
|
||||||
|
* @return The converted Student entity.
|
||||||
|
*/
|
||||||
private Student convertToEntity(StudentDTO dto, boolean isCreate) {
|
private Student convertToEntity(StudentDTO dto, boolean isCreate) {
|
||||||
if (dto == null || dto.getUser() == null) {
|
if (dto == null || dto.getUser() == null) {
|
||||||
throw new InvalidDataException("User data is required");
|
throw new InvalidDataException("User data is required");
|
||||||
|
|
@ -271,5 +389,4 @@ public class StudentController {
|
||||||
|
|
||||||
return student;
|
return student;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,10 @@ import org.springframework.web.bind.annotation.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* StudentHistoryController handles requests related to student history management.
|
||||||
|
* It provides endpoints for creating, retrieving, updating, and deleting student histories.
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/student-history")
|
@RequestMapping("/api/v1/student-history")
|
||||||
@Tag(name = "Student History Management", description = "Operations related to student history")
|
@Tag(name = "Student History Management", description = "Operations related to student history")
|
||||||
|
|
@ -21,11 +25,22 @@ public class StudentHistoryController {
|
||||||
private final StudentHistoryService studentHistoryService;
|
private final StudentHistoryService studentHistoryService;
|
||||||
private final StudentService studentService;
|
private final StudentService studentService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for StudentHistoryController.
|
||||||
|
*
|
||||||
|
* @param studentHistoryService Service for handling student history records.
|
||||||
|
* @param studentService Service for handling student records.
|
||||||
|
*/
|
||||||
public StudentHistoryController(StudentHistoryService studentHistoryService, StudentService studentService) {
|
public StudentHistoryController(StudentHistoryService studentHistoryService, StudentService studentService) {
|
||||||
this.studentHistoryService = studentHistoryService;
|
this.studentHistoryService = studentHistoryService;
|
||||||
this.studentService = studentService;
|
this.studentService = studentService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all student histories and returns them as a list of DTOs.
|
||||||
|
*
|
||||||
|
* @return ResponseEntity containing a list of StudentHistoryDTOs or no content if none found.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get all student histories", description = "Retrieve a list of all student histories")
|
@Operation(summary = "Get all student histories", description = "Retrieve a list of all student histories")
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
public ResponseEntity<List<StudentHistoryDTO>> getAll() {
|
public ResponseEntity<List<StudentHistoryDTO>> getAll() {
|
||||||
|
|
@ -36,6 +51,12 @@ public class StudentHistoryController {
|
||||||
return ResponseEntity.ok(dtos);
|
return ResponseEntity.ok(dtos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a student history by its ID and returns it as a DTO.
|
||||||
|
*
|
||||||
|
* @param id The ID of the student history to find.
|
||||||
|
* @return ResponseEntity containing the StudentHistoryDTO or not found if it doesn't exist.
|
||||||
|
*/
|
||||||
@Operation(summary = "find student history by ID", description = "Retrieve a student history by its ID")
|
@Operation(summary = "find student history by ID", description = "Retrieve a student history by its ID")
|
||||||
@GetMapping("/findById/{id}")
|
@GetMapping("/findById/{id}")
|
||||||
public ResponseEntity<StudentHistoryDTO> findById(@PathVariable Integer id) {
|
public ResponseEntity<StudentHistoryDTO> findById(@PathVariable Integer id) {
|
||||||
|
|
@ -43,6 +64,12 @@ public class StudentHistoryController {
|
||||||
return ResponseEntity.ok(toDTO(history));
|
return ResponseEntity.ok(toDTO(history));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new student history and returns the created history as a DTO.
|
||||||
|
*
|
||||||
|
* @param dto The StudentHistoryDTO containing the details of the history to be created.
|
||||||
|
* @return ResponseEntity containing the created StudentHistoryDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Create a new student history", description = "Create a new student history")
|
@Operation(summary = "Create a new student history", description = "Create a new student history")
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public ResponseEntity<StudentHistoryDTO> create(@RequestBody StudentHistoryDTO dto) {
|
public ResponseEntity<StudentHistoryDTO> create(@RequestBody StudentHistoryDTO dto) {
|
||||||
|
|
@ -51,6 +78,13 @@ public class StudentHistoryController {
|
||||||
return ResponseEntity.status(201).body(toDTO(saved));
|
return ResponseEntity.status(201).body(toDTO(saved));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing student history and returns the updated history as a DTO.
|
||||||
|
*
|
||||||
|
* @param id The ID of the student history to update.
|
||||||
|
* @param dto The StudentHistoryDTO containing the updated details.
|
||||||
|
* @return ResponseEntity containing the updated StudentHistoryDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Update an existing student history", description = "Update an existing student history")
|
@Operation(summary = "Update an existing student history", description = "Update an existing student history")
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
public ResponseEntity<StudentHistoryDTO> update(@PathVariable Integer id, @RequestBody StudentHistoryDTO dto) {
|
public ResponseEntity<StudentHistoryDTO> update(@PathVariable Integer id, @RequestBody StudentHistoryDTO dto) {
|
||||||
|
|
@ -60,6 +94,12 @@ public class StudentHistoryController {
|
||||||
return ResponseEntity.ok(toDTO(updated));
|
return ResponseEntity.ok(toDTO(updated));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a student history by its ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the student history to delete.
|
||||||
|
* @return ResponseEntity with a success message.
|
||||||
|
*/
|
||||||
@Operation(summary = "Delete a student history", description = "Delete a student history by its ID")
|
@Operation(summary = "Delete a student history", description = "Delete a student history by its ID")
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
public ResponseEntity<String> delete(@PathVariable Integer id) {
|
public ResponseEntity<String> delete(@PathVariable Integer id) {
|
||||||
|
|
@ -67,8 +107,14 @@ public class StudentHistoryController {
|
||||||
return ResponseEntity.ok("Student history deleted successfully.");
|
return ResponseEntity.ok("Student history deleted successfully.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------- Mapping --------------------
|
/* -------------------- Utils -------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a StudentHistory entity to a StudentHistoryDTO.
|
||||||
|
*
|
||||||
|
* @param history The StudentHistory entity to convert.
|
||||||
|
* @return The converted StudentHistoryDTO.
|
||||||
|
*/
|
||||||
private StudentHistoryDTO toDTO(StudentHistory history) {
|
private StudentHistoryDTO toDTO(StudentHistory history) {
|
||||||
return new StudentHistoryDTO(
|
return new StudentHistoryDTO(
|
||||||
history.getId(),
|
history.getId(),
|
||||||
|
|
@ -79,6 +125,13 @@ public class StudentHistoryController {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a StudentHistoryDTO to a StudentHistory entity.
|
||||||
|
*
|
||||||
|
* @param dto The StudentHistoryDTO to convert.
|
||||||
|
* @param includeExistingStudent Whether to include the existing student in the history.
|
||||||
|
* @return The converted StudentHistory entity.
|
||||||
|
*/
|
||||||
private StudentHistory toEntity(StudentHistoryDTO dto, boolean includeExistingStudent) {
|
private StudentHistory toEntity(StudentHistoryDTO dto, boolean includeExistingStudent) {
|
||||||
StudentHistory history = (dto.getId() != null)
|
StudentHistory history = (dto.getId() != null)
|
||||||
? studentHistoryService.findById(dto.getId())
|
? studentHistoryService.findById(dto.getId())
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@ import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller for managing teachers.
|
||||||
|
* Provides endpoints for creating, retrieving, updating, and deleting teachers.
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/teachers")
|
@RequestMapping("/api/v1/teachers")
|
||||||
@Tag(name = "Teacher Management", description = "Operations related to teachers")
|
@Tag(name = "Teacher Management", description = "Operations related to teachers")
|
||||||
|
|
@ -26,14 +30,28 @@ public class TeacherController {
|
||||||
private final TeacherService teacherService;
|
private final TeacherService teacherService;
|
||||||
private final RoleService roleService;
|
private final RoleService roleService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password encoder for encoding passwords.
|
||||||
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
private PasswordEncoder passwordEncoder;
|
private PasswordEncoder passwordEncoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for TeacherController.
|
||||||
|
*
|
||||||
|
* @param teacherService Service for handling teacher records.
|
||||||
|
* @param roleService Service for handling roles.
|
||||||
|
*/
|
||||||
public TeacherController(TeacherService teacherService, RoleService roleService) {
|
public TeacherController(TeacherService teacherService, RoleService roleService) {
|
||||||
this.teacherService = teacherService;
|
this.teacherService = teacherService;
|
||||||
this.roleService = roleService;
|
this.roleService = roleService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all teachers and returns them as a list of DTOs.
|
||||||
|
*
|
||||||
|
* @return ResponseEntity containing a list of TeacherDTOs or no content if none found.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get all teachers", description = "Retrieve a list of all teachers")
|
@Operation(summary = "Get all teachers", description = "Retrieve a list of all teachers")
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
public ResponseEntity<List<TeacherDTO>> getAllTeachers() {
|
public ResponseEntity<List<TeacherDTO>> getAllTeachers() {
|
||||||
|
|
@ -49,6 +67,12 @@ public class TeacherController {
|
||||||
return ResponseEntity.ok(dtos);
|
return ResponseEntity.ok(dtos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new teacher and returns the created teacher as a DTO.
|
||||||
|
*
|
||||||
|
* @param dto The TeacherDTO containing the details of the teacher to be created.
|
||||||
|
* @return ResponseEntity containing the created TeacherDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Create a new teacher", description = "Create a new teacher")
|
@Operation(summary = "Create a new teacher", description = "Create a new teacher")
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public ResponseEntity<TeacherDTO> createTeacher(@RequestBody TeacherDTO dto) {
|
public ResponseEntity<TeacherDTO> createTeacher(@RequestBody TeacherDTO dto) {
|
||||||
|
|
@ -57,6 +81,12 @@ public class TeacherController {
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(convertToDTO(saved));
|
return ResponseEntity.status(HttpStatus.CREATED).body(convertToDTO(saved));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a teacher by their ID and returns it as a DTO.
|
||||||
|
*
|
||||||
|
* @param id The ID of the teacher to find.
|
||||||
|
* @return ResponseEntity containing the TeacherDTO or not found if it doesn't exist.
|
||||||
|
*/
|
||||||
@Operation(summary = "Find a teacher by ID", description = "Retrieve a teacher by their ID")
|
@Operation(summary = "Find a teacher by ID", description = "Retrieve a teacher by their ID")
|
||||||
@GetMapping("/findById/{id}")
|
@GetMapping("/findById/{id}")
|
||||||
public ResponseEntity<TeacherDTO> findById(@PathVariable Integer id) {
|
public ResponseEntity<TeacherDTO> findById(@PathVariable Integer id) {
|
||||||
|
|
@ -67,6 +97,13 @@ public class TeacherController {
|
||||||
return ResponseEntity.ok(convertToDTO(teacher));
|
return ResponseEntity.ok(convertToDTO(teacher));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing teacher and returns the updated teacher as a DTO.
|
||||||
|
*
|
||||||
|
* @param id The ID of the teacher to update.
|
||||||
|
* @param dto The TeacherDTO containing the updated details of the teacher.
|
||||||
|
* @return ResponseEntity containing the updated TeacherDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Update a teacher", description = "Update an existing teacher")
|
@Operation(summary = "Update a teacher", description = "Update an existing teacher")
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
public ResponseEntity<TeacherDTO> updateTeacher(@PathVariable Integer id, @RequestBody TeacherDTO dto) {
|
public ResponseEntity<TeacherDTO> updateTeacher(@PathVariable Integer id, @RequestBody TeacherDTO dto) {
|
||||||
|
|
@ -76,7 +113,12 @@ public class TeacherController {
|
||||||
return ResponseEntity.ok(convertToDTO(updated));
|
return ResponseEntity.ok(convertToDTO(updated));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a teacher by their ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the teacher to delete.
|
||||||
|
* @return ResponseEntity with a success message.
|
||||||
|
*/
|
||||||
@Operation(summary = "Delete a teacher", description = "Delete a teacher by their ID")
|
@Operation(summary = "Delete a teacher", description = "Delete a teacher by their ID")
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
public ResponseEntity<String> deleteTeacher(@PathVariable Integer id) {
|
public ResponseEntity<String> deleteTeacher(@PathVariable Integer id) {
|
||||||
|
|
@ -84,12 +126,25 @@ public class TeacherController {
|
||||||
return ResponseEntity.ok("Teacher deleted successfully");
|
return ResponseEntity.ok("Teacher deleted successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------- Mapping ------------------
|
/* ----------------- Utils ------------------ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a Teacher entity to a TeacherDTO.
|
||||||
|
*
|
||||||
|
* @param teacher The Teacher entity to convert.
|
||||||
|
* @return The converted TeacherDTO.
|
||||||
|
*/
|
||||||
private TeacherDTO convertToDTO(Teacher teacher) {
|
private TeacherDTO convertToDTO(Teacher teacher) {
|
||||||
return TeacherDTO.fromEntity(teacher);
|
return TeacherDTO.fromEntity(teacher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a TeacherDTO to a Teacher entity.
|
||||||
|
*
|
||||||
|
* @param dto The TeacherDTO to convert.
|
||||||
|
* @param isCreate Indicates if this is a creation operation (true) or an update (false).
|
||||||
|
* @return The converted Teacher entity.
|
||||||
|
*/
|
||||||
private Teacher convertToEntity(TeacherDTO dto, boolean isCreate) {
|
private Teacher convertToEntity(TeacherDTO dto, boolean isCreate) {
|
||||||
if (dto == null || dto.getUser() == null) {
|
if (dto == null || dto.getUser() == null) {
|
||||||
throw new InvalidDataException("User data is required");
|
throw new InvalidDataException("User data is required");
|
||||||
|
|
@ -133,5 +188,4 @@ public class TeacherController {
|
||||||
|
|
||||||
return teacher;
|
return teacher;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,15 +38,30 @@ public class UserController {
|
||||||
private final RoleService roleService;
|
private final RoleService roleService;
|
||||||
private final JwtUtil jwtUtil;
|
private final JwtUtil jwtUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password encoder for encoding passwords.
|
||||||
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
private PasswordEncoder passwordEncoder;
|
private PasswordEncoder passwordEncoder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for UserController.
|
||||||
|
*
|
||||||
|
* @param userService Service for handling user records.
|
||||||
|
* @param roleService Service for handling roles.
|
||||||
|
* @param jwtUtil Utility for JWT operations.
|
||||||
|
*/
|
||||||
public UserController(UserService userService, RoleService roleService, JwtUtil jwtUtil) {
|
public UserController(UserService userService, RoleService roleService, JwtUtil jwtUtil) {
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
this.roleService = roleService;
|
this.roleService = roleService;
|
||||||
this.jwtUtil = jwtUtil;
|
this.jwtUtil = jwtUtil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all users and returns them as a list of DTOs.
|
||||||
|
*
|
||||||
|
* @return ResponseEntity containing a list of UserDTOs or no content if none found.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get all users", description = "Retrieve a list of all users")
|
@Operation(summary = "Get all users", description = "Retrieve a list of all users")
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
public ResponseEntity<List<UserDTO>> getAllUsers() {
|
public ResponseEntity<List<UserDTO>> getAllUsers() {
|
||||||
|
|
@ -62,6 +77,12 @@ public class UserController {
|
||||||
return ResponseEntity.ok(userDTOs);
|
return ResponseEntity.ok(userDTOs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a user by their ID and returns it as a DTO.
|
||||||
|
*
|
||||||
|
* @param id The ID of the user to find.
|
||||||
|
* @return ResponseEntity containing the UserDTO or not found if the ID does not exist.
|
||||||
|
*/
|
||||||
@Operation(summary = "Find a User by ID", description = "Retrieve a user by their ID")
|
@Operation(summary = "Find a User by ID", description = "Retrieve a user by their ID")
|
||||||
@GetMapping("/getById/{id}")
|
@GetMapping("/getById/{id}")
|
||||||
public ResponseEntity<UserDTO> getUserById(@PathVariable Integer id) {
|
public ResponseEntity<UserDTO> getUserById(@PathVariable Integer id) {
|
||||||
|
|
@ -69,7 +90,13 @@ public class UserController {
|
||||||
return ResponseEntity.ok(convertToDTO(user));
|
return ResponseEntity.ok(convertToDTO(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation( summary = "Find a User by email", description = "Retrieve a user by their email")
|
/**
|
||||||
|
* Creates a new user and returns the created user as a DTO.
|
||||||
|
*
|
||||||
|
* @param userDTO The UserDTO containing the details of the user to be created.
|
||||||
|
* @return ResponseEntity containing the created UserDTO with status 201 Created.
|
||||||
|
*/
|
||||||
|
@Operation(summary = "Create a new User", description = "Create a new user")
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
public ResponseEntity<UserDTO> createUser(@RequestBody UserDTO userDTO) {
|
public ResponseEntity<UserDTO> createUser(@RequestBody UserDTO userDTO) {
|
||||||
User user = convertToEntity(userDTO, true);
|
User user = convertToEntity(userDTO, true);
|
||||||
|
|
@ -77,6 +104,13 @@ public class UserController {
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(convertToDTO(saved));
|
return ResponseEntity.status(HttpStatus.CREATED).body(convertToDTO(saved));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing user by ID and returns the updated user as a DTO.
|
||||||
|
*
|
||||||
|
* @param id The ID of the user to update.
|
||||||
|
* @param userDTO The UserDTO containing the updated details of the user.
|
||||||
|
* @return ResponseEntity containing the updated UserDTO.
|
||||||
|
*/
|
||||||
@Operation(summary = "Update a user by ID", description = "Update an existing user")
|
@Operation(summary = "Update a user by ID", description = "Update an existing user")
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
public ResponseEntity<UserDTO> updateUser(@PathVariable Integer id, @RequestBody UserDTO userDTO) {
|
public ResponseEntity<UserDTO> updateUser(@PathVariable Integer id, @RequestBody UserDTO userDTO) {
|
||||||
|
|
@ -86,13 +120,25 @@ public class UserController {
|
||||||
return ResponseEntity.ok(convertToDTO(updated));
|
return ResponseEntity.ok(convertToDTO(updated));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "Update a user by email", description = "Update an existing user")
|
/**
|
||||||
|
* Deletes a user by ID.
|
||||||
|
*
|
||||||
|
* @param id The ID of the user to delete.
|
||||||
|
* @return ResponseEntity with a success message.
|
||||||
|
*/
|
||||||
|
@Operation(summary = "Delete User by Id", description = "Delete a user by ID")
|
||||||
@DeleteMapping("/delete/{id}")
|
@DeleteMapping("/delete/{id}")
|
||||||
public ResponseEntity<String> deleteUser(@PathVariable Integer id) {
|
public ResponseEntity<String> deleteUser(@PathVariable Integer id) {
|
||||||
userService.deleteById(id);
|
userService.deleteById(id);
|
||||||
return ResponseEntity.ok("User deleted successfully");
|
return ResponseEntity.ok("User deleted successfully");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the currently authenticated user based on the JWT token from the request.
|
||||||
|
*
|
||||||
|
* @param request The HTTP request containing the JWT token.
|
||||||
|
* @return ResponseEntity containing the UserDTO of the current user.
|
||||||
|
*/
|
||||||
@Operation(summary = "Get current user", description = "Retrieve the currently authenticated user")
|
@Operation(summary = "Get current user", description = "Retrieve the currently authenticated user")
|
||||||
@GetMapping("/me")
|
@GetMapping("/me")
|
||||||
public ResponseEntity<UserDTO> getCurrentUser(HttpServletRequest request) {
|
public ResponseEntity<UserDTO> getCurrentUser(HttpServletRequest request) {
|
||||||
|
|
@ -103,8 +149,15 @@ public class UserController {
|
||||||
return ResponseEntity.ok(convertToDTO(user));
|
return ResponseEntity.ok(convertToDTO(user));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------ UTILS ------------------
|
/* ------------------ UTILS ------------------ */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the JWT token from the Authorization header of the request.
|
||||||
|
*
|
||||||
|
* @param request The HTTP request containing the Authorization header.
|
||||||
|
* @return The extracted JWT token.
|
||||||
|
* @throws InvalidDataException if the Authorization header is missing or invalid.
|
||||||
|
*/
|
||||||
private String extractTokenFromRequest(HttpServletRequest request) {
|
private String extractTokenFromRequest(HttpServletRequest request) {
|
||||||
String authHeader = request.getHeader("Authorization");
|
String authHeader = request.getHeader("Authorization");
|
||||||
if (authHeader == null || !authHeader.startsWith("Bearer ")) {
|
if (authHeader == null || !authHeader.startsWith("Bearer ")) {
|
||||||
|
|
@ -113,6 +166,12 @@ public class UserController {
|
||||||
return authHeader.substring(7); // Remove "Bearer "
|
return authHeader.substring(7); // Remove "Bearer "
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a User entity to a UserDTO.
|
||||||
|
*
|
||||||
|
* @param user The User entity to convert.
|
||||||
|
* @return The converted UserDTO.
|
||||||
|
*/
|
||||||
private UserDTO convertToDTO(User user) {
|
private UserDTO convertToDTO(User user) {
|
||||||
UserDTO dto = new UserDTO(
|
UserDTO dto = new UserDTO(
|
||||||
user.getId(),
|
user.getId(),
|
||||||
|
|
@ -156,6 +215,12 @@ public class UserController {
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a Notification entity to a NotificationMiniDTO.
|
||||||
|
*
|
||||||
|
* @param notification The Notification entity to convert.
|
||||||
|
* @return The converted NotificationMiniDTO.
|
||||||
|
*/
|
||||||
private NotificationMiniDTO convertNotificationToMiniDTO(Notification notification) {
|
private NotificationMiniDTO convertNotificationToMiniDTO(Notification notification) {
|
||||||
return new NotificationMiniDTO(
|
return new NotificationMiniDTO(
|
||||||
notification.getId(),
|
notification.getId(),
|
||||||
|
|
@ -166,6 +231,14 @@ public class UserController {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a UserDTO to a User entity.
|
||||||
|
*
|
||||||
|
* @param dto The UserDTO to convert.
|
||||||
|
* @param isCreate Indicates if the conversion is for creation (true) or update (false).
|
||||||
|
* @return The converted User entity.
|
||||||
|
* @throws InvalidDataException if the provided data is invalid.
|
||||||
|
*/
|
||||||
private User convertToEntity(UserDTO dto, boolean isCreate) {
|
private User convertToEntity(UserDTO dto, boolean isCreate) {
|
||||||
User user;
|
User user;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
package com.denniseckerskorn.dtos.class_managment_dtos;
|
package com.denniseckerskorn.dtos.class_managment_dtos;
|
||||||
|
|
||||||
|
|
||||||
import com.denniseckerskorn.entities.class_managment.Assistance;
|
import com.denniseckerskorn.entities.class_managment.Assistance;
|
||||||
import com.denniseckerskorn.entities.class_managment.TrainingSession;
|
import com.denniseckerskorn.entities.class_managment.TrainingSession;
|
||||||
import com.denniseckerskorn.entities.user_managment.users.Student;
|
import com.denniseckerskorn.entities.user_managment.users.Student;
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ public class CreateInvoiceLineDTO {
|
||||||
this.unitPrice = unitPrice;
|
this.unitPrice = unitPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convierte a entidad con parámetros necesarios
|
|
||||||
public InvoiceLine toEntity(Invoice invoice, ProductService productService) {
|
public InvoiceLine toEntity(Invoice invoice, ProductService productService) {
|
||||||
InvoiceLine entity = new InvoiceLine();
|
InvoiceLine entity = new InvoiceLine();
|
||||||
entity.setInvoice(invoice);
|
entity.setInvoice(invoice);
|
||||||
|
|
@ -47,11 +46,10 @@ public class CreateInvoiceLineDTO {
|
||||||
entity.setQuantity(this.quantity);
|
entity.setQuantity(this.quantity);
|
||||||
entity.setUnitPrice(this.unitPrice);
|
entity.setUnitPrice(this.unitPrice);
|
||||||
entity.setSubtotal(this.unitPrice.multiply(BigDecimal.valueOf(this.quantity)));
|
entity.setSubtotal(this.unitPrice.multiply(BigDecimal.valueOf(this.quantity)));
|
||||||
entity.setDescription(productService.getName()); // opcional
|
entity.setDescription(productService.getName());
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convierte desde una entidad (opcional)
|
|
||||||
public static CreateInvoiceLineDTO fromEntity(InvoiceLine entity) {
|
public static CreateInvoiceLineDTO fromEntity(InvoiceLine entity) {
|
||||||
CreateInvoiceLineDTO dto = new CreateInvoiceLineDTO();
|
CreateInvoiceLineDTO dto = new CreateInvoiceLineDTO();
|
||||||
dto.setProductServiceId(entity.getProductService() != null ? entity.getProductService().getId() : null);
|
dto.setProductServiceId(entity.getProductService() != null ? entity.getProductService().getId() : null);
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,6 @@ public class CreateInvoiceRequestDTO {
|
||||||
public CreateInvoiceRequestDTO() {
|
public CreateInvoiceRequestDTO() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters y setters
|
|
||||||
|
|
||||||
public Integer getUserId() {
|
public Integer getUserId() {
|
||||||
return userId;
|
return userId;
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +60,6 @@ public class CreateInvoiceRequestDTO {
|
||||||
this.lines = lines;
|
this.lines = lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convierte el DTO a entidad base (sin líneas, requiere setUser)
|
|
||||||
public Invoice toEntity(User user) {
|
public Invoice toEntity(User user) {
|
||||||
Invoice invoice = new Invoice();
|
Invoice invoice = new Invoice();
|
||||||
invoice.setUser(user);
|
invoice.setUser(user);
|
||||||
|
|
@ -72,7 +69,6 @@ public class CreateInvoiceRequestDTO {
|
||||||
return invoice;
|
return invoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea el DTO desde una entidad (opcional)
|
|
||||||
public static CreateInvoiceRequestDTO fromEntity(Invoice invoice) {
|
public static CreateInvoiceRequestDTO fromEntity(Invoice invoice) {
|
||||||
CreateInvoiceRequestDTO dto = new CreateInvoiceRequestDTO();
|
CreateInvoiceRequestDTO dto = new CreateInvoiceRequestDTO();
|
||||||
dto.setUserId(invoice.getUser() != null ? invoice.getUser().getId().intValue() : null);
|
dto.setUserId(invoice.getUser() != null ? invoice.getUser().getId().intValue() : null);
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@ public class IVATypeDTO {
|
||||||
|
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
public IVATypeDTO() {}
|
public IVATypeDTO() {
|
||||||
|
}
|
||||||
|
|
||||||
public IVATypeDTO(IVAType entity) {
|
public IVATypeDTO(IVAType entity) {
|
||||||
this.id = entity.getId();
|
this.id = entity.getId();
|
||||||
|
|
@ -34,9 +35,6 @@ public class IVATypeDTO {
|
||||||
return iva;
|
return iva;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters y setters...
|
|
||||||
|
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,9 +63,6 @@ public class InvoiceDTO {
|
||||||
return invoice;
|
return invoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters y setters (puedes generarlos automáticamente)
|
|
||||||
|
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,8 @@ public class InvoiceLineDTO {
|
||||||
|
|
||||||
private BigDecimal subtotal;
|
private BigDecimal subtotal;
|
||||||
|
|
||||||
public InvoiceLineDTO() {}
|
public InvoiceLineDTO() {
|
||||||
|
}
|
||||||
|
|
||||||
public InvoiceLineDTO(InvoiceLine entity) {
|
public InvoiceLineDTO(InvoiceLine entity) {
|
||||||
this.id = entity.getId();
|
this.id = entity.getId();
|
||||||
|
|
@ -51,9 +52,6 @@ public class InvoiceLineDTO {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters y setters...
|
|
||||||
|
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -67,10 +67,6 @@ public class PaymentDTO {
|
||||||
return payment;
|
return payment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Getters y setters...
|
|
||||||
|
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,8 +70,6 @@ public class ProductServiceDTO {
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters y setters
|
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,6 @@ public class AdminDTO {
|
||||||
this.user = user;
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------ Métodos de conversión ------------
|
|
||||||
|
|
||||||
public static AdminDTO fromEntity(Admin admin) {
|
public static AdminDTO fromEntity(Admin admin) {
|
||||||
if (admin == null || admin.getUser() == null) {
|
if (admin == null || admin.getUser() == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@ public class NotificationDTO {
|
||||||
private StatusValues status;
|
private StatusValues status;
|
||||||
private Set<Integer> userIds;
|
private Set<Integer> userIds;
|
||||||
|
|
||||||
public NotificationDTO() {}
|
public NotificationDTO() {
|
||||||
|
}
|
||||||
|
|
||||||
public NotificationDTO(Integer id, String title, String message, LocalDateTime shippingDate, String type, StatusValues status, Set<Integer> userIds) {
|
public NotificationDTO(Integer id, String title, String message, LocalDateTime shippingDate, String type, StatusValues status, Set<Integer> userIds) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ public class NotificationMiniDTO {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters y setters
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -109,8 +109,6 @@ public class StudentDTO {
|
||||||
return student;
|
return student;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters y Setters...
|
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ public class StudentHistoryMiniDTO {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters y setters
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,10 @@ import java.util.Set;
|
||||||
|
|
||||||
public class StudentMiniDTO {
|
public class StudentMiniDTO {
|
||||||
private Integer id;
|
private Integer id;
|
||||||
private Set<StudentHistoryMiniDTO> histories; // 🔥 mini DTO
|
private Set<StudentHistoryMiniDTO> histories;
|
||||||
|
|
||||||
public StudentMiniDTO() {}
|
public StudentMiniDTO() {
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,19 @@
|
||||||
package com.denniseckerskorn.dtos.user_managment_dtos;
|
package com.denniseckerskorn.dtos.user_managment_dtos;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
|
||||||
public class StudentRegisterDTO {
|
public class StudentRegisterDTO {
|
||||||
|
|
||||||
// Datos de usuario
|
|
||||||
private String name;
|
private String name;
|
||||||
private String surname;
|
private String surname;
|
||||||
private String email;
|
private String email;
|
||||||
private String password;
|
private String password;
|
||||||
private String phoneNumber;
|
private String phoneNumber;
|
||||||
private String address;
|
private String address;
|
||||||
private String roleName; // ejemplo: "ROLE_STUDENT"
|
private String roleName;
|
||||||
private String status; // ejemplo: "ACTIVE"
|
private String status;
|
||||||
|
|
||||||
// Datos de estudiante
|
|
||||||
private String dni;
|
private String dni;
|
||||||
|
|
||||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
|
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
|
||||||
|
|
@ -27,89 +25,115 @@ public class StudentRegisterDTO {
|
||||||
private String parentName;
|
private String parentName;
|
||||||
private Integer membershipId;
|
private Integer membershipId;
|
||||||
|
|
||||||
// --- Getters y Setters ---
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSurname() {
|
public String getSurname() {
|
||||||
return surname;
|
return surname;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSurname(String surname) {
|
public void setSurname(String surname) {
|
||||||
this.surname = surname;
|
this.surname = surname;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getEmail() {
|
public String getEmail() {
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEmail(String email) {
|
public void setEmail(String email) {
|
||||||
this.email = email;
|
this.email = email;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
public String getPassword() {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassword(String password) {
|
public void setPassword(String password) {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPhoneNumber() {
|
public String getPhoneNumber() {
|
||||||
return phoneNumber;
|
return phoneNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPhoneNumber(String phoneNumber) {
|
public void setPhoneNumber(String phoneNumber) {
|
||||||
this.phoneNumber = phoneNumber;
|
this.phoneNumber = phoneNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAddress() {
|
public String getAddress() {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAddress(String address) {
|
public void setAddress(String address) {
|
||||||
this.address = address;
|
this.address = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRoleName() {
|
public String getRoleName() {
|
||||||
return roleName;
|
return roleName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRoleName(String roleName) {
|
public void setRoleName(String roleName) {
|
||||||
this.roleName = roleName;
|
this.roleName = roleName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStatus() {
|
public String getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus(String status) {
|
public void setStatus(String status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDni() {
|
public String getDni() {
|
||||||
return dni;
|
return dni;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDni(String dni) {
|
public void setDni(String dni) {
|
||||||
this.dni = dni;
|
this.dni = dni;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocalDate getBirthdate() {
|
public LocalDate getBirthdate() {
|
||||||
return birthdate;
|
return birthdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBirthdate(LocalDate birthdate) {
|
public void setBirthdate(LocalDate birthdate) {
|
||||||
this.birthdate = birthdate;
|
this.birthdate = birthdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBelt() {
|
public String getBelt() {
|
||||||
return belt;
|
return belt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBelt(String belt) {
|
public void setBelt(String belt) {
|
||||||
this.belt = belt;
|
this.belt = belt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProgress() {
|
public String getProgress() {
|
||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProgress(String progress) {
|
public void setProgress(String progress) {
|
||||||
this.progress = progress;
|
this.progress = progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMedicalReport() {
|
public String getMedicalReport() {
|
||||||
return medicalReport;
|
return medicalReport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMedicalReport(String medicalReport) {
|
public void setMedicalReport(String medicalReport) {
|
||||||
this.medicalReport = medicalReport;
|
this.medicalReport = medicalReport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getParentName() {
|
public String getParentName() {
|
||||||
return parentName;
|
return parentName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setParentName(String parentName) {
|
public void setParentName(String parentName) {
|
||||||
this.parentName = parentName;
|
this.parentName = parentName;
|
||||||
}
|
}
|
||||||
|
|
@ -117,9 +141,9 @@ public class StudentRegisterDTO {
|
||||||
public Integer getMembershipId() {
|
public Integer getMembershipId() {
|
||||||
return membershipId;
|
return membershipId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMembershipId(Integer membershipId) {
|
public void setMembershipId(Integer membershipId) {
|
||||||
this.membershipId = membershipId;
|
this.membershipId = membershipId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,6 @@ public class TeacherDTO {
|
||||||
this.discipline = discipline;
|
this.discipline = discipline;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters y Setters
|
|
||||||
|
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,6 @@ public class UserDTO {
|
||||||
private LocalDateTime registerDate;
|
private LocalDateTime registerDate;
|
||||||
private String roleName;
|
private String roleName;
|
||||||
private StatusValues status;
|
private StatusValues status;
|
||||||
|
|
||||||
// 🔥 Nuevos campos para el perfil completo
|
|
||||||
private Set<NotificationMiniDTO> notifications;
|
private Set<NotificationMiniDTO> notifications;
|
||||||
private StudentMiniDTO student;
|
private StudentMiniDTO student;
|
||||||
|
|
||||||
|
|
@ -54,8 +52,6 @@ public class UserDTO {
|
||||||
this.status = user.getStatus();
|
this.status = user.getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Getters y Setters
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
@ -152,7 +148,6 @@ public class UserDTO {
|
||||||
this.student = student;
|
this.student = student;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Conversión (opcional)
|
|
||||||
public static UserDTO fromEntity(User user) {
|
public static UserDTO fromEntity(User user) {
|
||||||
if (user == null) return null;
|
if (user == null) return null;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,10 @@ import org.springframework.web.servlet.resource.NoResourceFoundException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GlobalExceptionHandler handles exceptions thrown by the application.
|
||||||
|
* It provides a centralized way to manage error responses for various exceptions.
|
||||||
|
*/
|
||||||
@ControllerAdvice
|
@ControllerAdvice
|
||||||
public class GlobalExceptionHandler {
|
public class GlobalExceptionHandler {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,10 @@ import org.springframework.stereotype.Service;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* InvoicePdfGenerator is a service that generates a PDF representation of an Invoice.
|
||||||
|
* It uses iText library to create the PDF document with invoice details.
|
||||||
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class InvoicePdfGenerator {
|
public class InvoicePdfGenerator {
|
||||||
|
|
||||||
|
|
@ -23,20 +27,20 @@ public class InvoicePdfGenerator {
|
||||||
PdfDocument pdf = new PdfDocument(writer);
|
PdfDocument pdf = new PdfDocument(writer);
|
||||||
Document doc = new Document(pdf);
|
Document doc = new Document(pdf);
|
||||||
|
|
||||||
// Cabecera
|
// Document title and metadata
|
||||||
doc.add(new Paragraph("FACTURA #" + invoice.getId()).setFontSize(16).setBold());
|
doc.add(new Paragraph("FACTURA #" + invoice.getId()).setFontSize(16).setBold());
|
||||||
doc.add(new Paragraph("Fecha: " + invoice.getDate()));
|
doc.add(new Paragraph("Fecha: " + invoice.getDate()));
|
||||||
doc.add(new Paragraph("Estado: " + invoice.getStatus()));
|
doc.add(new Paragraph("Estado: " + invoice.getStatus()));
|
||||||
doc.add(new Paragraph(" "));
|
doc.add(new Paragraph(" "));
|
||||||
|
|
||||||
// Información del cliente
|
// Cliente information
|
||||||
var user = invoice.getUser();
|
var user = invoice.getUser();
|
||||||
doc.add(new Paragraph("Cliente: " + user.getName() + " " + user.getSurname()));
|
doc.add(new Paragraph("Cliente: " + user.getName() + " " + user.getSurname()));
|
||||||
doc.add(new Paragraph("Email: " + user.getEmail()));
|
doc.add(new Paragraph("Email: " + user.getEmail()));
|
||||||
doc.add(new Paragraph("Teléfono: " + user.getPhoneNumber()));
|
doc.add(new Paragraph("Teléfono: " + user.getPhoneNumber()));
|
||||||
doc.add(new Paragraph("Dirección: " + user.getAddress()));
|
doc.add(new Paragraph("Dirección: " + user.getAddress()));
|
||||||
|
|
||||||
// Si es estudiante, mostrar info básica (sin tutor ni cinturón)
|
// Student information
|
||||||
Student student = user.getStudent();
|
Student student = user.getStudent();
|
||||||
if (student != null) {
|
if (student != null) {
|
||||||
doc.add(new Paragraph("DNI: " + student.getDni()));
|
doc.add(new Paragraph("DNI: " + student.getDni()));
|
||||||
|
|
@ -45,7 +49,7 @@ public class InvoicePdfGenerator {
|
||||||
|
|
||||||
doc.add(new Paragraph(" "));
|
doc.add(new Paragraph(" "));
|
||||||
|
|
||||||
// Detalle de productos
|
// Products and services details
|
||||||
doc.add(new Paragraph("Detalle de productos:").setBold());
|
doc.add(new Paragraph("Detalle de productos:").setBold());
|
||||||
doc.add(new Paragraph("Producto | Cant. | Precio | IVA % | Subtotal (sin IVA) | IVA"));
|
doc.add(new Paragraph("Producto | Cant. | Precio | IVA % | Subtotal (sin IVA) | IVA"));
|
||||||
|
|
||||||
|
|
@ -74,7 +78,7 @@ public class InvoicePdfGenerator {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Totales
|
// Totals
|
||||||
doc.add(new Paragraph(" "));
|
doc.add(new Paragraph(" "));
|
||||||
doc.add(new Paragraph("Subtotal (sin IVA): " + totalSubtotal + " €").setBold());
|
doc.add(new Paragraph("Subtotal (sin IVA): " + totalSubtotal + " €").setBold());
|
||||||
doc.add(new Paragraph("IVA total: " + totalIVA + " €").setBold());
|
doc.add(new Paragraph("IVA total: " + totalIVA + " €").setBold());
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
1. Comprobar seguridad y permisos en cada endpoint.
|
|
||||||
2. Comprobar o arreglar el tema de los ID automáticos y los DTOs.
|
|
||||||
3. Documentar los endpoints.
|
|
||||||
4. Crear javadoc de cada metodo.
|
|
||||||
5. Crear un README.md con la información del proyecto.
|
|
||||||
7. Comprobar como funciona logger en cada endpoint.
|
|
||||||
8. Mejorar excepciones y mensajes de error.
|
|
||||||
|
|
@ -13,16 +13,31 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hibernate configuration class for setting up the EntityManagerFactory and DataSource.
|
||||||
|
* It uses HikariCP for connection pooling and configures JPA properties.
|
||||||
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
public class HibernateConfig {
|
public class HibernateConfig {
|
||||||
|
|
||||||
private final Environment env;
|
private final Environment env;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor to inject the Environment object for accessing properties.
|
||||||
|
*
|
||||||
|
* @param env the Environment object containing application properties
|
||||||
|
*/
|
||||||
public HibernateConfig(Environment env) {
|
public HibernateConfig(Environment env) {
|
||||||
this.env = env;
|
this.env = env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bean definition for DataSource using HikariCP.
|
||||||
|
* Reads properties from the application environment.
|
||||||
|
*
|
||||||
|
* @return a configured DataSource instance
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public DataSource dataSource() {
|
public DataSource dataSource() {
|
||||||
HikariDataSource dataSource = new HikariDataSource();
|
HikariDataSource dataSource = new HikariDataSource();
|
||||||
|
|
@ -33,6 +48,12 @@ public class HibernateConfig {
|
||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bean definition for LocalContainerEntityManagerFactoryBean.
|
||||||
|
*
|
||||||
|
* @param dataSource the DataSource to be used by the EntityManagerFactory
|
||||||
|
* @return a configured LocalContainerEntityManagerFactoryBean instance
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
|
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
|
||||||
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
|
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
|
||||||
|
|
@ -50,6 +71,13 @@ public class HibernateConfig {
|
||||||
return emf;
|
return emf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bean definition for PlatformTransactionManager.
|
||||||
|
* Uses JpaTransactionManager to manage transactions.
|
||||||
|
*
|
||||||
|
* @param emf the LocalContainerEntityManagerFactoryBean to be used by the transaction manager
|
||||||
|
* @return a configured PlatformTransactionManager instance
|
||||||
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public PlatformTransactionManager transactionManager(LocalContainerEntityManagerFactoryBean emf) {
|
public PlatformTransactionManager transactionManager(LocalContainerEntityManagerFactoryBean emf) {
|
||||||
JpaTransactionManager transactionManager = new JpaTransactionManager();
|
JpaTransactionManager transactionManager = new JpaTransactionManager();
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,11 @@ import org.springframework.data.repository.query.Param;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing Assistance entities.
|
||||||
|
* Provides methods to find assistance records by training session ID, student ID,
|
||||||
|
* and date range, as well as a method to find assistance by both training session ID and student ID.
|
||||||
|
*/
|
||||||
public interface AssistanceRepository extends JpaRepository<Assistance, Integer> {
|
public interface AssistanceRepository extends JpaRepository<Assistance, Integer> {
|
||||||
Assistance findByTrainingSessionId(Integer trainingSessionId);
|
Assistance findByTrainingSessionId(Integer trainingSessionId);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@ import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing Membership entities.
|
||||||
|
* Provides methods to find memberships by various attributes.
|
||||||
|
*/
|
||||||
public interface MembershipRepository extends JpaRepository<Membership, Integer> {
|
public interface MembershipRepository extends JpaRepository<Membership, Integer> {
|
||||||
Membership findByType(MembershipTypeValues type);
|
Membership findByType(MembershipTypeValues type);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,9 @@ package com.denniseckerskorn.repositories.class_managment_repositories;
|
||||||
import com.denniseckerskorn.entities.class_managment.TrainingGroup;
|
import com.denniseckerskorn.entities.class_managment.TrainingGroup;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing TrainingGroup entities.
|
||||||
|
* Provides methods to perform CRUD operations on TrainingGroup entities.
|
||||||
|
*/
|
||||||
public interface TrainingGroupRepository extends JpaRepository<TrainingGroup, Integer> {
|
public interface TrainingGroupRepository extends JpaRepository<TrainingGroup, Integer> {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,10 @@ import java.time.LocalDateTime;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing TrainingSession entities.
|
||||||
|
* Provides methods to find training sessions by date and date range.
|
||||||
|
*/
|
||||||
public interface TrainingSessionRepository extends JpaRepository<TrainingSession, Integer> {
|
public interface TrainingSessionRepository extends JpaRepository<TrainingSession, Integer> {
|
||||||
TrainingSession findByDate(LocalDateTime date);
|
TrainingSession findByDate(LocalDateTime date);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,10 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing IVAType entities.
|
||||||
|
* Provides methods to perform CRUD operations on IVAType entities.
|
||||||
|
*/
|
||||||
public interface IVATypeRepository extends JpaRepository<IVAType, Integer> {
|
public interface IVATypeRepository extends JpaRepository<IVAType, Integer> {
|
||||||
boolean existsByPercentage(BigDecimal percentage);
|
boolean existsByPercentage(BigDecimal percentage);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,9 @@ package com.denniseckerskorn.repositories.finance_repositories;
|
||||||
import com.denniseckerskorn.entities.finance.InvoiceLine;
|
import com.denniseckerskorn.entities.finance.InvoiceLine;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing InvoiceLine entities.
|
||||||
|
* Provides methods to perform CRUD operations on InvoiceLine entities.
|
||||||
|
*/
|
||||||
public interface InvoiceLineRepository extends JpaRepository<InvoiceLine, Integer> {
|
public interface InvoiceLineRepository extends JpaRepository<InvoiceLine, Integer> {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,9 @@ package com.denniseckerskorn.repositories.finance_repositories;
|
||||||
import com.denniseckerskorn.entities.finance.Invoice;
|
import com.denniseckerskorn.entities.finance.Invoice;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing Invoice entities.
|
||||||
|
* Provides methods to perform CRUD operations on Invoice entities.
|
||||||
|
*/
|
||||||
public interface InvoiceRepository extends JpaRepository<Invoice, Integer> {
|
public interface InvoiceRepository extends JpaRepository<Invoice, Integer> {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,10 @@ import com.denniseckerskorn.entities.finance.Payment;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing Payment entities.
|
||||||
|
* Provides methods to check if a payment exists by invoice ID and to find payments by user ID.
|
||||||
|
*/
|
||||||
public interface PaymentRepository extends JpaRepository<Payment, Integer> {
|
public interface PaymentRepository extends JpaRepository<Payment, Integer> {
|
||||||
boolean existsByInvoiceId(Integer invoiceId);
|
boolean existsByInvoiceId(Integer invoiceId);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@ package com.denniseckerskorn.repositories.finance_repositories;
|
||||||
import com.denniseckerskorn.entities.finance.ProductService;
|
import com.denniseckerskorn.entities.finance.ProductService;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing ProductService entities.
|
||||||
|
* Provides methods to perform CRUD operations on ProductService entities.
|
||||||
|
*/
|
||||||
public interface ProductServiceRepository extends JpaRepository<ProductService, Integer> {
|
public interface ProductServiceRepository extends JpaRepository<ProductService, Integer> {
|
||||||
boolean existsByName(String name);
|
boolean existsByName(String name);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@ package com.denniseckerskorn.repositories.user_managment_repositories;
|
||||||
import com.denniseckerskorn.entities.user_managment.users.Admin;
|
import com.denniseckerskorn.entities.user_managment.users.Admin;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing Admin entities.
|
||||||
|
* Provides methods to perform CRUD operations on Admin entities.
|
||||||
|
*/
|
||||||
public interface AdminRepository extends JpaRepository<Admin, Integer> {
|
public interface AdminRepository extends JpaRepository<Admin, Integer> {
|
||||||
boolean existsByUserEmail(String email);
|
boolean existsByUserEmail(String email);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,11 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing Notification entities.
|
||||||
|
* Provides methods to check if a notification exists by title and shipping date,
|
||||||
|
* and to find notifications by their ID.
|
||||||
|
*/
|
||||||
public interface NotificationRepository extends JpaRepository<Notification, Integer> {
|
public interface NotificationRepository extends JpaRepository<Notification, Integer> {
|
||||||
boolean existsByTitleAndShippingDate(String title, LocalDateTime shippingDate);
|
boolean existsByTitleAndShippingDate(String title, LocalDateTime shippingDate);
|
||||||
List<Notification> findNotificationsById(Integer id);
|
List<Notification> findNotificationsById(Integer id);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,10 @@ import com.denniseckerskorn.entities.user_managment.Permission;
|
||||||
import com.denniseckerskorn.enums.PermissionValues;
|
import com.denniseckerskorn.enums.PermissionValues;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing Permission entities.
|
||||||
|
* Provides methods to perform CRUD operations on Permission entities.
|
||||||
|
*/
|
||||||
public interface PermissionRepository extends JpaRepository<Permission, Integer> {
|
public interface PermissionRepository extends JpaRepository<Permission, Integer> {
|
||||||
Permission findByPermissionName(PermissionValues permissionName);
|
Permission findByPermissionName(PermissionValues permissionName);
|
||||||
boolean existsByPermissionName(PermissionValues permissionName);
|
boolean existsByPermissionName(PermissionValues permissionName);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@ package com.denniseckerskorn.repositories.user_managment_repositories;
|
||||||
import com.denniseckerskorn.entities.user_managment.Role;
|
import com.denniseckerskorn.entities.user_managment.Role;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing Role entities.
|
||||||
|
* Provides methods to perform CRUD operations on Role entities.
|
||||||
|
*/
|
||||||
public interface RoleRepository extends JpaRepository<Role, Integer> {
|
public interface RoleRepository extends JpaRepository<Role, Integer> {
|
||||||
Role findByName(String name);
|
Role findByName(String name);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@ package com.denniseckerskorn.repositories.user_managment_repositories;
|
||||||
import com.denniseckerskorn.entities.user_managment.StudentHistory;
|
import com.denniseckerskorn.entities.user_managment.StudentHistory;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing StudentHistory entities.
|
||||||
|
* Provides methods to perform CRUD operations on StudentHistory entities.
|
||||||
|
*/
|
||||||
public interface StudentHistoryRepository extends JpaRepository<StudentHistory, Integer> {
|
public interface StudentHistoryRepository extends JpaRepository<StudentHistory, Integer> {
|
||||||
boolean existsByEventType(String eventType);
|
boolean existsByEventType(String eventType);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@ package com.denniseckerskorn.repositories.user_managment_repositories;
|
||||||
import com.denniseckerskorn.entities.user_managment.users.Student;
|
import com.denniseckerskorn.entities.user_managment.users.Student;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing Student entities.
|
||||||
|
* Provides methods to perform CRUD operations on Student entities.
|
||||||
|
*/
|
||||||
public interface StudentRepository extends JpaRepository<Student, Integer> {
|
public interface StudentRepository extends JpaRepository<Student, Integer> {
|
||||||
boolean existsByDni(String dni);
|
boolean existsByDni(String dni);
|
||||||
Student findByDni(String dni);
|
Student findByDni(String dni);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@ package com.denniseckerskorn.repositories.user_managment_repositories;
|
||||||
import com.denniseckerskorn.entities.user_managment.users.Teacher;
|
import com.denniseckerskorn.entities.user_managment.users.Teacher;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing Teacher entities.
|
||||||
|
* Provides methods to perform CRUD operations on Teacher entities.
|
||||||
|
*/
|
||||||
public interface TeacherRepository extends JpaRepository<Teacher, Integer> {
|
public interface TeacherRepository extends JpaRepository<Teacher, Integer> {
|
||||||
|
|
||||||
boolean existsByUserEmail(String mail);
|
boolean existsByUserEmail(String mail);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,11 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository interface for managing User entities.
|
||||||
|
* Provides methods to check if a user exists by email, find a user by email,
|
||||||
|
* and retrieve all users with a specific role.
|
||||||
|
*/
|
||||||
public interface UserRepository extends JpaRepository<User, Integer> {
|
public interface UserRepository extends JpaRepository<User, Integer> {
|
||||||
boolean existsByEmail(String email);
|
boolean existsByEmail(String email);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,12 @@ import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TestDataSeeder is a component that seeds the database with initial test data
|
||||||
|
* when the application starts in the "dev" profile.
|
||||||
|
* It creates roles, permissions, users, memberships, training groups, sessions,
|
||||||
|
* and other entities to facilitate development and testing.
|
||||||
|
*/
|
||||||
@Component
|
@Component
|
||||||
@Profile("dev")
|
@Profile("dev")
|
||||||
public class TestDataSeeder implements CommandLineRunner {
|
public class TestDataSeeder implements CommandLineRunner {
|
||||||
|
|
@ -58,7 +64,27 @@ public class TestDataSeeder implements CommandLineRunner {
|
||||||
private final ProductServiceService productServiceService;
|
private final ProductServiceService productServiceService;
|
||||||
private final PaymentService paymentService;
|
private final PaymentService paymentService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for TestDataSeeder.
|
||||||
|
*
|
||||||
|
* @param adminService Service for managing admin entities.
|
||||||
|
* @param notificationService Service for managing notifications.
|
||||||
|
* @param permissionService Service for managing permissions.
|
||||||
|
* @param roleService Service for managing roles.
|
||||||
|
* @param studentHistoryService Service for managing student history.
|
||||||
|
* @param studentService Service for managing student entities.
|
||||||
|
* @param teacherService Service for managing teacher entities.
|
||||||
|
* @param userService Service for managing user entities.
|
||||||
|
* @param membershipService Service for managing memberships.
|
||||||
|
* @param assistanceService Service for managing assistance records.
|
||||||
|
* @param trainingGroupService Service for managing training groups.
|
||||||
|
* @param trainingSessionService Service for managing training sessions.
|
||||||
|
* @param invoiceService Service for managing invoices.
|
||||||
|
* @param invoiceLineService Service for managing invoice lines.
|
||||||
|
* @param ivaTypeService Service for managing IVA types.
|
||||||
|
* @param productServiceService Service for managing product/services.
|
||||||
|
* @param paymentService Service for managing payments.
|
||||||
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
public TestDataSeeder(AdminService adminService,
|
public TestDataSeeder(AdminService adminService,
|
||||||
NotificationService notificationService,
|
NotificationService notificationService,
|
||||||
|
|
@ -96,6 +122,14 @@ public class TestDataSeeder implements CommandLineRunner {
|
||||||
this.paymentService = paymentService;
|
this.paymentService = paymentService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is executed when the application starts.
|
||||||
|
* It seeds the database with initial data for roles, permissions, users,
|
||||||
|
* memberships, training groups, sessions, and other entities.
|
||||||
|
*
|
||||||
|
* @param args command line arguments
|
||||||
|
* @throws Exception if an error occurs during seeding
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void run(String... args) throws Exception {
|
public void run(String... args) throws Exception {
|
||||||
// Roles
|
// Roles
|
||||||
|
|
@ -111,32 +145,30 @@ public class TestDataSeeder implements CommandLineRunner {
|
||||||
adminRole.setName("ROLE_ADMIN");
|
adminRole.setName("ROLE_ADMIN");
|
||||||
this.roleService.save(adminRole);
|
this.roleService.save(adminRole);
|
||||||
|
|
||||||
// Permisos
|
// Permissions
|
||||||
for (PermissionValues value : PermissionValues.values()) {
|
for (PermissionValues value : PermissionValues.values()) {
|
||||||
Permission p = new Permission();
|
Permission p = new Permission();
|
||||||
p.setPermissionName(value);
|
p.setPermissionName(value);
|
||||||
this.permissionService.save(p);
|
this.permissionService.save(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtener permisos de la base de datos
|
// Obtain permissions
|
||||||
Permission fullAccess = this.permissionService.findPermissionByName(PermissionValues.FULL_ACCESS);
|
Permission fullAccess = this.permissionService.findPermissionByName(PermissionValues.FULL_ACCESS);
|
||||||
Permission manageUsers = this.permissionService.findPermissionByName(PermissionValues.MANAGE_STUDENTS);
|
Permission manageUsers = this.permissionService.findPermissionByName(PermissionValues.MANAGE_STUDENTS);
|
||||||
Permission viewOwnData = this.permissionService.findPermissionByName(PermissionValues.VIEW_OWN_DATA);
|
Permission viewOwnData = this.permissionService.findPermissionByName(PermissionValues.VIEW_OWN_DATA);
|
||||||
|
|
||||||
// Asignar permisos a roles
|
// Assign permissions to roles
|
||||||
studentRole.addPermission(viewOwnData);
|
studentRole.addPermission(viewOwnData);
|
||||||
teacherRole.addPermission(manageUsers);
|
teacherRole.addPermission(manageUsers);
|
||||||
teacherRole.addPermission(viewOwnData);
|
teacherRole.addPermission(viewOwnData);
|
||||||
adminRole.addPermission(fullAccess);
|
adminRole.addPermission(fullAccess);
|
||||||
|
|
||||||
|
// Update roles with permissions
|
||||||
// Guardar roles actualizados
|
|
||||||
this.roleService.update(studentRole);
|
this.roleService.update(studentRole);
|
||||||
this.roleService.update(teacherRole);
|
this.roleService.update(teacherRole);
|
||||||
this.roleService.update(adminRole);
|
this.roleService.update(adminRole);
|
||||||
|
|
||||||
|
// Memberships
|
||||||
// Membresías
|
|
||||||
Membership basicMembership = new Membership();
|
Membership basicMembership = new Membership();
|
||||||
basicMembership.setType(MembershipTypeValues.BASIC);
|
basicMembership.setType(MembershipTypeValues.BASIC);
|
||||||
basicMembership.setStartDate(LocalDate.now());
|
basicMembership.setStartDate(LocalDate.now());
|
||||||
|
|
@ -165,7 +197,7 @@ public class TestDataSeeder implements CommandLineRunner {
|
||||||
noLimitMembership.setStatus(StatusValues.ACTIVE);
|
noLimitMembership.setStatus(StatusValues.ACTIVE);
|
||||||
this.membershipService.save(noLimitMembership);
|
this.membershipService.save(noLimitMembership);
|
||||||
|
|
||||||
// Usuarios
|
// Users and their roles
|
||||||
User studentUser = new User();
|
User studentUser = new User();
|
||||||
studentUser.setName("Student");
|
studentUser.setName("Student");
|
||||||
studentUser.setSurname("One");
|
studentUser.setSurname("One");
|
||||||
|
|
@ -178,7 +210,6 @@ public class TestDataSeeder implements CommandLineRunner {
|
||||||
studentUser.setRole(studentRole);
|
studentUser.setRole(studentRole);
|
||||||
this.userService.save(studentUser);
|
this.userService.save(studentUser);
|
||||||
|
|
||||||
|
|
||||||
Student student = new Student();
|
Student student = new Student();
|
||||||
student.setUser(studentUser);
|
student.setUser(studentUser);
|
||||||
student.setBirthdate(LocalDate.of(2005, 5, 20));
|
student.setBirthdate(LocalDate.of(2005, 5, 20));
|
||||||
|
|
@ -210,7 +241,6 @@ public class TestDataSeeder implements CommandLineRunner {
|
||||||
teacherUser.setRole(teacherRole);
|
teacherUser.setRole(teacherRole);
|
||||||
this.userService.save(teacherUser);
|
this.userService.save(teacherUser);
|
||||||
|
|
||||||
|
|
||||||
Teacher teacher = new Teacher();
|
Teacher teacher = new Teacher();
|
||||||
teacher.setUser(teacherUser);
|
teacher.setUser(teacherUser);
|
||||||
teacher.setDiscipline("Jiu-Jitsu");
|
teacher.setDiscipline("Jiu-Jitsu");
|
||||||
|
|
@ -228,7 +258,6 @@ public class TestDataSeeder implements CommandLineRunner {
|
||||||
adminUser.setRole(adminRole);
|
adminUser.setRole(adminRole);
|
||||||
this.userService.save(adminUser);
|
this.userService.save(adminUser);
|
||||||
|
|
||||||
|
|
||||||
Admin admin = new Admin();
|
Admin admin = new Admin();
|
||||||
admin.setUser(adminUser);
|
admin.setUser(adminUser);
|
||||||
this.adminService.save(admin);
|
this.adminService.save(admin);
|
||||||
|
|
@ -246,32 +275,31 @@ public class TestDataSeeder implements CommandLineRunner {
|
||||||
notification.addUser(adminUser);
|
notification.addUser(adminUser);
|
||||||
this.notificationService.update(notification);
|
this.notificationService.update(notification);
|
||||||
|
|
||||||
// Grupo de entrenamiento
|
// Create a training group
|
||||||
TrainingGroup trainingGroup = new TrainingGroup();
|
TrainingGroup trainingGroup = new TrainingGroup();
|
||||||
trainingGroup.setName("Grupo JiuJitsu Avanzado");
|
trainingGroup.setName("Grupo JiuJitsu Avanzado");
|
||||||
trainingGroup.setSchedule(LocalDateTime.now().plusDays(1));
|
trainingGroup.setSchedule(LocalDateTime.now().plusDays(1));
|
||||||
trainingGroup.setTeacher(teacher);
|
trainingGroup.setTeacher(teacher);
|
||||||
this.trainingGroupService.save(trainingGroup);
|
this.trainingGroupService.save(trainingGroup);
|
||||||
|
|
||||||
// Asignar grupo al estudiante
|
// Assign the training group to the student
|
||||||
this.studentService.addGroupToStudent(student.getId(), trainingGroup);
|
this.studentService.addGroupToStudent(student.getId(), trainingGroup);
|
||||||
|
|
||||||
// Sesión de entrenamiento
|
// Create a training session
|
||||||
TrainingSession trainingSession = new TrainingSession();
|
TrainingSession trainingSession = new TrainingSession();
|
||||||
trainingSession.setTrainingGroup(trainingGroup);
|
trainingSession.setTrainingGroup(trainingGroup);
|
||||||
trainingSession.setDate(LocalDateTime.now().plusDays(2));
|
trainingSession.setDate(LocalDateTime.now().plusDays(2));
|
||||||
trainingSession.setStatus(StatusValues.ACTIVE);
|
trainingSession.setStatus(StatusValues.ACTIVE);
|
||||||
this.trainingSessionService.save(trainingSession);
|
this.trainingSessionService.save(trainingSession);
|
||||||
|
|
||||||
|
// Add the training session to the group
|
||||||
// Crear asistencia con sesión válida
|
|
||||||
Assistance validAssistance = new Assistance();
|
Assistance validAssistance = new Assistance();
|
||||||
validAssistance.setDate(LocalDateTime.now());
|
validAssistance.setDate(LocalDateTime.now());
|
||||||
validAssistance.setStudent(student);
|
validAssistance.setStudent(student);
|
||||||
validAssistance.setTrainingSession(trainingSession);
|
validAssistance.setTrainingSession(trainingSession);
|
||||||
this.studentService.addAssistanceToStudent(student, validAssistance);
|
this.studentService.addAssistanceToStudent(student, validAssistance);
|
||||||
|
|
||||||
// Factura para el estudiante
|
// Create an invalid assistance
|
||||||
Invoice invoice = new Invoice();
|
Invoice invoice = new Invoice();
|
||||||
invoice.setUser(studentUser);
|
invoice.setUser(studentUser);
|
||||||
invoice.setDate(LocalDateTime.now().minusDays(1));
|
invoice.setDate(LocalDateTime.now().minusDays(1));
|
||||||
|
|
@ -280,13 +308,13 @@ public class TestDataSeeder implements CommandLineRunner {
|
||||||
this.invoiceService.save(invoice);
|
this.invoiceService.save(invoice);
|
||||||
this.userService.addInvoiceToUser(studentUser, invoice);
|
this.userService.addInvoiceToUser(studentUser, invoice);
|
||||||
|
|
||||||
// IVA TYPE
|
// Create an IVA type
|
||||||
IVAType ivaGeneral = new IVAType();
|
IVAType ivaGeneral = new IVAType();
|
||||||
ivaGeneral.setPercentage(new BigDecimal("21.00"));
|
ivaGeneral.setPercentage(new BigDecimal("21.00"));
|
||||||
ivaGeneral.setDescription("IVA General");
|
ivaGeneral.setDescription("IVA General");
|
||||||
this.ivaTypeService.save(ivaGeneral);
|
this.ivaTypeService.save(ivaGeneral);
|
||||||
|
|
||||||
// PRODUCTO / SERVICIO
|
// Create a product/service
|
||||||
ProductService jiuJitsuClass = new ProductService();
|
ProductService jiuJitsuClass = new ProductService();
|
||||||
jiuJitsuClass.setName("Clase de JiuJitsu");
|
jiuJitsuClass.setName("Clase de JiuJitsu");
|
||||||
jiuJitsuClass.setType("Servicio");
|
jiuJitsuClass.setType("Servicio");
|
||||||
|
|
@ -295,7 +323,7 @@ public class TestDataSeeder implements CommandLineRunner {
|
||||||
jiuJitsuClass.setStatus(StatusValues.ACTIVE);
|
jiuJitsuClass.setStatus(StatusValues.ACTIVE);
|
||||||
this.productServiceService.save(jiuJitsuClass);
|
this.productServiceService.save(jiuJitsuClass);
|
||||||
|
|
||||||
// LÍNEA DE FACTURA
|
// Add the product/service to the invoice
|
||||||
InvoiceLine line = new InvoiceLine();
|
InvoiceLine line = new InvoiceLine();
|
||||||
line.setInvoice(invoice);
|
line.setInvoice(invoice);
|
||||||
line.setProductService(jiuJitsuClass);
|
line.setProductService(jiuJitsuClass);
|
||||||
|
|
@ -304,18 +332,16 @@ public class TestDataSeeder implements CommandLineRunner {
|
||||||
line.setSubtotal(jiuJitsuClass.getPrice().multiply(BigDecimal.valueOf(line.getQuantity())));
|
line.setSubtotal(jiuJitsuClass.getPrice().multiply(BigDecimal.valueOf(line.getQuantity())));
|
||||||
this.invoiceService.addLineToInvoice(invoice, line);
|
this.invoiceService.addLineToInvoice(invoice, line);
|
||||||
|
|
||||||
|
// Calculate the total with IVA
|
||||||
// PAGO (PAYMENT)
|
|
||||||
Payment payment = new Payment();
|
Payment payment = new Payment();
|
||||||
payment.setInvoice(invoice);
|
payment.setInvoice(invoice);
|
||||||
payment.setAmount(invoice.getTotal()); // Debe incluir el IVA si se calcula externamente
|
payment.setAmount(invoice.getTotal());
|
||||||
payment.setPaymentMethod(PaymentMethodValues.CREDIT_CARD);
|
payment.setPaymentMethod(PaymentMethodValues.CREDIT_CARD);
|
||||||
payment.setPaymentDate(LocalDateTime.now());
|
payment.setPaymentDate(LocalDateTime.now());
|
||||||
payment.setStatus(StatusValues.PAID);
|
payment.setStatus(StatusValues.PAID);
|
||||||
this.paymentService.save(payment);
|
this.paymentService.save(payment);
|
||||||
|
|
||||||
|
// Show all data in the console
|
||||||
// Mostrar todo
|
|
||||||
System.out.println("--- ROLES ---");
|
System.out.println("--- ROLES ---");
|
||||||
this.roleService.findAll().forEach(System.out::println);
|
this.roleService.findAll().forEach(System.out::println);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,15 +23,23 @@ public class AssistanceService extends AbstractService<Assistance, Integer> {
|
||||||
private final AssistanceRepository assistanceRepository;
|
private final AssistanceRepository assistanceRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for AssitanceService.
|
* Constructor for AssistanceService.
|
||||||
*
|
*
|
||||||
* @param assistanceRepository the assistance repository
|
* @param assistanceRepository the repository for assistance records
|
||||||
*/
|
*/
|
||||||
public AssistanceService(AssistanceRepository assistanceRepository) {
|
public AssistanceService(AssistanceRepository assistanceRepository) {
|
||||||
super(assistanceRepository);
|
super(assistanceRepository);
|
||||||
this.assistanceRepository = assistanceRepository;
|
this.assistanceRepository = assistanceRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Assistance entity with the current date and time.
|
||||||
|
*
|
||||||
|
* @param entity the assistance to create
|
||||||
|
* @return the created assistance entity
|
||||||
|
* @throws IllegalArgumentException if the assistance is null
|
||||||
|
* @throws DuplicateEntityException if the assistance already exists
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Assistance save(Assistance entity) throws IllegalArgumentException, DuplicateEntityException {
|
public Assistance save(Assistance entity) throws IllegalArgumentException, DuplicateEntityException {
|
||||||
logger.info("Saving assistance: {}", entity);
|
logger.info("Saving assistance: {}", entity);
|
||||||
|
|
@ -42,6 +50,15 @@ public class AssistanceService extends AbstractService<Assistance, Integer> {
|
||||||
return super.save(entity);
|
return super.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing Assistance entity.
|
||||||
|
*
|
||||||
|
* @param entity the entity to update
|
||||||
|
* @return the updated assistance entity
|
||||||
|
* @throws IllegalArgumentException if the assistance is null
|
||||||
|
* @throws InvalidDataException if the assistance data is invalid
|
||||||
|
* @throws EntityNotFoundException if the assistance does not exist
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Assistance update(Assistance entity) throws IllegalArgumentException, InvalidDataException, EntityNotFoundException {
|
public Assistance update(Assistance entity) throws IllegalArgumentException, InvalidDataException, EntityNotFoundException {
|
||||||
logger.info("Updating assistance: {}", entity);
|
logger.info("Updating assistance: {}", entity);
|
||||||
|
|
@ -49,11 +66,26 @@ public class AssistanceService extends AbstractService<Assistance, Integer> {
|
||||||
return super.update(entity);
|
return super.update(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the ID of the Assistance entity.
|
||||||
|
*
|
||||||
|
* @param entity the assistance entity
|
||||||
|
* @return the ID of the assistance entity
|
||||||
|
* @throws IllegalStateException if the entity does not have an ID
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Integer getEntityId(Assistance entity) throws IllegalStateException {
|
protected Integer getEntityId(Assistance entity) throws IllegalStateException {
|
||||||
return super.getEntityId(entity);
|
return super.getEntityId(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds an Assistance entity by its ID.
|
||||||
|
*
|
||||||
|
* @param id the ID of the assistance
|
||||||
|
* @return the found assistance entity
|
||||||
|
* @throws InvalidDataException if the ID is null
|
||||||
|
* @throws EntityNotFoundException if the assistance does not exist
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Assistance findById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
public Assistance findById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
||||||
logger.info("Finding assistance by ID: {}", id);
|
logger.info("Finding assistance by ID: {}", id);
|
||||||
|
|
@ -64,6 +96,13 @@ public class AssistanceService extends AbstractService<Assistance, Integer> {
|
||||||
return super.findById(id);
|
return super.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an Assistance entity by its ID.
|
||||||
|
*
|
||||||
|
* @param id the ID of the assistance to delete
|
||||||
|
* @throws InvalidDataException if the ID is null
|
||||||
|
* @throws EntityNotFoundException if the assistance does not exist
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void deleteById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
public void deleteById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
||||||
logger.info("Deleting assistance by ID: {}", id);
|
logger.info("Deleting assistance by ID: {}", id);
|
||||||
|
|
@ -75,12 +114,23 @@ public class AssistanceService extends AbstractService<Assistance, Integer> {
|
||||||
super.deleteById(id);
|
super.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds all Assistance records.
|
||||||
|
*
|
||||||
|
* @return a list of all assistance records
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Assistance> findAll() {
|
public List<Assistance> findAll() {
|
||||||
logger.info("Finding all assistance records");
|
logger.info("Finding all assistance records");
|
||||||
return super.findAll();
|
return super.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if an Assistance entity exists.
|
||||||
|
*
|
||||||
|
* @param entity the assistance entity to check
|
||||||
|
* @return true if the assistance exists, false otherwise
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected boolean exists(Assistance entity) {
|
protected boolean exists(Assistance entity) {
|
||||||
logger.info("Checking if assistance exists: {}", entity);
|
logger.info("Checking if assistance exists: {}", entity);
|
||||||
|
|
|
||||||
|
|
@ -15,17 +15,33 @@ import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service class for managing training groups.
|
||||||
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class TrainingGroupService extends AbstractService<TrainingGroup, Integer> {
|
public class TrainingGroupService extends AbstractService<TrainingGroup, Integer> {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(TrainingGroupService.class);
|
private static final Logger logger = LoggerFactory.getLogger(TrainingGroupService.class);
|
||||||
private final TrainingGroupRepository trainingGroupRepository;
|
private final TrainingGroupRepository trainingGroupRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for TrainingGroupService.
|
||||||
|
*
|
||||||
|
* @param trainingGroupRepository the repository for training groups
|
||||||
|
*/
|
||||||
public TrainingGroupService(TrainingGroupRepository trainingGroupRepository) {
|
public TrainingGroupService(TrainingGroupRepository trainingGroupRepository) {
|
||||||
super(trainingGroupRepository);
|
super(trainingGroupRepository);
|
||||||
this.trainingGroupRepository = trainingGroupRepository;
|
this.trainingGroupRepository = trainingGroupRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves a new TrainingGroup entity.
|
||||||
|
*
|
||||||
|
* @param entity the training group to save
|
||||||
|
* @return the saved training group
|
||||||
|
* @throws IllegalArgumentException if the training group is null
|
||||||
|
* @throws DuplicateEntityException if the training group already exists
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TrainingGroup save(TrainingGroup entity) throws IllegalArgumentException, DuplicateEntityException {
|
public TrainingGroup save(TrainingGroup entity) throws IllegalArgumentException, DuplicateEntityException {
|
||||||
logger.info("Saving training group: {}", entity);
|
logger.info("Saving training group: {}", entity);
|
||||||
|
|
@ -36,6 +52,15 @@ public class TrainingGroupService extends AbstractService<TrainingGroup, Integer
|
||||||
return super.save(entity);
|
return super.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing TrainingGroup entity.
|
||||||
|
*
|
||||||
|
* @param entity the training group to update
|
||||||
|
* @return the updated training group
|
||||||
|
* @throws IllegalArgumentException if the training group is null
|
||||||
|
* @throws InvalidDataException if the training group data is invalid
|
||||||
|
* @throws EntityNotFoundException if the training group does not exist
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TrainingGroup update(TrainingGroup entity) throws IllegalArgumentException, InvalidDataException, EntityNotFoundException {
|
public TrainingGroup update(TrainingGroup entity) throws IllegalArgumentException, InvalidDataException, EntityNotFoundException {
|
||||||
logger.info("Updating training group: {}", entity);
|
logger.info("Updating training group: {}", entity);
|
||||||
|
|
@ -43,17 +68,38 @@ public class TrainingGroupService extends AbstractService<TrainingGroup, Integer
|
||||||
return super.update(entity);
|
return super.update(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the ID of the TrainingGroup entity.
|
||||||
|
*
|
||||||
|
* @param entity the training group entity
|
||||||
|
* @return the ID of the training group
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Integer getEntityId(TrainingGroup entity) {
|
protected Integer getEntityId(TrainingGroup entity) {
|
||||||
return super.getEntityId(entity);
|
return super.getEntityId(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a TrainingGroup by its ID.
|
||||||
|
*
|
||||||
|
* @param id the ID of the training group
|
||||||
|
* @return the found training group
|
||||||
|
* @throws InvalidDataException if the ID is invalid
|
||||||
|
* @throws EntityNotFoundException if the training group does not exist
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TrainingGroup findById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
public TrainingGroup findById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
||||||
logger.info("Finding training group by ID: {}", id);
|
logger.info("Finding training group by ID: {}", id);
|
||||||
return super.findById(id);
|
return super.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a TrainingGroup by its ID.
|
||||||
|
*
|
||||||
|
* @param id the ID of the training group to delete
|
||||||
|
* @throws InvalidDataException if the ID is invalid
|
||||||
|
* @throws EntityNotFoundException if the training group does not exist
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void deleteById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
public void deleteById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
||||||
logger.info("Deleting training group by ID: {}", id);
|
logger.info("Deleting training group by ID: {}", id);
|
||||||
|
|
@ -65,18 +111,35 @@ public class TrainingGroupService extends AbstractService<TrainingGroup, Integer
|
||||||
super.deleteById(id);
|
super.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds all training groups.
|
||||||
|
*
|
||||||
|
* @return a list of all training groups
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<TrainingGroup> findAll() {
|
public List<TrainingGroup> findAll() {
|
||||||
logger.info("Finding all training groups");
|
logger.info("Finding all training groups");
|
||||||
return super.findAll();
|
return super.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a TrainingGroup exists in the database.
|
||||||
|
*
|
||||||
|
* @param entity the training group to check
|
||||||
|
* @return true if the training group exists, false otherwise
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected boolean exists(TrainingGroup entity) {
|
protected boolean exists(TrainingGroup entity) {
|
||||||
logger.info("Checking if training group exists: {}", entity);
|
logger.info("Checking if training group exists: {}", entity);
|
||||||
return super.exists(entity);
|
return super.exists(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the TrainingGroup entity.
|
||||||
|
*
|
||||||
|
* @param group the training group to validate
|
||||||
|
* @throws InvalidDataException if the training group data is invalid
|
||||||
|
*/
|
||||||
private void validateTrainingGroup(TrainingGroup group) throws InvalidDataException {
|
private void validateTrainingGroup(TrainingGroup group) throws InvalidDataException {
|
||||||
if (group.getTeacher() == null) {
|
if (group.getTeacher() == null) {
|
||||||
throw new InvalidDataException("Teacher cannot be null");
|
throw new InvalidDataException("Teacher cannot be null");
|
||||||
|
|
@ -89,6 +152,14 @@ public class TrainingGroupService extends AbstractService<TrainingGroup, Integer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a student to a training group.
|
||||||
|
*
|
||||||
|
* @param group the training group
|
||||||
|
* @param student the student to add
|
||||||
|
* @throws InvalidDataException if the group or student is null
|
||||||
|
* @throws EntityNotFoundException if the group does not exist
|
||||||
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public void addStudentToGroup(TrainingGroup group, Student student) throws InvalidDataException, EntityNotFoundException {
|
public void addStudentToGroup(TrainingGroup group, Student student) throws InvalidDataException, EntityNotFoundException {
|
||||||
if (group == null || student == null) {
|
if (group == null || student == null) {
|
||||||
|
|
@ -104,6 +175,14 @@ public class TrainingGroupService extends AbstractService<TrainingGroup, Integer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a student from a training group.
|
||||||
|
*
|
||||||
|
* @param group the training group
|
||||||
|
* @param student the student to remove
|
||||||
|
* @throws InvalidDataException if the group or student is null
|
||||||
|
* @throws EntityNotFoundException if the group does not exist
|
||||||
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public void removeStudentFromGroup(TrainingGroup group, Student student) throws InvalidDataException, EntityNotFoundException {
|
public void removeStudentFromGroup(TrainingGroup group, Student student) throws InvalidDataException, EntityNotFoundException {
|
||||||
if (group == null || student == null) {
|
if (group == null || student == null) {
|
||||||
|
|
@ -119,6 +198,14 @@ public class TrainingGroupService extends AbstractService<TrainingGroup, Integer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a training session to a training group.
|
||||||
|
*
|
||||||
|
* @param group the training group
|
||||||
|
* @param session the training session to add
|
||||||
|
* @throws InvalidDataException if the group or session is null
|
||||||
|
* @throws EntityNotFoundException if the group does not exist
|
||||||
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public void addTrainingSessionToGroup(TrainingGroup group, TrainingSession session) throws InvalidDataException, EntityNotFoundException {
|
public void addTrainingSessionToGroup(TrainingGroup group, TrainingSession session) throws InvalidDataException, EntityNotFoundException {
|
||||||
if (group == null || session == null) {
|
if (group == null || session == null) {
|
||||||
|
|
@ -131,6 +218,14 @@ public class TrainingGroupService extends AbstractService<TrainingGroup, Integer
|
||||||
trainingGroupRepository.save(managedGroup);
|
trainingGroupRepository.save(managedGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a training session from a training group.
|
||||||
|
*
|
||||||
|
* @param group the training group
|
||||||
|
* @param session the training session to remove
|
||||||
|
* @throws InvalidDataException if the group or session is null
|
||||||
|
* @throws EntityNotFoundException if the group does not exist
|
||||||
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public void removeTrainingSessionFromGroup(TrainingGroup group, TrainingSession session) throws InvalidDataException, EntityNotFoundException {
|
public void removeTrainingSessionFromGroup(TrainingGroup group, TrainingSession session) throws InvalidDataException, EntityNotFoundException {
|
||||||
if (group == null || session == null) {
|
if (group == null || session == null) {
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,24 @@ public class TrainingSessionService extends AbstractService<TrainingSession, Int
|
||||||
private static final Logger logger = LoggerFactory.getLogger(TrainingSessionService.class);
|
private static final Logger logger = LoggerFactory.getLogger(TrainingSessionService.class);
|
||||||
private final TrainingSessionRepository trainingSessionRepository;
|
private final TrainingSessionRepository trainingSessionRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for TrainingSessionService.
|
||||||
|
*
|
||||||
|
* @param trainingSessionRepository the repository for training sessions
|
||||||
|
*/
|
||||||
public TrainingSessionService(TrainingSessionRepository trainingSessionRepository) {
|
public TrainingSessionService(TrainingSessionRepository trainingSessionRepository) {
|
||||||
super(trainingSessionRepository);
|
super(trainingSessionRepository);
|
||||||
this.trainingSessionRepository = trainingSessionRepository;
|
this.trainingSessionRepository = trainingSessionRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves a new TrainingSession entity.
|
||||||
|
*
|
||||||
|
* @param entity the training session to save
|
||||||
|
* @return the saved training session
|
||||||
|
* @throws IllegalArgumentException if the training session is null
|
||||||
|
* @throws DuplicateEntityException if the training session already exists
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TrainingSession save(TrainingSession entity) throws IllegalArgumentException, DuplicateEntityException {
|
public TrainingSession save(TrainingSession entity) throws IllegalArgumentException, DuplicateEntityException {
|
||||||
logger.info("Saving training session: {}", entity);
|
logger.info("Saving training session: {}", entity);
|
||||||
|
|
@ -42,6 +55,15 @@ public class TrainingSessionService extends AbstractService<TrainingSession, Int
|
||||||
return super.save(entity);
|
return super.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing TrainingSession entity.
|
||||||
|
*
|
||||||
|
* @param entity the training session to update
|
||||||
|
* @return the updated training session
|
||||||
|
* @throws IllegalArgumentException if the training session is null
|
||||||
|
* @throws InvalidDataException if the training session data is invalid
|
||||||
|
* @throws EntityNotFoundException if the training session does not exist
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TrainingSession update(TrainingSession entity) throws IllegalArgumentException, InvalidDataException, EntityNotFoundException {
|
public TrainingSession update(TrainingSession entity) throws IllegalArgumentException, InvalidDataException, EntityNotFoundException {
|
||||||
logger.info("Updating training session: {}", entity);
|
logger.info("Updating training session: {}", entity);
|
||||||
|
|
@ -49,17 +71,39 @@ public class TrainingSessionService extends AbstractService<TrainingSession, Int
|
||||||
return super.update(entity);
|
return super.update(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the ID of the training session entity.
|
||||||
|
*
|
||||||
|
* @param entity the training session entity
|
||||||
|
* @return the ID of the training session
|
||||||
|
* @throws IllegalStateException if the entity is not managed
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Integer getEntityId(TrainingSession entity) throws IllegalStateException {
|
protected Integer getEntityId(TrainingSession entity) throws IllegalStateException {
|
||||||
return super.getEntityId(entity);
|
return super.getEntityId(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a training session by its ID.
|
||||||
|
*
|
||||||
|
* @param id the ID of the training session
|
||||||
|
* @return the found training session
|
||||||
|
* @throws InvalidDataException if the ID is invalid
|
||||||
|
* @throws EntityNotFoundException if the training session does not exist
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TrainingSession findById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
public TrainingSession findById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
||||||
logger.info("Finding training session by ID: {}", id);
|
logger.info("Finding training session by ID: {}", id);
|
||||||
return super.findById(id);
|
return super.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a training session by its ID.
|
||||||
|
*
|
||||||
|
* @param id the ID of the training session to delete
|
||||||
|
* @throws InvalidDataException if the ID is invalid
|
||||||
|
* @throws EntityNotFoundException if the training session does not exist
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void deleteById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
public void deleteById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
||||||
logger.info("Deleting training session by ID: {}", id);
|
logger.info("Deleting training session by ID: {}", id);
|
||||||
|
|
@ -71,12 +115,23 @@ public class TrainingSessionService extends AbstractService<TrainingSession, Int
|
||||||
super.deleteById(id);
|
super.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds all training sessions.
|
||||||
|
*
|
||||||
|
* @return a list of all training sessions
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<TrainingSession> findAll() {
|
public List<TrainingSession> findAll() {
|
||||||
logger.info("Finding all training sessions");
|
logger.info("Finding all training sessions");
|
||||||
return super.findAll();
|
return super.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a training session exists in the database.
|
||||||
|
*
|
||||||
|
* @param entity the training session to check
|
||||||
|
* @return true if the training session exists, false otherwise
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected boolean exists(TrainingSession entity) {
|
protected boolean exists(TrainingSession entity) {
|
||||||
logger.info("Checking if training session exists: {}", entity);
|
logger.info("Checking if training session exists: {}", entity);
|
||||||
|
|
@ -98,6 +153,14 @@ public class TrainingSessionService extends AbstractService<TrainingSession, Int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all students from a specific training session.
|
||||||
|
*
|
||||||
|
* @param session the training session
|
||||||
|
* @return a set of students enrolled in the session
|
||||||
|
* @throws EntityNotFoundException if the session does not exist
|
||||||
|
* @throws InvalidDataException if the session is null or has no ID
|
||||||
|
*/
|
||||||
public Set<Student> getStudentsFromSession(TrainingSession session) throws EntityNotFoundException, InvalidDataException {
|
public Set<Student> getStudentsFromSession(TrainingSession session) throws EntityNotFoundException, InvalidDataException {
|
||||||
if (session == null || session.getId() == null) {
|
if (session == null || session.getId() == null) {
|
||||||
throw new InvalidDataException("Session cannot be null");
|
throw new InvalidDataException("Session cannot be null");
|
||||||
|
|
@ -107,6 +170,13 @@ public class TrainingSessionService extends AbstractService<TrainingSession, Int
|
||||||
return managedSession.getTrainingGroup().getStudents();
|
return managedSession.getTrainingGroup().getStudents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes all assistances for a specific training session.
|
||||||
|
*
|
||||||
|
* @param sessionId the ID of the training session
|
||||||
|
* @throws EntityNotFoundException if the session does not exist
|
||||||
|
* @throws InvalidDataException if the session ID is null
|
||||||
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public void deleteAllAssistancesBySession(Integer sessionId) {
|
public void deleteAllAssistancesBySession(Integer sessionId) {
|
||||||
logger.info("Deleting all assistances for session ID: {}", sessionId);
|
logger.info("Deleting all assistances for session ID: {}", sessionId);
|
||||||
|
|
@ -119,6 +189,13 @@ public class TrainingSessionService extends AbstractService<TrainingSession, Int
|
||||||
logger.info("All assistances for session ID: {} have been deleted", sessionId);
|
logger.info("All assistances for session ID: {} have been deleted", sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates recurring training sessions for a given training group.
|
||||||
|
*
|
||||||
|
* @param group the training group for which to generate sessions
|
||||||
|
* @param months the number of months for which to generate sessions
|
||||||
|
* @throws InvalidDataException if the group is null or has no schedule
|
||||||
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public void generateRecurringSession(TrainingGroup group, int months) {
|
public void generateRecurringSession(TrainingGroup group, int months) {
|
||||||
logger.info("Generating recurring sessions for group: {} for {} months", group.getName(), months);
|
logger.info("Generating recurring sessions for group: {} for {} months", group.getName(), months);
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,10 @@ import org.springframework.stereotype.Service;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service class for managing IVA types.
|
||||||
|
* This class provides methods to perform CRUD operations on IVAType entities.
|
||||||
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class IVATypeService extends AbstractService<IVAType, Integer> {
|
public class IVATypeService extends AbstractService<IVAType, Integer> {
|
||||||
|
|
||||||
|
|
@ -21,12 +25,25 @@ public class IVATypeService extends AbstractService<IVAType, Integer> {
|
||||||
private final IVATypeRepository ivaTypeRepository;
|
private final IVATypeRepository ivaTypeRepository;
|
||||||
private final ProductServiceRepository productServiceRepository;
|
private final ProductServiceRepository productServiceRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for IVATypeService.
|
||||||
|
*
|
||||||
|
* @param ivaTypeRepository the repository for IVA types
|
||||||
|
* @param productServiceRepository the repository for product services
|
||||||
|
*/
|
||||||
public IVATypeService(IVATypeRepository ivaTypeRepository, ProductServiceRepository productServiceRepository) {
|
public IVATypeService(IVATypeRepository ivaTypeRepository, ProductServiceRepository productServiceRepository) {
|
||||||
super(ivaTypeRepository);
|
super(ivaTypeRepository);
|
||||||
this.ivaTypeRepository = ivaTypeRepository;
|
this.ivaTypeRepository = ivaTypeRepository;
|
||||||
this.productServiceRepository = productServiceRepository;
|
this.productServiceRepository = productServiceRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves a new IVAType entity.
|
||||||
|
*
|
||||||
|
* @param entity the IVAType to save
|
||||||
|
* @return the saved IVAType
|
||||||
|
* @throws DuplicateEntityException if an entity with the same percentage already exists
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IVAType save(IVAType entity) throws DuplicateEntityException {
|
public IVAType save(IVAType entity) throws DuplicateEntityException {
|
||||||
logger.info("Saving IVAType: {}", entity);
|
logger.info("Saving IVAType: {}", entity);
|
||||||
|
|
@ -37,6 +54,14 @@ public class IVATypeService extends AbstractService<IVAType, Integer> {
|
||||||
return super.save(entity);
|
return super.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing IVAType entity.
|
||||||
|
*
|
||||||
|
* @param entity the IVAType to update
|
||||||
|
* @return the updated IVAType
|
||||||
|
* @throws InvalidDataException if the entity data is invalid
|
||||||
|
* @throws EntityNotFoundException if the entity does not exist
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IVAType update(IVAType entity) throws InvalidDataException, EntityNotFoundException {
|
public IVAType update(IVAType entity) throws InvalidDataException, EntityNotFoundException {
|
||||||
logger.info("Updating IVAType: {}", entity);
|
logger.info("Updating IVAType: {}", entity);
|
||||||
|
|
@ -44,22 +69,46 @@ public class IVATypeService extends AbstractService<IVAType, Integer> {
|
||||||
return super.update(entity);
|
return super.update(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies if an IVAType entity exists in the database.
|
||||||
|
*
|
||||||
|
* @param entity the entity to check
|
||||||
|
* @return true if the entity exists, false otherwise
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected boolean exists(IVAType entity) {
|
protected boolean exists(IVAType entity) {
|
||||||
return entity != null && entity.getId() != null && ivaTypeRepository.existsById(entity.getId());
|
return entity != null && entity.getId() != null && ivaTypeRepository.existsById(entity.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the ID of the IVAType entity.
|
||||||
|
*
|
||||||
|
* @param entity the IVAType entity
|
||||||
|
* @return the ID of the IVAType
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Integer getEntityId(IVAType entity) {
|
protected Integer getEntityId(IVAType entity) {
|
||||||
return entity.getId();
|
return entity.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds all IVAType entities.
|
||||||
|
*
|
||||||
|
* @return a list of all IVAType entities
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<IVAType> findAll() {
|
public List<IVAType> findAll() {
|
||||||
logger.info("Retrieving all IVA types");
|
logger.info("Retrieving all IVA types");
|
||||||
return super.findAll();
|
return super.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an IVAType entity by its ID.
|
||||||
|
*
|
||||||
|
* @param id the ID of the entity to delete
|
||||||
|
* @throws InvalidDataException if the ID is null or invalid
|
||||||
|
* @throws EntityNotFoundException if the entity does not exist
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void deleteById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
public void deleteById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
||||||
if (productServiceRepository.existsByIvaTypeId(id)) {
|
if (productServiceRepository.existsByIvaTypeId(id)) {
|
||||||
|
|
@ -68,6 +117,12 @@ public class IVATypeService extends AbstractService<IVAType, Integer> {
|
||||||
super.deleteById(id);
|
super.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the IVAType entity before saving or updating.
|
||||||
|
*
|
||||||
|
* @param ivaType the IVAType to validate
|
||||||
|
* @throws InvalidDataException if the IVAType data is invalid
|
||||||
|
*/
|
||||||
private void validate(IVAType ivaType) {
|
private void validate(IVAType ivaType) {
|
||||||
if (ivaType.getPercentage() == null || ivaType.getPercentage().compareTo(BigDecimal.ZERO) < 0) {
|
if (ivaType.getPercentage() == null || ivaType.getPercentage().compareTo(BigDecimal.ZERO) < 0) {
|
||||||
throw new InvalidDataException("IVA percentage must be >= 0");
|
throw new InvalidDataException("IVA percentage must be >= 0");
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,24 @@ public class InvoiceLineService extends AbstractService<InvoiceLine, Integer> {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(InvoiceLineService.class);
|
private static final Logger logger = LoggerFactory.getLogger(InvoiceLineService.class);
|
||||||
private final InvoiceLineRepository invoiceLineRepository;
|
private final InvoiceLineRepository invoiceLineRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for InvoiceLineService.
|
||||||
|
*
|
||||||
|
* @param invoiceLineRepository the repository for InvoiceLine entities
|
||||||
|
*/
|
||||||
public InvoiceLineService(InvoiceLineRepository invoiceLineRepository) {
|
public InvoiceLineService(InvoiceLineRepository invoiceLineRepository) {
|
||||||
super(invoiceLineRepository);
|
super(invoiceLineRepository);
|
||||||
this.invoiceLineRepository = invoiceLineRepository;
|
this.invoiceLineRepository = invoiceLineRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves a new InvoiceLine entity.
|
||||||
|
*
|
||||||
|
* @param entity the InvoiceLine to save
|
||||||
|
* @return the saved InvoiceLine
|
||||||
|
* @throws IllegalArgumentException if the entity is null
|
||||||
|
* @throws DuplicateEntityException if an entity with the same ID already exists
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public InvoiceLine save(InvoiceLine entity) throws IllegalArgumentException, DuplicateEntityException {
|
public InvoiceLine save(InvoiceLine entity) throws IllegalArgumentException, DuplicateEntityException {
|
||||||
logger.info("Saving invoice line: {}", entity);
|
logger.info("Saving invoice line: {}", entity);
|
||||||
|
|
@ -35,6 +48,15 @@ public class InvoiceLineService extends AbstractService<InvoiceLine, Integer> {
|
||||||
return super.save(entity);
|
return super.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing InvoiceLine entity.
|
||||||
|
*
|
||||||
|
* @param entity the InvoiceLine to update
|
||||||
|
* @return the updated InvoiceLine
|
||||||
|
* @throws IllegalArgumentException if the entity is null
|
||||||
|
* @throws InvalidDataException if the entity data is invalid
|
||||||
|
* @throws EntityNotFoundException if the entity does not exist
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public InvoiceLine update(InvoiceLine entity) throws IllegalArgumentException, InvalidDataException, EntityNotFoundException {
|
public InvoiceLine update(InvoiceLine entity) throws IllegalArgumentException, InvalidDataException, EntityNotFoundException {
|
||||||
logger.info("Updating invoice line: {}", entity);
|
logger.info("Updating invoice line: {}", entity);
|
||||||
|
|
@ -42,22 +64,44 @@ public class InvoiceLineService extends AbstractService<InvoiceLine, Integer> {
|
||||||
return super.update(entity);
|
return super.update(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds all InvoiceLine entities.
|
||||||
|
*
|
||||||
|
* @return a list of all InvoiceLine entities
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<InvoiceLine> findAll() {
|
public List<InvoiceLine> findAll() {
|
||||||
logger.info("Retrieving all invoice lines");
|
logger.info("Retrieving all invoice lines");
|
||||||
return super.findAll();
|
return super.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies if an InvoiceLine entity exists in the repository.
|
||||||
|
*
|
||||||
|
* @param entity the entity to check
|
||||||
|
* @return true if the entity exists, false otherwise
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected boolean exists(InvoiceLine entity) {
|
protected boolean exists(InvoiceLine entity) {
|
||||||
return entity != null && entity.getId() != null && invoiceLineRepository.existsById(entity.getId());
|
return entity != null && entity.getId() != null && invoiceLineRepository.existsById(entity.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the ID of an InvoiceLine entity.
|
||||||
|
*
|
||||||
|
* @param entity the entity from which to retrieve the ID
|
||||||
|
* @return the ID of the InvoiceLine entity
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Integer getEntityId(InvoiceLine entity) {
|
protected Integer getEntityId(InvoiceLine entity) {
|
||||||
return entity.getId();
|
return entity.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the InvoiceLine entity before saving or updating.
|
||||||
|
*
|
||||||
|
* @param line the InvoiceLine to validate
|
||||||
|
*/
|
||||||
private void validateInvoiceLine(InvoiceLine line) {
|
private void validateInvoiceLine(InvoiceLine line) {
|
||||||
if (line.getInvoice() == null) {
|
if (line.getInvoice() == null) {
|
||||||
throw new InvalidDataException("InvoiceLine must be linked to an invoice");
|
throw new InvalidDataException("InvoiceLine must be linked to an invoice");
|
||||||
|
|
@ -72,7 +116,6 @@ public class InvoiceLineService extends AbstractService<InvoiceLine, Integer> {
|
||||||
throw new InvalidDataException("Unit price must be greater than 0");
|
throw new InvalidDataException("Unit price must be greater than 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validación automática de subtotal
|
|
||||||
BigDecimal expected = line.getUnitPrice().multiply(new BigDecimal(line.getQuantity()));
|
BigDecimal expected = line.getUnitPrice().multiply(new BigDecimal(line.getQuantity()));
|
||||||
line.setSubtotal(expected);
|
line.setSubtotal(expected);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,17 +17,34 @@ import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service class for managing invoices.
|
||||||
|
* This class provides methods to perform CRUD operations on Invoice entities.
|
||||||
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class InvoiceService extends AbstractService<Invoice, Integer> {
|
public class InvoiceService extends AbstractService<Invoice, Integer> {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(InvoiceService.class);
|
private static final Logger logger = LoggerFactory.getLogger(InvoiceService.class);
|
||||||
private final InvoiceRepository invoiceRepository;
|
private final InvoiceRepository invoiceRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for InvoiceService.
|
||||||
|
*
|
||||||
|
* @param invoiceRepository the repository for Invoice entities
|
||||||
|
*/
|
||||||
public InvoiceService(InvoiceRepository invoiceRepository) {
|
public InvoiceService(InvoiceRepository invoiceRepository) {
|
||||||
super(invoiceRepository);
|
super(invoiceRepository);
|
||||||
this.invoiceRepository = invoiceRepository;
|
this.invoiceRepository = invoiceRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves a new invoice in the database.
|
||||||
|
*
|
||||||
|
* @param entity the invoice to save
|
||||||
|
* @return the saved invoice
|
||||||
|
* @throws IllegalArgumentException if the invoice is null
|
||||||
|
* @throws DuplicateEntityException if an invoice with the same ID already exists
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Invoice save(Invoice entity) throws IllegalArgumentException, DuplicateEntityException {
|
public Invoice save(Invoice entity) throws IllegalArgumentException, DuplicateEntityException {
|
||||||
logger.info("Saving invoice: {}", entity);
|
logger.info("Saving invoice: {}", entity);
|
||||||
|
|
@ -38,6 +55,15 @@ public class InvoiceService extends AbstractService<Invoice, Integer> {
|
||||||
return super.save(entity);
|
return super.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing invoice in the database.
|
||||||
|
*
|
||||||
|
* @param entity the invoice to update
|
||||||
|
* @return the updated invoice
|
||||||
|
* @throws IllegalArgumentException if the invoice is null
|
||||||
|
* @throws InvalidDataException if the invoice data is invalid
|
||||||
|
* @throws EntityNotFoundException if the invoice does not exist
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Invoice update(Invoice entity) throws IllegalArgumentException, InvalidDataException, EntityNotFoundException {
|
public Invoice update(Invoice entity) throws IllegalArgumentException, InvalidDataException, EntityNotFoundException {
|
||||||
logger.info("Updating invoice: {}", entity);
|
logger.info("Updating invoice: {}", entity);
|
||||||
|
|
@ -45,12 +71,27 @@ public class InvoiceService extends AbstractService<Invoice, Integer> {
|
||||||
return super.update(entity);
|
return super.update(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds an invoice by its ID.
|
||||||
|
*
|
||||||
|
* @param id the ID of the entity to find
|
||||||
|
* @return the found invoice
|
||||||
|
* @throws InvalidDataException if the ID is null or invalid
|
||||||
|
* @throws EntityNotFoundException if the invoice does not exist
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Invoice findById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
public Invoice findById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
||||||
logger.info("Finding invoice by ID: {}", id);
|
logger.info("Finding invoice by ID: {}", id);
|
||||||
return super.findById(id);
|
return super.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes an invoice by its ID.
|
||||||
|
*
|
||||||
|
* @param id the ID of the invoice to delete
|
||||||
|
* @throws InvalidDataException if the ID is null or invalid
|
||||||
|
* @throws EntityNotFoundException if the invoice does not exist
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void deleteById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
public void deleteById(Integer id) throws InvalidDataException, EntityNotFoundException {
|
||||||
logger.info("Deleting invoice by ID: {}", id);
|
logger.info("Deleting invoice by ID: {}", id);
|
||||||
|
|
@ -61,24 +102,45 @@ public class InvoiceService extends AbstractService<Invoice, Integer> {
|
||||||
super.deleteById(id);
|
super.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all invoices.
|
||||||
|
*
|
||||||
|
* @return a list of all invoices
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Invoice> findAll() {
|
public List<Invoice> findAll() {
|
||||||
logger.info("Retrieving all invoices");
|
logger.info("Retrieving all invoices");
|
||||||
return super.findAll();
|
return super.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if an invoice exists in the database.
|
||||||
|
*
|
||||||
|
* @param entity the invoice to check
|
||||||
|
* @return true if the invoice exists, false otherwise
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected boolean exists(Invoice entity) {
|
protected boolean exists(Invoice entity) {
|
||||||
return entity != null && entity.getId() != null && invoiceRepository.existsById(entity.getId());
|
return entity != null && entity.getId() != null && invoiceRepository.existsById(entity.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the ID of the invoice entity.
|
||||||
|
*
|
||||||
|
* @param entity the invoice entity
|
||||||
|
* @return the ID of the invoice
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Integer getEntityId(Invoice entity) {
|
protected Integer getEntityId(Invoice entity) {
|
||||||
return entity.getId();
|
return entity.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtiene todas las facturas de un usuario específico.
|
* Finds all invoices associated with a specific user ID.
|
||||||
|
*
|
||||||
|
* @param userId the ID of the user
|
||||||
|
* @return a list of invoices associated with the user
|
||||||
|
* @throws InvalidDataException if the user ID is null
|
||||||
*/
|
*/
|
||||||
public List<Invoice> findAllInvoicesByUserId(Integer userId) throws InvalidDataException {
|
public List<Invoice> findAllInvoicesByUserId(Integer userId) throws InvalidDataException {
|
||||||
if (userId == null) {
|
if (userId == null) {
|
||||||
|
|
@ -91,7 +153,10 @@ public class InvoiceService extends AbstractService<Invoice, Integer> {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the invoice before saving/updating.
|
* Validates the invoice entity.
|
||||||
|
*
|
||||||
|
* @param invoice the invoice to validate
|
||||||
|
* @throws InvalidDataException if the invoice data is invalid
|
||||||
*/
|
*/
|
||||||
private void validateInvoice(Invoice invoice) throws InvalidDataException {
|
private void validateInvoice(Invoice invoice) throws InvalidDataException {
|
||||||
if (invoice.getUser() == null) {
|
if (invoice.getUser() == null) {
|
||||||
|
|
@ -108,6 +173,13 @@ public class InvoiceService extends AbstractService<Invoice, Integer> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a line to an invoice.
|
||||||
|
*
|
||||||
|
* @param invoice the invoice to which the line will be added
|
||||||
|
* @param line the line to add
|
||||||
|
* @throws InvalidDataException if the invoice or line is null
|
||||||
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public void addLineToInvoice(Invoice invoice, InvoiceLine line) {
|
public void addLineToInvoice(Invoice invoice, InvoiceLine line) {
|
||||||
if (invoice == null || line == null) {
|
if (invoice == null || line == null) {
|
||||||
|
|
@ -119,6 +191,13 @@ public class InvoiceService extends AbstractService<Invoice, Integer> {
|
||||||
invoiceRepository.save(invoice);
|
invoiceRepository.save(invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a line from an invoice.
|
||||||
|
*
|
||||||
|
* @param invoice the invoice from which the line will be removed
|
||||||
|
* @param line the line to remove
|
||||||
|
* @throws InvalidDataException if the invoice or line is null
|
||||||
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public void removeLineFromInvoice(Invoice invoice, InvoiceLine line) {
|
public void removeLineFromInvoice(Invoice invoice, InvoiceLine line) {
|
||||||
if (invoice == null || line == null) {
|
if (invoice == null || line == null) {
|
||||||
|
|
@ -130,6 +209,11 @@ public class InvoiceService extends AbstractService<Invoice, Integer> {
|
||||||
invoiceRepository.save(invoice);
|
invoiceRepository.save(invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the total amount of an invoice based on its lines.
|
||||||
|
*
|
||||||
|
* @param invoice the invoice to update
|
||||||
|
*/
|
||||||
public void updateInvoiceTotal(Invoice invoice) {
|
public void updateInvoiceTotal(Invoice invoice) {
|
||||||
BigDecimal total = BigDecimal.ZERO;
|
BigDecimal total = BigDecimal.ZERO;
|
||||||
|
|
||||||
|
|
@ -152,13 +236,25 @@ public class InvoiceService extends AbstractService<Invoice, Integer> {
|
||||||
invoice.setTotal(total);
|
invoice.setTotal(total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a line to an invoice by its ID.
|
||||||
|
*
|
||||||
|
* @param invoiceId the ID of the invoice to which the line will be added
|
||||||
|
* @param line the line to add
|
||||||
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public void addLineToInvoiceById(Integer invoiceId, InvoiceLine line) {
|
public void addLineToInvoiceById(Integer invoiceId, InvoiceLine line) {
|
||||||
Invoice invoice = findById(invoiceId);
|
Invoice invoice = findById(invoiceId);
|
||||||
addLineToInvoice(invoice, line);
|
addLineToInvoice(invoice, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a line from an invoice by its ID.
|
||||||
|
*
|
||||||
|
* @param invoiceId the ID of the invoice from which the line will be removed
|
||||||
|
* @param lineId the ID of the line to remove
|
||||||
|
* @throws EntityNotFoundException if the line does not exist in the invoice
|
||||||
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public void removeLineFromInvoiceById(Integer invoiceId, Integer lineId) {
|
public void removeLineFromInvoiceById(Integer invoiceId, Integer lineId) {
|
||||||
Invoice invoice = findById(invoiceId);
|
Invoice invoice = findById(invoiceId);
|
||||||
|
|
@ -169,12 +265,21 @@ public class InvoiceService extends AbstractService<Invoice, Integer> {
|
||||||
removeLineFromInvoice(invoice, line);
|
removeLineFromInvoice(invoice, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recalculates the total of an invoice and saves it.
|
||||||
|
*
|
||||||
|
* @param invoice the invoice to recalculate
|
||||||
|
*/
|
||||||
public void recalculateTotal(Invoice invoice) {
|
public void recalculateTotal(Invoice invoice) {
|
||||||
updateInvoiceTotal(invoice);
|
updateInvoiceTotal(invoice);
|
||||||
invoiceRepository.save(invoice);
|
invoiceRepository.save(invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears all lines from an invoice and updates the total.
|
||||||
|
*
|
||||||
|
* @param invoice the invoice to clear lines from
|
||||||
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public void clearInvoiceLines(Invoice invoice) {
|
public void clearInvoiceLines(Invoice invoice) {
|
||||||
invoice.getInvoiceLines().clear();
|
invoice.getInvoiceLines().clear();
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,10 @@ import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service class for managing Payment entities.
|
||||||
|
* This class provides methods to perform CRUD operations on Payment entities.
|
||||||
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class PaymentService extends AbstractService<Payment, Integer> {
|
public class PaymentService extends AbstractService<Payment, Integer> {
|
||||||
|
|
||||||
|
|
@ -24,12 +28,27 @@ public class PaymentService extends AbstractService<Payment, Integer> {
|
||||||
private final PaymentRepository paymentRepository;
|
private final PaymentRepository paymentRepository;
|
||||||
private final InvoiceService invoiceService;
|
private final InvoiceService invoiceService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for PaymentService.
|
||||||
|
*
|
||||||
|
* @param paymentRepository the repository for Payment entities
|
||||||
|
* @param invoiceService the service for Invoice entities
|
||||||
|
*/
|
||||||
public PaymentService(PaymentRepository paymentRepository, InvoiceService invoiceService) {
|
public PaymentService(PaymentRepository paymentRepository, InvoiceService invoiceService) {
|
||||||
super(paymentRepository);
|
super(paymentRepository);
|
||||||
this.paymentRepository = paymentRepository;
|
this.paymentRepository = paymentRepository;
|
||||||
this.invoiceService = invoiceService;
|
this.invoiceService = invoiceService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves a new Payment entity.
|
||||||
|
*
|
||||||
|
* @param payment the payment to save
|
||||||
|
* @return the saved payment
|
||||||
|
* @throws DuplicateEntityException if a payment already exists for the invoice
|
||||||
|
* @throws EntityNotFoundException if the associated invoice does not exist
|
||||||
|
* @throws InvalidDataException if the payment data is invalid
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public Payment save(Payment payment) throws DuplicateEntityException {
|
public Payment save(Payment payment) throws DuplicateEntityException {
|
||||||
|
|
@ -50,14 +69,20 @@ public class PaymentService extends AbstractService<Payment, Integer> {
|
||||||
|
|
||||||
Payment savedPayment = super.save(payment);
|
Payment savedPayment = super.save(payment);
|
||||||
|
|
||||||
//invoice.setPayment(savedPayment);
|
|
||||||
invoice.setStatus(StatusValues.PAID);
|
invoice.setStatus(StatusValues.PAID);
|
||||||
invoiceService.update(invoice);
|
invoiceService.update(invoice);
|
||||||
|
|
||||||
return savedPayment;
|
return savedPayment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing Payment entity.
|
||||||
|
*
|
||||||
|
* @param payment the entity to update
|
||||||
|
* @return the updated payment
|
||||||
|
* @throws EntityNotFoundException if the payment does not exist
|
||||||
|
* @throws InvalidDataException if the payment data is invalid
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public Payment update(Payment payment) throws EntityNotFoundException, InvalidDataException {
|
public Payment update(Payment payment) throws EntityNotFoundException, InvalidDataException {
|
||||||
|
|
@ -82,22 +107,44 @@ public class PaymentService extends AbstractService<Payment, Integer> {
|
||||||
return super.update(payment);
|
return super.update(payment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies if a Payment entity exists in the database.
|
||||||
|
*
|
||||||
|
* @param entity the entity to check
|
||||||
|
* @return true if the entity exists, false otherwise
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected boolean exists(Payment entity) {
|
protected boolean exists(Payment entity) {
|
||||||
return entity != null && entity.getId() != null && paymentRepository.existsById(entity.getId());
|
return entity != null && entity.getId() != null && paymentRepository.existsById(entity.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains the ID of a Payment entity.
|
||||||
|
*
|
||||||
|
* @param entity the entity from which to retrieve the ID
|
||||||
|
* @return the ID of the Payment entity
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Integer getEntityId(Payment entity) {
|
protected Integer getEntityId(Payment entity) {
|
||||||
return entity.getId();
|
return entity.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Obtains all Payment entities.
|
||||||
|
*
|
||||||
|
* @return a list of all Payment entities
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Payment> findAll() {
|
public List<Payment> findAll() {
|
||||||
logger.info("Retrieving all payments");
|
logger.info("Retrieving all payments");
|
||||||
return super.findAll();
|
return super.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the Payment entity before saving or updating.
|
||||||
|
*
|
||||||
|
* @param payment the Payment to validate
|
||||||
|
*/
|
||||||
private void validate(Payment payment) {
|
private void validate(Payment payment) {
|
||||||
if (payment.getInvoice() == null) {
|
if (payment.getInvoice() == null) {
|
||||||
throw new InvalidDataException("Payment must be linked to an invoice");
|
throw new InvalidDataException("Payment must be linked to an invoice");
|
||||||
|
|
@ -116,6 +163,11 @@ public class PaymentService extends AbstractService<Payment, Integer> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a Payment entity by its ID.
|
||||||
|
*
|
||||||
|
* @param paymentId the ID of the payment to remove
|
||||||
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public void removePayment(Integer paymentId) {
|
public void removePayment(Integer paymentId) {
|
||||||
Payment payment = findById(paymentId);
|
Payment payment = findById(paymentId);
|
||||||
|
|
@ -131,10 +183,22 @@ public class PaymentService extends AbstractService<Payment, Integer> {
|
||||||
invoiceService.update(invoice);
|
invoiceService.update(invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds all Payment entities associated with a specific user ID.
|
||||||
|
*
|
||||||
|
* @param userId the ID of the user
|
||||||
|
* @return a list of payments associated with the user
|
||||||
|
*/
|
||||||
public List<Payment> findAllByUserId(Integer userId) {
|
public List<Payment> findAllByUserId(Integer userId) {
|
||||||
return paymentRepository.findByInvoice_User_Id(userId);
|
return paymentRepository.findByInvoice_User_Id(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves an Invoice by its ID.
|
||||||
|
*
|
||||||
|
* @param id the ID of the invoice
|
||||||
|
* @return the Invoice entity
|
||||||
|
*/
|
||||||
public Invoice getInvoiceById(Integer id) {
|
public Invoice getInvoiceById(Integer id) {
|
||||||
return invoiceService.findById(id);
|
return invoiceService.findById(id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,10 @@ import org.springframework.stereotype.Service;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service class for managing ProductService entities.
|
||||||
|
* This class provides methods to perform CRUD operations on ProductService entities.
|
||||||
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class ProductServiceService extends AbstractService<ProductService, Integer> {
|
public class ProductServiceService extends AbstractService<ProductService, Integer> {
|
||||||
|
|
||||||
|
|
@ -22,12 +26,26 @@ public class ProductServiceService extends AbstractService<ProductService, Integ
|
||||||
private final ProductServiceRepository productServiceRepository;
|
private final ProductServiceRepository productServiceRepository;
|
||||||
private final IVATypeService ivaTypeService;
|
private final IVATypeService ivaTypeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for ProductServiceService.
|
||||||
|
*
|
||||||
|
* @param productServiceRepository the repository for ProductService entities
|
||||||
|
* @param ivaTypeService the service for IVAType entities
|
||||||
|
*/
|
||||||
public ProductServiceService(ProductServiceRepository productServiceRepository, IVATypeService ivaTypeService) {
|
public ProductServiceService(ProductServiceRepository productServiceRepository, IVATypeService ivaTypeService) {
|
||||||
super(productServiceRepository);
|
super(productServiceRepository);
|
||||||
this.productServiceRepository = productServiceRepository;
|
this.productServiceRepository = productServiceRepository;
|
||||||
this.ivaTypeService = ivaTypeService;
|
this.ivaTypeService = ivaTypeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves a new ProductService entity.
|
||||||
|
*
|
||||||
|
* @param entity the product/service to save
|
||||||
|
* @return the saved product/service
|
||||||
|
* @throws IllegalArgumentException if the product/service is invalid
|
||||||
|
* @throws DuplicateEntityException if a product/service with the same name already exists
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public ProductService save(ProductService entity) throws IllegalArgumentException, DuplicateEntityException {
|
public ProductService save(ProductService entity) throws IllegalArgumentException, DuplicateEntityException {
|
||||||
|
|
@ -51,6 +69,15 @@ public class ProductServiceService extends AbstractService<ProductService, Integ
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing ProductService entity.
|
||||||
|
*
|
||||||
|
* @param entity the product/service to update
|
||||||
|
* @return the updated product/service
|
||||||
|
* @throws IllegalArgumentException if the product/service is invalid
|
||||||
|
* @throws InvalidDataException if the product/service data is invalid
|
||||||
|
* @throws EntityNotFoundException if the product/service does not exist
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public ProductService update(ProductService entity) throws IllegalArgumentException, InvalidDataException, EntityNotFoundException {
|
public ProductService update(ProductService entity) throws IllegalArgumentException, InvalidDataException, EntityNotFoundException {
|
||||||
|
|
@ -68,23 +95,44 @@ public class ProductServiceService extends AbstractService<ProductService, Integ
|
||||||
return super.update(entity);
|
return super.update(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds all ProductService entities.
|
||||||
|
*
|
||||||
|
* @return a list of all products/services
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<ProductService> findAll() {
|
public List<ProductService> findAll() {
|
||||||
logger.info("Retrieving all products/services");
|
logger.info("Retrieving all products/services");
|
||||||
return super.findAll();
|
return super.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exists method to check if a ProductService entity exists in the repository.
|
||||||
|
*
|
||||||
|
* @param entity the entity to check
|
||||||
|
* @return true if the entity exists, false otherwise
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected boolean exists(ProductService entity) {
|
protected boolean exists(ProductService entity) {
|
||||||
return entity != null && entity.getId() != null && productServiceRepository.existsById(entity.getId());
|
return entity != null && entity.getId() != null && productServiceRepository.existsById(entity.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the ID of a ProductService entity.
|
||||||
|
*
|
||||||
|
* @param entity the entity from which to retrieve the ID
|
||||||
|
* @return the ID of the ProductService entity
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Integer getEntityId(ProductService entity) {
|
protected Integer getEntityId(ProductService entity) {
|
||||||
return entity.getId();
|
return entity.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the ProductService entity before saving or updating.
|
||||||
|
*
|
||||||
|
* @param product the ProductService to validate
|
||||||
|
*/
|
||||||
private void validateProduct(ProductService product) {
|
private void validateProduct(ProductService product) {
|
||||||
if (product.getName() == null || product.getName().isBlank()) {
|
if (product.getName() == null || product.getName().isBlank()) {
|
||||||
throw new InvalidDataException("Product name cannot be null or blank");
|
throw new InvalidDataException("Product name cannot be null or blank");
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,14 @@ public class NotificationService extends AbstractService<Notification, Integer>
|
||||||
return super.findById(id);
|
return super.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates an existing notification.
|
||||||
|
*
|
||||||
|
* @param entity the notification to update
|
||||||
|
* @return the updated notification
|
||||||
|
* @throws EntityNotFoundException if the notification is not found
|
||||||
|
* @throws InvalidDataException if the entity data is invalid
|
||||||
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
@Override
|
@Override
|
||||||
public Notification update(Notification entity) throws EntityNotFoundException {
|
public Notification update(Notification entity) throws EntityNotFoundException {
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ public class StudentService extends AbstractService<Student, Integer> {
|
||||||
* Constructor for StudentService.
|
* Constructor for StudentService.
|
||||||
*
|
*
|
||||||
* @param studentRepository the student repository
|
* @param studentRepository the student repository
|
||||||
|
* @param userRepository the user repository
|
||||||
|
* @param assistanceRepository the assistance repository
|
||||||
*/
|
*/
|
||||||
public StudentService(StudentRepository studentRepository, UserRepository userRepository, AssistanceRepository assistanceRepository) {
|
public StudentService(StudentRepository studentRepository, UserRepository userRepository, AssistanceRepository assistanceRepository) {
|
||||||
super(studentRepository);
|
super(studentRepository);
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ public class TeacherService extends AbstractService<Teacher, Integer> {
|
||||||
* Constructor for TeacherService.
|
* Constructor for TeacherService.
|
||||||
*
|
*
|
||||||
* @param teacherRepository the teacher repository
|
* @param teacherRepository the teacher repository
|
||||||
|
* @param userRepository the user repository
|
||||||
*/
|
*/
|
||||||
public TeacherService(TeacherRepository teacherRepository, UserRepository userRepository) {
|
public TeacherService(TeacherRepository teacherRepository, UserRepository userRepository) {
|
||||||
super(teacherRepository);
|
super(teacherRepository);
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,13 @@ public class UserService extends AbstractService<User, Integer> {
|
||||||
return userRepository.existsByEmail(email);
|
return userRepository.existsByEmail(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an invoice to a user.
|
||||||
|
*
|
||||||
|
* @param user the user to whom the invoice will be added
|
||||||
|
* @param invoice the invoice to add
|
||||||
|
* @throws InvalidDataException if the user or invoice is null
|
||||||
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public void addInvoiceToUser(User user, Invoice invoice) throws InvalidDataException {
|
public void addInvoiceToUser(User user, Invoice invoice) throws InvalidDataException {
|
||||||
if (user == null || invoice == null) {
|
if (user == null || invoice == null) {
|
||||||
|
|
@ -167,6 +174,13 @@ public class UserService extends AbstractService<User, Integer> {
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes an invoice from a user.
|
||||||
|
*
|
||||||
|
* @param user the user from whom the invoice will be removed
|
||||||
|
* @param invoice the invoice to remove
|
||||||
|
* @throws InvalidDataException if the user or invoice is null
|
||||||
|
*/
|
||||||
@Transactional
|
@Transactional
|
||||||
public void removeInvoiceFromUser(User user, Invoice invoice) throws InvalidDataException {
|
public void removeInvoiceFromUser(User user, Invoice invoice) throws InvalidDataException {
|
||||||
if (user == null || invoice == null) {
|
if (user == null || invoice == null) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue