Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.ironhack.application.usecase.doctor;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ironhack.application.dto.DoctorDTO;
import com.ironhack.application.dto.response.ApiResponse;
import com.ironhack.infra.adapter.mapper.MappingFacade;
import com.ironhack.infra.adapter.output.DoctorRepository;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class ListDoctorsUseCase {
private final DoctorRepository doctorRepository;
private final MappingFacade mappingFacade;

@Transactional(readOnly = true)
public ApiResponse<List<DoctorDTO>> invoke() {
var entities = doctorRepository.findAll();
var dtos = mappingFacade.toDoctorDTOList(entities);
return ApiResponse.success(dtos, "Doctors retrieved successfully.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.ironhack.application.usecase.patient;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ironhack.application.dto.PatientDTO;
import com.ironhack.application.dto.response.ApiResponse;
import com.ironhack.infra.adapter.mapper.MappingFacade;
import com.ironhack.infra.adapter.output.PatientRepository;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class ListPatientsUseCase {
private final PatientRepository patientRepository;
private final MappingFacade mappingFacade;

@Transactional(readOnly = true)
public ApiResponse<List<PatientDTO>> invoke() {
var entities = patientRepository.findAll();
var dtos = mappingFacade.toPatientDTOList(entities);
return ApiResponse.success(dtos, "Patients retrieved successfully.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.ironhack.application.usecase.appointment.ListDoctorAppointmentsUseCase;
import com.ironhack.application.usecase.doctor.AssignSpecialtyToDoctorUseCase;
import com.ironhack.application.usecase.doctor.CreateDoctorUseCase;
import com.ironhack.application.usecase.doctor.ListDoctorsUseCase;
import com.ironhack.domain.AppointmentStatus;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand All @@ -29,6 +30,13 @@ public class DoctorRestAdapter {
private final CreateDoctorUseCase createDoctorUseCase;
private final AssignSpecialtyToDoctorUseCase assignSpecialtyToDoctorUseCase;
private final ListDoctorAppointmentsUseCase listDoctorAppointmentsUseCase;
private final ListDoctorsUseCase listDoctorsUseCase;

@GetMapping
public ResponseEntity<ApiResponse<List<DoctorDTO>>> listDoctors() {
ApiResponse<List<DoctorDTO>> body = listDoctorsUseCase.invoke();
return ResponseEntity.ok(body);
}

@PostMapping
public ResponseEntity<ApiResponse<DoctorDTO>> createDoctor(@Valid @RequestBody CreateDoctorRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.ironhack.application.dto.response.ApiResponse;
import com.ironhack.application.usecase.appointment.ListPatientAppointmentsUseCase;
import com.ironhack.application.usecase.patient.CreatePatientUseCase;
import com.ironhack.application.usecase.patient.ListPatientsUseCase;
import com.ironhack.domain.AppointmentStatus;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand All @@ -32,6 +33,13 @@
public class PatientRestAdapter {
private final CreatePatientUseCase createPatientUseCase;
private final ListPatientAppointmentsUseCase listPatientAppointmentsUseCase;
private final ListPatientsUseCase listPatientsUseCase;

@GetMapping
public ResponseEntity<ApiResponse<List<PatientDTO>>> listPatients() {
ApiResponse<List<PatientDTO>> body = listPatientsUseCase.invoke();
return ResponseEntity.ok(body);
}

@PostMapping
public ResponseEntity<ApiResponse<PatientDTO>> createPatient(@Valid @RequestBody CreatePatientRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@Mapper(config = MapStructConfig.class)
public interface DoctorMapper {
DoctorDTO toDoctorDTO(DoctorEntity doctorEntity);
java.util.List<DoctorDTO> toDoctorDTOList(java.util.List<DoctorEntity> doctorEntities);

@Mapping(target = "id", ignore = true)
DoctorEntity toDoctorEntity(CreateDoctorRequest createDoctorRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public AppointmentDTO toAppointmentDTO(AppointmentEntity entity) {
return appointmentMapper.toAppointmentDTO(entity);
}

public List<DoctorDTO> toDoctorDTOList(List<DoctorEntity> entities) {
return doctorMapper.toDoctorDTOList(entities);
}

public List<PatientDTO> toPatientDTOList(List<PatientEntity> entities) {
return patientMapper.toPatientDTOList(entities);
}

public List<AppointmentDTO> toAppointmentDTOList(List<AppointmentEntity> entities) {
return appointmentMapper.toAppointmentDTOList(entities);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@Mapper(config = MapStructConfig.class)
public interface PatientMapper {
PatientDTO toPatientDTO(PatientEntity patientEntity);
java.util.List<PatientDTO> toPatientDTOList(java.util.List<PatientEntity> patientEntities);

@Mapping(target = "id", ignore = true)
PatientEntity toPatientEntity(CreatePatientRequest createPatientRequest);
Expand Down
Loading
Loading