-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
564 additions
and
99 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
backend/src/main/java/com/greenfoxacademy/backend/controller/PetController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.greenfoxacademy.backend.controller; | ||
|
||
import com.greenfoxacademy.backend.dtos.PetListResponseDto; | ||
import com.greenfoxacademy.backend.services.pet.PetService; | ||
import java.security.Principal; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* A REST controller that handles operations related to users' pets. | ||
* | ||
* @author Your Name | ||
*/ | ||
@RequiredArgsConstructor | ||
@RestController | ||
public class PetController { | ||
private final PetService petService; | ||
|
||
@GetMapping("/pets") | ||
public ResponseEntity<PetListResponseDto> getPets(Principal owner) { | ||
return ResponseEntity.status(HttpStatus.OK).body(petService.getOwnerPets(owner.getName())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/com/greenfoxacademy/backend/dtos/PetDetailsDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.greenfoxacademy.backend.dtos; | ||
|
||
import jakarta.validation.constraints.FutureOrPresent; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.PastOrPresent; | ||
import java.util.Date; | ||
import lombok.Data; | ||
|
||
/** | ||
* A data transfer object for pet details. | ||
* | ||
* @author Your Name | ||
*/ | ||
@Data | ||
public class PetDetailsDto { | ||
@NotBlank | ||
String name; | ||
@NotBlank | ||
String breed; | ||
@NotBlank | ||
String sex; | ||
@PastOrPresent(message = "The birth date must be in the past or present") | ||
Date birthDate; | ||
@PastOrPresent(message = "The last check-up date must be in the past or present") | ||
Date lastCheckUp; | ||
@FutureOrPresent(message = "The next check-up date must be in the future or present") | ||
Date nextCheckUp; | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/com/greenfoxacademy/backend/dtos/PetListResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.greenfoxacademy.backend.dtos; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A data transfer object for a list of pets. | ||
* | ||
*/ | ||
public record PetListResponseDto( | ||
List<PetDetailsDto> pets | ||
){ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
backend/src/main/java/com/greenfoxacademy/backend/repositories/ClinicAddressRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.greenfoxacademy.backend.repositories; | ||
|
||
import com.greenfoxacademy.backend.models.ClinicAddress; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
/** | ||
* ClinicAddressRepository provides database access methods for ClinicAddress entities. | ||
* It extends JpaRepository to perform CRUD operations. | ||
*/ | ||
public interface ClinicAddressRepository extends JpaRepository<ClinicAddress, Long> { | ||
|
||
/** | ||
* Retrieves a list of clinic addresses based on partial matches for zip code, city, or street. | ||
* | ||
* @param zip the partial or full zip code of the clinic address. | ||
* @param city the partial or full city name of the clinic address. | ||
* @param street the partial or full street name of the clinic address. | ||
* @return a list of clinic addresses matching the given criteria. | ||
*/ | ||
List<ClinicAddress> findAllByZipContainingOrCityContainingOrStreetContaining( | ||
int zip, String city, String street); | ||
} |
21 changes: 21 additions & 0 deletions
21
backend/src/main/java/com/greenfoxacademy/backend/repositories/ClinicDetailsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.greenfoxacademy.backend.repositories; | ||
|
||
import com.greenfoxacademy.backend.models.ClinicDetails; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
|
||
/** | ||
* ClinicDetailsRepository provides database access methods for ClinicDetails entities. | ||
* It extends JpaRepository to perform CRUD operations. | ||
*/ | ||
public interface ClinicDetailsRepository extends JpaRepository<ClinicDetails, Long> { | ||
|
||
/** | ||
* Retrieves a list of clinic details where the clinic name contains the specified word. | ||
* | ||
* @param word a partial or full word to search within clinic names. | ||
* @return a list of clinic details matching the specified word in their names. | ||
*/ | ||
List<ClinicDetails> findAllByClinicNameContaining(String word); | ||
} |
25 changes: 24 additions & 1 deletion
25
backend/src/main/java/com/greenfoxacademy/backend/repositories/VetRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,30 @@ | ||
package com.greenfoxacademy.backend.repositories; | ||
|
||
import com.greenfoxacademy.backend.models.Vet; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface VetRepository extends JpaRepository<Vet,Long> { | ||
/** | ||
* VetRepository provides database access methods for Vet entities. | ||
* It extends JpaRepository to perform CRUD operations. | ||
*/ | ||
public interface VetRepository extends JpaRepository<Vet, Long> { | ||
|
||
/** | ||
* Retrieves a list of vets based on the first or last name. | ||
* | ||
* @param firstName the first name of the vet. | ||
* @param lastName the last name of the vet. | ||
* @return a list of vets matching the given first or last name. | ||
*/ | ||
List<Vet> findAllByFirstNameOrLastName(String firstName, String lastName); | ||
|
||
/** | ||
* Retrieves a list of vets based on the clinic name. | ||
* | ||
* @param clinicName the name of the clinic. | ||
* @return a list of vets working at the clinic with the given name. | ||
*/ | ||
List<Vet> findAllByClinicDetailsClinicName(String clinicName); | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
backend/src/main/java/com/greenfoxacademy/backend/services/pet/PetService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.greenfoxacademy.backend.services.pet; | ||
|
||
import com.greenfoxacademy.backend.dtos.PetListResponseDto; | ||
import org.springframework.security.core.userdetails.UserDetailsService; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Retrieves the pets of the specified owner. | ||
* | ||
* @param name The name of the owner. | ||
* @return A response containing the owner's pets. | ||
*/ | ||
|
||
public interface PetService { | ||
PetListResponseDto getOwnerPets(String name); | ||
} |
43 changes: 43 additions & 0 deletions
43
backend/src/main/java/com/greenfoxacademy/backend/services/pet/PetServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.greenfoxacademy.backend.services.pet; | ||
|
||
import com.greenfoxacademy.backend.dtos.PetDetailsDto; | ||
import com.greenfoxacademy.backend.dtos.PetListResponseDto; | ||
import com.greenfoxacademy.backend.models.Pet; | ||
import com.greenfoxacademy.backend.repositories.PetRepository; | ||
import com.greenfoxacademy.backend.services.user.owner.OwnerService; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.modelmapper.ModelMapper; | ||
import org.springframework.security.core.userdetails.UsernameNotFoundException; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Retrieves a list of pets owned by the user with the specified email. | ||
*/ | ||
@Service | ||
@RequiredArgsConstructor | ||
public class PetServiceImpl implements PetService { | ||
private final PetRepository petRepository; | ||
private final OwnerService ownerService; | ||
private final ModelMapper modelMapper = new ModelMapper(); | ||
|
||
/** | ||
* Retrieves a list of pets owned by the user with the specified email. | ||
* | ||
* @param email the email of the pet owner | ||
* @return a {@link PetListResponseDto} containing the list of pets | ||
* @throws UsernameNotFoundException if the user with the specified email is not found | ||
*/ | ||
@Override | ||
public PetListResponseDto getOwnerPets(String email) { | ||
List<Pet> petList = petRepository | ||
.findAllByOwnerId(ownerService.findByEmail(email).getId()); | ||
|
||
List<PetDetailsDto> petDtoList = petList.stream() | ||
.map(pet -> modelMapper.map(pet, PetDetailsDto.class)) | ||
.collect(Collectors.toList()); | ||
|
||
return new PetListResponseDto(petDtoList); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
backend/src/main/java/com/greenfoxacademy/backend/services/user/vet/VetService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
package com.greenfoxacademy.backend.services.user.vet; | ||
|
||
import com.greenfoxacademy.backend.dtos.VetListResponseDto; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* VetService defines the business logic for handling veterinarian-related data and | ||
* operations. | ||
* This interface provides methods for retrieving veterinarian data. | ||
*/ | ||
|
||
@Service | ||
public interface VetService { | ||
|
||
VetListResponseDto getAll(); | ||
VetListResponseDto getAll(String word); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.