Skip to content

Commit 5dcbadd

Browse files
committed
Updated ParentController, ParentServiceImpl, and StudentServiceImpl with new methods.
1 parent a623e6c commit 5dcbadd

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

BackEnd/No-Country-simulation/src/main/java/com/school/rest/entityControllers/ParentController.java

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,7 @@ public ResponseEntity<DeleteResponse> deleteParent(@PathVariable Long id) {
7272
}
7373

7474
@GetMapping("/verify/{dni}")
75-
@Operation(
76-
summary = "Verify Teacher by DNI",
77-
description = "Verifies the existence of a teacher by their DNI.",
78-
responses = {
79-
@ApiResponse(
80-
responseCode = "200", description = "Teacher verification result",
81-
content = @Content(
82-
schema = @Schema(implementation = StudentResponse.class)
83-
)
84-
),
85-
@ApiResponse(
86-
responseCode = "404", description = "Teacher not found",
87-
content = @Content(
88-
schema = @Schema(implementation = ApiError.class)
89-
)
90-
)
91-
}
92-
)
93-
public ResponseEntity<StudentResponse> verifyChildByDni(@PathVariable String dni) {
94-
return ResponseEntity.ok(parentService.verifyChildByDni(dni));
75+
public ResponseEntity<StudentResponse> getStudentAndParentByDni(@PathVariable String dni) {
76+
return ResponseEntity.ok(parentService.getStudentAndParentByDni(dni));
9577
}
9678
}

BackEnd/No-Country-simulation/src/main/java/com/school/service/implementation/ParentServiceImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ public DeleteResponse delete(Long id) {
151151
return new DeleteResponse("Parent successfully deleted", true);
152152
}
153153

154-
public StudentResponse verifyChildByDni(String dni) {
155-
return studentService.verifyChildByDni(dni);
156-
}
157-
158154
public StudentResponse verifyStudentByParentDni(String dni) {
159155
// Buscar el padre por DNI
160156
Parent parent = parentRepository.findByDniWithChildren(dni)
@@ -174,4 +170,8 @@ public StudentResponse verifyStudentByParentDni(String dni) {
174170
// Devolver la información del hijo como DTO
175171
return new StudentResponse(student.getDni(), student.getName(), student.getLastName(), student.getYear(), student.getSession(), parent.getName(), parent.getLastName());
176172
}
173+
174+
public StudentResponse getStudentAndParentByDni(String dni) {
175+
return studentService.getStudentAndParentByDni(dni);
176+
}
177177
}

BackEnd/No-Country-simulation/src/main/java/com/school/service/implementation/StudentServiceImpl.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,23 @@ public StudentResponse verifyChildByDni(String dni) {
165165
public Optional<Student> findStudentByDni(String dni) {
166166
return studentRepository.findByDni(dni);
167167
}
168+
169+
public StudentResponse getStudentAndParentByDni(String dni) {
170+
// Buscar el hijo por DNI
171+
Student student = studentRepository.findByDniWithParents(dni)
172+
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND,
173+
"Child not found with DNI: " + dni));
174+
175+
// Obtener la lista de padres
176+
Set<Parent> parents = student.getParents();
177+
178+
if (parents == null || parents.isEmpty()) {
179+
throw new ResponseStatusException(HttpStatus.NOT_FOUND,
180+
"No parents found for the child with DNI: " + dni);
181+
}
182+
Parent parent = parents.iterator().next();
183+
184+
// Devolver la información del hijo como DTO
185+
return new StudentResponse(student.getDni(), student.getName(), student.getLastName(), student.getYear(), student.getSession(), parent.getName(), parent.getLastName());
186+
}
168187
}

0 commit comments

Comments
 (0)