Skip to content

Commit

Permalink
getAll operation for appointment
Browse files Browse the repository at this point in the history
  • Loading branch information
ituitis20-karadagd20 committed Jan 1, 2024
1 parent 5818722 commit cc9045a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ public ResponseEntity<AppointmentDTO> getAppointmentById(@PathVariable Integer i
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
@GetMapping("/all")
public ResponseEntity<List<AppointmentDTO>> getAllAppointments() {
List<AppointmentDTO> response = appointmentService.getAllAppointments();

if (!response.isEmpty()) {
return new ResponseEntity<>(response, HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}

@PostMapping
public ResponseEntity<AppointmentDTO> saveAppointment(@RequestBody CreateOrUpdateAppointmentDTO appointmentDTO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.production.ehayvanbackendapi.Mappers.AppointmentMapper;
import com.production.ehayvanbackendapi.Repositories.AppointmentRepository;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand All @@ -29,6 +30,17 @@ public AppointmentDTO getAppointmentById(Integer id) {
return appointment != null ? appointmentMapper.convertToDto(appointment) : null;
}

public List<AppointmentDTO> getAllAppointments() {
List<Appointment> appointmentList = appointmentRepository.findAll();
List<AppointmentDTO> appointmentDtoList = new ArrayList<>();

for (Appointment appointment : appointmentList) {
appointmentDtoList.add(appointmentMapper.convertToDto(appointment));
}

return appointmentDtoList;
}

public AppointmentDTO postAppointment(CreateOrUpdateAppointmentDTO appointmentDto){
// Map the appointment dto to appointment.
Appointment newAppointment = appointmentMapper.convertToEntity(appointmentDto);
Expand Down

0 comments on commit cc9045a

Please sign in to comment.