diff --git a/src/main/java/com/production/ehayvanbackendapi/Controllers/CustomerController.java b/src/main/java/com/production/ehayvanbackendapi/Controllers/CustomerController.java index 9df6756..7df9689 100644 --- a/src/main/java/com/production/ehayvanbackendapi/Controllers/CustomerController.java +++ b/src/main/java/com/production/ehayvanbackendapi/Controllers/CustomerController.java @@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + @RestController @RequestMapping("/api/customers") public class CustomerController { @@ -32,7 +34,17 @@ public ResponseEntity getCustomerById(@PathVariable Integer id) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } } + @GetMapping("/all") + public ResponseEntity> getAllCustomers(){ + List response = customerService.getAllCustomers(); + if(response != null){ + return new ResponseEntity<>(response, HttpStatus.OK); + } + else { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + } // @PostMapping // public ResponseEntity createCustomer(@RequestBody CustomerDTO customerDTO) { // CustomerDTO createdCustomer = customerService.createCustomer(customerDTO); diff --git a/src/main/java/com/production/ehayvanbackendapi/Controllers/MedicationController.java b/src/main/java/com/production/ehayvanbackendapi/Controllers/MedicationController.java index 5fbe979..23f1fa0 100644 --- a/src/main/java/com/production/ehayvanbackendapi/Controllers/MedicationController.java +++ b/src/main/java/com/production/ehayvanbackendapi/Controllers/MedicationController.java @@ -4,11 +4,10 @@ import com.production.ehayvanbackendapi.Services.MedicationService; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.*; +@RestController +@RequestMapping("/api/medications") public class MedicationController { private final MedicationService medicationService; diff --git a/src/main/java/com/production/ehayvanbackendapi/DTO/AppointmentDTO.java b/src/main/java/com/production/ehayvanbackendapi/DTO/AppointmentDTO.java index 1bd0b2a..b673312 100644 --- a/src/main/java/com/production/ehayvanbackendapi/DTO/AppointmentDTO.java +++ b/src/main/java/com/production/ehayvanbackendapi/DTO/AppointmentDTO.java @@ -9,7 +9,9 @@ public class AppointmentDTO { private Integer petID; private Date appointmentDate; + public AppointmentDTO(){ + } public AppointmentDTO(Integer appointmentID, Integer petOwnerID, Integer vetID, Integer petID, Date appointmentDate) { this.appointmentID = appointmentID; this.petOwnerID = petOwnerID; diff --git a/src/main/java/com/production/ehayvanbackendapi/DTO/CustomerDTO.java b/src/main/java/com/production/ehayvanbackendapi/DTO/CustomerDTO.java index 528a828..2561a85 100644 --- a/src/main/java/com/production/ehayvanbackendapi/DTO/CustomerDTO.java +++ b/src/main/java/com/production/ehayvanbackendapi/DTO/CustomerDTO.java @@ -10,7 +10,9 @@ public class CustomerDTO { private Integer vetID; private Integer ownerID; + public CustomerDTO(){ + } public CustomerDTO(Integer userID, String name, String surname, String email, String password, Integer userTypeID, Integer vetID, Integer ownerID) { this.userID = userID; diff --git a/src/main/java/com/production/ehayvanbackendapi/DTO/MedicationDTO.java b/src/main/java/com/production/ehayvanbackendapi/DTO/MedicationDTO.java index d51ae5f..b561d2c 100644 --- a/src/main/java/com/production/ehayvanbackendapi/DTO/MedicationDTO.java +++ b/src/main/java/com/production/ehayvanbackendapi/DTO/MedicationDTO.java @@ -7,7 +7,9 @@ public class MedicationDTO { private Integer scheduleID; private Integer petID; + public MedicationDTO(){ + } public MedicationDTO(Integer medicationID, String medicationName, Integer medTypeID, Integer scheduleID, Integer petID) { this.medicationID = medicationID; @@ -55,11 +57,4 @@ public Integer getPetID() { public void setPetID(Integer petID) { this.petID = petID; } - - - - - - - } diff --git a/src/main/java/com/production/ehayvanbackendapi/Mappers/AppointmentMapper.java b/src/main/java/com/production/ehayvanbackendapi/Mappers/AppointmentMapper.java index 4988ba0..b7c526f 100644 --- a/src/main/java/com/production/ehayvanbackendapi/Mappers/AppointmentMapper.java +++ b/src/main/java/com/production/ehayvanbackendapi/Mappers/AppointmentMapper.java @@ -1,7 +1,9 @@ package com.production.ehayvanbackendapi.Mappers; import com.production.ehayvanbackendapi.DTO.AppointmentDTO; +import com.production.ehayvanbackendapi.DTO.CustomerDTO; import com.production.ehayvanbackendapi.Entities.Appointment; +import com.production.ehayvanbackendapi.Entities.Customer; import org.modelmapper.ModelMapper; import org.springframework.stereotype.Component; @@ -11,6 +13,14 @@ public class AppointmentMapper { public AppointmentMapper(ModelMapper modelMapper) { this.modelMapper = modelMapper; + this.modelMapper.getConfiguration().setAmbiguityIgnored(true); + this.modelMapper.createTypeMap(Appointment.class, AppointmentDTO.class).addMappings( + mapper -> { + mapper.map(src -> src.getPetID().getPetID(), AppointmentDTO::setPetID); + mapper.map(src -> src.getVetID().getVetID(), AppointmentDTO::setVetID); + mapper.map(src -> src.getPetOwnerID().getPetOwnerID(), AppointmentDTO::setPetOwnerID); + } + ); } public AppointmentDTO convertToDto(Appointment appointment) { diff --git a/src/main/java/com/production/ehayvanbackendapi/Mappers/CustomerMapper.java b/src/main/java/com/production/ehayvanbackendapi/Mappers/CustomerMapper.java index 5c17a26..08fa1da 100644 --- a/src/main/java/com/production/ehayvanbackendapi/Mappers/CustomerMapper.java +++ b/src/main/java/com/production/ehayvanbackendapi/Mappers/CustomerMapper.java @@ -10,10 +10,17 @@ public class CustomerMapper { public CustomerMapper(ModelMapper modelMapper) { this.modelMapper = modelMapper; + this.modelMapper.createTypeMap(Customer.class, CustomerDTO.class).addMappings( + mapper -> { + mapper.map(src -> src.getVet().getVetID(), CustomerDTO::setVetID); + mapper.map(src -> src.getOwner().getPetOwnerID(), CustomerDTO::setOwnerID); + mapper.map(src -> src.getUserTypeID().getUserTypeID(), CustomerDTO::setUserTypeID); + } + ); } public CustomerDTO convertToDto(Customer customer) { - return modelMapper.map(customer, CustomerDTO.class); + return modelMapper.map(customer, CustomerDTO.class); } public Customer convertToEntity(CustomerDTO customerDTO) { diff --git a/src/main/java/com/production/ehayvanbackendapi/Mappers/MedicationMapper.java b/src/main/java/com/production/ehayvanbackendapi/Mappers/MedicationMapper.java index 94a93e3..1e9797d 100644 --- a/src/main/java/com/production/ehayvanbackendapi/Mappers/MedicationMapper.java +++ b/src/main/java/com/production/ehayvanbackendapi/Mappers/MedicationMapper.java @@ -11,6 +11,13 @@ public class MedicationMapper { public MedicationMapper(ModelMapper modelMapper) { this.modelMapper = modelMapper; + this.modelMapper.createTypeMap(Medication.class, MedicationDTO.class).addMappings( + mapper -> { + mapper.map(src -> src.getPetID().getPetID(), MedicationDTO::setPetID); + mapper.map(src -> src.getScheduleID().getScheduleID(), MedicationDTO::setScheduleID); + mapper.map(src -> src.getMedTypeID().getMedTypeID(), MedicationDTO::setMedTypeID); + } + ); } public MedicationDTO convertToDto(Medication medication) { diff --git a/src/main/java/com/production/ehayvanbackendapi/Services/CustomerService.java b/src/main/java/com/production/ehayvanbackendapi/Services/CustomerService.java index deebec0..b5250d4 100644 --- a/src/main/java/com/production/ehayvanbackendapi/Services/CustomerService.java +++ b/src/main/java/com/production/ehayvanbackendapi/Services/CustomerService.java @@ -5,6 +5,7 @@ import com.production.ehayvanbackendapi.Mappers.CustomerMapper; import com.production.ehayvanbackendapi.Repositories.CustomerRepository; +import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; @@ -32,6 +33,14 @@ public CustomerDTO getCustomerById(Integer id) { // return customerMapper.convertToDto(savedCustomer); // } + public List getAllCustomers(){ + List customerList = customerRepository.findAll(); + List customerDtoList = new ArrayList<>(); + for(Customer cust: customerList){ + customerDtoList.add(customerMapper.convertToDto(cust)); + } + return customerDtoList; + } // Other service methods for creating, updating, and deleting customers } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c96ef72..8d27f7e 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -5,3 +5,5 @@ spring.datasource.driver-class-name=org.postgresql.Driver spring.jpa.generate-ddl=true spring.jpa.hibernate.ddl-auto=update spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.PostgreSQLDialect +spring.security.user.name=test +spring.security.user.password=password