Skip to content

Commit

Permalink
add count for pet, pet owner and vet
Browse files Browse the repository at this point in the history
  • Loading branch information
ituitis20-karadagd20 committed Jan 3, 2024
1 parent 55ba3ec commit c1ad030
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public ResponseEntity<PetDTO> getPetById(@PathVariable Integer id) {
}
}

@GetMapping("/count")
public ResponseEntity<Integer> getAllPetsCount() {
int count = petService.getAllPetsCount();
return new ResponseEntity<>(count, HttpStatus.OK);
}

@GetMapping("/all/{petOwnerId}")
public ResponseEntity<List<PetDTO>> getAllPetsForPetOwner(@PathVariable Integer petOwnerId) {
List<PetDTO> response = petService.getAllPetsForPetOwner(petOwnerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public ResponseEntity<PetOwnerDTO> getPetOwnerById(@PathVariable Integer id) {
}
}

@GetMapping("/count")
public ResponseEntity<Integer> getAllPetOwnersCount() {
int count = petOwnerService.getAllPetOwnersCount();
return new ResponseEntity<>(count, HttpStatus.OK);
}

@GetMapping("/forVet/{vetId}")
public ResponseEntity<List<PetOwnerDTO>> getPetOwnersForVeterinarian(@PathVariable Integer vetId) {
List<PetOwnerDTO> response = petOwnerService.getPetOwnersForVeterinarian(vetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public VeterinarianController(VeterinarianService veterinarianService) {
this.veterinarianService = veterinarianService;
}

@GetMapping("/count")
public ResponseEntity<Integer> getAllVetsCount() {
int count = veterinarianService.getAllVetsCount();
return new ResponseEntity<>(count, HttpStatus.OK);
}
@GetMapping("/{id}")
public ResponseEntity<VeterinarianDTO> getVeterinarianById(@PathVariable Integer id) {
VeterinarianDTO veterinarianDTO = veterinarianService.getVeterinarianById(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
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);

@Query(value = "SELECT COUNT(*) FROM pet_owner", nativeQuery = true)
public int getAllPetOwnersCount();
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@
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);

@Query(value = "SELECT COUNT(*) FROM pet", nativeQuery = true)
public int getAllPetsCount();

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ public interface VeterinarianRepository extends JpaRepository<Veterinarian, Inte
@Query(value = "SELECT veterinarian.* FROM veterinarian INNER JOIN customer ON veterinarian.userid = customer.userid WHERE name LIKE :name%",
nativeQuery = true)
public List<Veterinarian> findVeterinariansByName(@Param("name") String name);

@Query(value = "SELECT COUNT(*) FROM veterinarian", nativeQuery = true)
public int getAllVetsCount();
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public List<PetOwnerDTO> getPetOwnersForVeterinarian(Integer vetId) {
}
}

public int getAllPetOwnersCount() {
return petOwnerRepository.getAllPetOwnersCount();
}

public PetOwnerDTO getPetOwnerById(Integer id) {
Optional<PetOwner> petOwner = petOwnerRepository.findById(id);
// Listeler otomatik olarak mapleniyor. Şimdilik bir problem yok.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public PetService(PetRepository petRepository, PetMapper petMapper) {
this.petMapper = petMapper;
}

public int getAllPetsCount() {
return petRepository.getAllPetsCount();
}

public PetDTO getPetById(Integer id) {
// Find pet if exists.
Optional<Pet> pet = petRepository.findById(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public VeterinarianService(VeterinarianRepository veterinarianRepository, Veteri
this.veterinarianMapper = veterinarianMapper;
}

public int getAllVetsCount() {
return veterinarianRepository.getAllVetsCount();
}

public VeterinarianDTO getVeterinarianById(Integer id) {
Veterinarian veterinarian = veterinarianRepository.findById(id).orElse(null);
return veterinarian != null ? veterinarianMapper.convertToDto(veterinarian) : null;
Expand Down

0 comments on commit c1ad030

Please sign in to comment.