Skip to content

Commit

Permalink
Merge branch '1-create-table-for-medtype' of https://github.com/E-Hay…
Browse files Browse the repository at this point in the history
…van/e-hayvan-backend into 1-create-table-for-medtype
  • Loading branch information
FruTooTi committed Jan 1, 2024
2 parents 5ae7d07 + 60d046c commit e9bb2b4
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,37 @@ 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);
}
}
@GetMapping("/all/{petOwnerId}")
public ResponseEntity<List<AppointmentDTO>> getAllAppointmentsForPetOwner(@PathVariable Integer petOwnerId) {
List<AppointmentDTO> response = appointmentService.getAllAppointmentsForPetOwner(petOwnerId);

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

@GetMapping("/all/veterinarian/{vetId}")
public ResponseEntity<List<AppointmentDTO>> getAllAppointmentsForVeterinarian(@PathVariable Integer vetId) {
List<AppointmentDTO> response = appointmentService.getAllAppointmentsForVeterinarian(vetId);

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 @@ -6,6 +6,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/medtypes")
public class MedTypeController {
Expand All @@ -26,6 +28,17 @@ public ResponseEntity<MedTypeDTO> getMedTypeById(@PathVariable Integer id) {
}
}

@GetMapping("/all")
public ResponseEntity<List<MedTypeDTO>> getAllMedTypes() {
List<MedTypeDTO> response = medTypeService.getAllMedTypes();

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

@DeleteMapping("/{id}")
public ResponseEntity<MedTypeDTO> deleteMedType(@PathVariable Integer id) {
MedTypeDTO deletedMedType = medTypeService.deleteMedType(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/medications")
public class MedicationController {
Expand All @@ -26,6 +28,18 @@ public ResponseEntity<MedicationDTO> getMedicationById(@PathVariable Integer id)
}
}

@GetMapping("/all")
public ResponseEntity<List<MedicationDTO>> getAllMedications() {
List<MedicationDTO> response = medicationService.getAllMedications();

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


@PostMapping
public ResponseEntity<MedicationDTO> postMedication(@RequestBody CreateOrUpdateMedicationDTO medicationDto){
MedicationDTO postedMedication = medicationService.postMedication(medicationDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.web.bind.annotation.*;

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

@RestController
@RequestMapping("/api/pets")
Expand All @@ -29,12 +30,17 @@ public ResponseEntity<PetDTO> getPetById(@PathVariable Integer id) {
}
}

// @GetMapping
// public ResponseEntity<List<PetDTO>> getAllPets() {
// List<PetDTO> petDTOList = petService.getAllPets();
// return new ResponseEntity<>(petDTOList, HttpStatus.OK);
// }
//
@GetMapping("/all/{petOwnerId}")
public ResponseEntity<List<PetDTO>> getAllPetsForPetOwner(@PathVariable Integer petOwnerId) {
List<PetDTO> response = petService.getAllPetsForPetOwner(petOwnerId);

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

@PostMapping
public ResponseEntity<PetDTO> savePet(@RequestBody CreateOrUpdatePetDTO petDTO) {
PetDTO savedPet = petService.postPet(petDTO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/petowners")
public class PetOwnerController {
Expand All @@ -27,6 +29,17 @@ public ResponseEntity<PetOwnerDTO> getPetOwnerById(@PathVariable Integer id) {
}
}

@GetMapping("/forVet/{vetId}")
public ResponseEntity<List<PetOwnerDTO>> getPetOwnersForVeterinarian(@PathVariable Integer vetId) {
List<PetOwnerDTO> response = petOwnerService.getPetOwnersForVeterinarian(vetId);

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

@PostMapping("/newowner")
public ResponseEntity<PetOwnerDTO> savePetOwner(@RequestBody CreateOrUpdatePetOwnerDTO petOwnerDTO) {
PetOwnerDTO savedPetOwner = petOwnerService.postPetOwner(petOwnerDTO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ResponseEntity<ScheduleDTO> getScheduleById(@PathVariable Integer id) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}

@DeleteMapping("/{id}")
public ResponseEntity<ScheduleDTO> deleteSchedule(@PathVariable Integer id) {
ScheduleDTO deletedSchedule = scheduleService.deleteSchedule(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@

import com.production.ehayvanbackendapi.Entities.Appointment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

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

@Repository
public interface AppointmentRepository extends JpaRepository<Appointment, Integer> {
@Query(value="SELECT *FROM Appointment WHERE Appointment.pet_ownerid= :pet_ownerid",nativeQuery = true)
public Optional<List<Appointment>> getAppointmentsForPetOwnerId (@Param("pet_ownerid") int pet_ownerid);
@Query(value="SELECT *FROM Appointment WHERE Appointment.vetid= :vetid",nativeQuery = true)
public Optional<List<Appointment>> getAppointmentsForVetID(@Param("vetid") int vetid);

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package com.production.ehayvanbackendapi.Repositories;

import com.production.ehayvanbackendapi.Entities.Pet;
import com.production.ehayvanbackendapi.Entities.PetOwner;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

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

@Repository
public interface PetOwnerRepository extends JpaRepository<PetOwner, Integer> {
@Query(value="SELECT *FROM pet_owner WHERE pet_owner.vetid = :vetid",nativeQuery = true)
public Optional<List<PetOwner>> getAllPetsForPetOwner(@Param("vetid") int vetid);
}

Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package com.production.ehayvanbackendapi.Repositories;

import com.production.ehayvanbackendapi.Entities.Appointment;
import com.production.ehayvanbackendapi.Entities.Pet;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

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

@Repository
public interface PetRepository extends JpaRepository<Pet, Integer> {
@Query(value="SELECT *FROM Pet WHERE Pet.pet_ownerid = :pet_ownerid",nativeQuery = true)
public Optional<List<Pet>> getAllPetsForPetOwner(@Param("pet_ownerid") int pet_ownerid);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.production.ehayvanbackendapi.Services;

import com.production.ehayvanbackendapi.DTO.AppointmentDTO;
import com.production.ehayvanbackendapi.DTO.PetOwnerDTO;
import com.production.ehayvanbackendapi.DTO.request.CreateOrUpdateAppointmentDTO;
import com.production.ehayvanbackendapi.Entities.Appointment;
import com.production.ehayvanbackendapi.Entities.Pet;
Expand All @@ -9,6 +10,8 @@
import com.production.ehayvanbackendapi.Mappers.AppointmentMapper;
import com.production.ehayvanbackendapi.Repositories.AppointmentRepository;

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

Expand All @@ -29,6 +32,44 @@ 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 List<AppointmentDTO> getAllAppointmentsForPetOwner(Integer petOwnerId) {
Optional<List<Appointment>> appointmentsOptional = appointmentRepository.getAppointmentsForPetOwnerId(petOwnerId);

if (appointmentsOptional.isPresent()) {
List<AppointmentDTO> appointmentDtoList = new ArrayList<>();
for (Appointment appointment : appointmentsOptional.get()) {
appointmentDtoList.add(appointmentMapper.convertToDto(appointment));
}
return appointmentDtoList;
} else {
return null;
}
}
public List<AppointmentDTO> getAllAppointmentsForVeterinarian(Integer vetId) {
Optional<List<Appointment>> appointmentsOptional = appointmentRepository.getAppointmentsForVetID(vetId);

if (appointmentsOptional.isPresent()) {
List<AppointmentDTO> appointmentDtoList = new ArrayList<>();
for (Appointment appointment : appointmentsOptional.get()) {
appointmentDtoList.add(appointmentMapper.convertToDto(appointment));
}
return appointmentDtoList;
} else {
return Collections.emptyList(); // empty list mi dönmeli null mı emin olamadım
}
}

public AppointmentDTO postAppointment(CreateOrUpdateAppointmentDTO appointmentDto){
// Map the appointment dto to appointment.
Appointment newAppointment = appointmentMapper.convertToEntity(appointmentDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.production.ehayvanbackendapi.Repositories.MedTypeRepository;
import com.production.ehayvanbackendapi.Repositories.MedicationRepository;

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

Expand All @@ -28,6 +29,17 @@ public MedTypeDTO getMedTypeById(Integer id) {
return medType != null ? medTypeMapper.convertToDto(medType) : null;
}

public List<MedTypeDTO> getAllMedTypes() {
List<MedType> medTypeList = medTypeRepository.findAll();
List<MedTypeDTO> medTypeDtoList = new ArrayList<>();

for (MedType medType : medTypeList) {
medTypeDtoList.add(medTypeMapper.convertToDto(medType));
}

return medTypeDtoList;
}

//gerekli mi bilemedim?????
public MedTypeDTO deleteMedType(Integer id) {
// Find the target MedType to delete.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
Expand All @@ -28,6 +30,17 @@ public MedicationDTO getMedicationById(Integer id) {
return medication != null ? medicationMapper.convertToDto(medication) : null;
}

public List<MedicationDTO> getAllMedications() {
List<Medication> medicationList = medicationRepository.findAll();
List<MedicationDTO> medicationDtoList = new ArrayList<>();

for (Medication medication : medicationList) {
medicationDtoList.add(medicationMapper.convertToDto(medication));
}

return medicationDtoList;
}

public MedicationDTO postMedication(CreateOrUpdateMedicationDTO medicationDto){
// Create a new medication from the dto.
Medication newMedication = medicationMapper.convertToEntity(medicationDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ public PetOwnerService(PetOwnerRepository petOwnerRepository, PetOwnerMapper pet
this.petOwnerMapper = petOwnerMapper;
}

public List<PetOwnerDTO> getPetOwnersForVeterinarian(Integer vetId) {
Optional<List<PetOwner>> petOwnersOptional = petOwnerRepository.getAllPetsForPetOwner(vetId);

if (petOwnersOptional.isPresent()) {
List<PetOwnerDTO> petOwnerDtoList = new ArrayList<>();
for (PetOwner petOwner : petOwnersOptional.get()) {
petOwnerDtoList.add(petOwnerMapper.convertToDto(petOwner));
}
return petOwnerDtoList;
} else {
return null;
}
}

public PetOwnerDTO getPetOwnerById(Integer id) {
Optional<PetOwner> petOwner = petOwnerRepository.findById(id);
// Listeler otomatik olarak mapleniyor. Şimdilik bir problem yok.
Expand All @@ -40,7 +54,6 @@ public PetOwnerDTO getPetOwnerById(Integer id) {
}
// Other service methods for updating, deleting pet owners, etc.

// TODO: getAllPetOwners() fonksiyonu oluşturulacak.

public PetOwnerDTO postPetOwner(CreateOrUpdatePetOwnerDTO petOwnerDTO){
// Map the data transfer object data to real object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,21 @@ public PetDTO deletePet(Integer id){
return null;
}

// public List<PetDTO> getAllPets() {
// List<Pet> pets = petRepository.findAll();
// return petMapper.mapList(pets, PetDTO.class);
// }
public List<PetDTO> getAllPetsForPetOwner(Integer petOwnerId) {
Optional<List<Pet>> petsOptional = petRepository.getAllPetsForPetOwner(petOwnerId);

if (petsOptional.isPresent()) {
List<PetDTO> petDtoList = new ArrayList<>();
for (Pet pet : petsOptional.get()) {
petDtoList.add(petMapper.convertToDto(pet));
}
return petDtoList;
} else {
return null;
}
}



// Other service methods
}

0 comments on commit e9bb2b4

Please sign in to comment.