-
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.
Merge branch 'main' into fix/make-buttons-visible
- Loading branch information
Showing
17 changed files
with
343 additions
and
132 deletions.
There are no files selected for viewing
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
46 changes: 46 additions & 0 deletions
46
backend/src/main/java/com/greenfoxacademy/backend/models/ClinicAddress.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,46 @@ | ||
package com.greenfoxacademy.backend.models; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import jakarta.persistence.Id; | ||
import lombok.Data; | ||
|
||
/** | ||
* Represents an address for a clinic. | ||
* <p> | ||
* The {@code ClinicAddress} class is used as an embeddable type in JPA entities to store address | ||
* details of a clinic. It includes information such as the street address, city, postal code, | ||
* and clinic name. | ||
* </p> | ||
* <p> | ||
* This class is marked with {@code @Embeddable} to indicate that it can be embedded in other JPA | ||
* entities. | ||
* </p> | ||
* <p> | ||
* The {@code id} field is used as a unique identifier for the address. This field is optional and | ||
* is provided for cases where a unique identifier is necessary. | ||
* </p> | ||
* <p> | ||
* The {@code zip} field represents the postal code for the clinic address and is limited to a | ||
* length of 4 digits. | ||
* </p> | ||
* <p> | ||
* The {@code clinicName} field specifies the name of the clinic associated with the address. | ||
* </p> | ||
* | ||
* @see jakarta.persistence.Embeddable | ||
*/ | ||
|
||
@Embeddable | ||
@Data | ||
public class ClinicAddress { | ||
@Id | ||
private Long id; | ||
private String city; | ||
@Column(length = 4) | ||
private int zip; | ||
private String street; | ||
private String clinicName; | ||
|
||
|
||
} |
27 changes: 27 additions & 0 deletions
27
backend/src/main/java/com/greenfoxacademy/backend/models/ClinicDetails.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,27 @@ | ||
package com.greenfoxacademy.backend.models; | ||
|
||
import jakarta.persistence.Embeddable; | ||
import lombok.Data; | ||
|
||
/** | ||
* Represents the details of a clinic. | ||
* <p> | ||
* The {@code ClinicDetails} class is used as an embeddable type in JPA entities to store detailed | ||
* information about a clinic. This class contains the address of the clinic as well as any | ||
* additional details that may be relevant for clinic management. | ||
* </p> | ||
* <p> | ||
* This class is annotated with {@code @Embeddable} to indicate that it can be embedded within | ||
* other JPA entities. | ||
* </p> | ||
* | ||
* @see ClinicAddress | ||
*/ | ||
|
||
@Data | ||
@Embeddable | ||
public class ClinicDetails { | ||
|
||
private ClinicAddress clinicAddress; | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
backend/src/main/java/com/greenfoxacademy/backend/models/Owner.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,49 @@ | ||
package com.greenfoxacademy.backend.models; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.OneToMany; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.Transient; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
|
||
/** | ||
* Represents an owner in the system who is also a user. | ||
* <p> | ||
* The {@code Owner} class extends the {@code User} class and includes specific information related | ||
* to an owner, such as the list of pets they own. It is marked with {@code @Entity} to indicate | ||
* that it is a JPA entity and is mapped to a database table. | ||
* </p> | ||
* <p> | ||
* The {@code @Table(name = "_owner")} annotation specifies the name of the database table | ||
* associated with this entity. The table name is prefixed with an underscore to avoid conflicts | ||
* with reserved SQL keywords. | ||
* </p> | ||
* <p> | ||
* The {@code getAuthorities} method overrides the method from {@code User} to provide specific | ||
* authorities for an owner, granting the role {@code ROLE_OWNER}. | ||
* </p> | ||
* | ||
* @see User | ||
*/ | ||
|
||
@Entity | ||
@SuperBuilder | ||
@RequiredArgsConstructor | ||
@AllArgsConstructor | ||
@Table(name = "_owner") | ||
public class Owner extends User { | ||
@OneToMany(mappedBy = "petOwner") | ||
private List<Pet> pets; | ||
|
||
@Override | ||
@Transient | ||
public Collection<? extends GrantedAuthority> getAuthorities() { | ||
return List.of(new SimpleGrantedAuthority("ROLE_OWNER")); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
backend/src/main/java/com/greenfoxacademy/backend/models/Pet.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,44 @@ | ||
package com.greenfoxacademy.backend.models; | ||
|
||
import jakarta.persistence.CascadeType; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import java.util.Date; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* Represents a pet entity in the system. This class is a data model | ||
* that maps to the pet table in the database. | ||
*/ | ||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Entity | ||
@Table(name = "_pet") | ||
public class Pet { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Integer id; | ||
|
||
@Column(nullable = false) | ||
private String petName; | ||
private String petBreed; | ||
private String petSex; | ||
private Date petBirthDate; | ||
private Date lastCheckUp; | ||
private Date nextCheckUp; | ||
|
||
@ManyToOne(cascade = CascadeType.ALL) | ||
@JoinColumn(name = "petOwner_Id") | ||
private Owner petOwner; | ||
} |
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
47 changes: 47 additions & 0 deletions
47
backend/src/main/java/com/greenfoxacademy/backend/models/Vet.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,47 @@ | ||
package com.greenfoxacademy.backend.models; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Table; | ||
import jakarta.persistence.Transient; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
|
||
/** | ||
* Represents a veterinarian who is also a user in the system. | ||
* <p> | ||
* The {@code Vet} class extends the {@code User} class and adds specific information related to | ||
* a veterinarian, such as the clinic address. It is annotated with {@code @Entity} to indicate | ||
* that it is a JPA entity and will be mapped to a database table. | ||
* </p> | ||
* <p> | ||
* This class is annotated with {@code @Table(name = "_vet")} to specify the name of the database | ||
* table to which this entity is mapped. The table name is prefixed with an underscore to avoid | ||
* conflicts with reserved SQL keywords. | ||
* </p> | ||
* <p> | ||
* The {@code getAuthorities} method overrides the method from {@code User} to provide specific | ||
* authorities for a veterinarian, in this case, granting the role {@code ROLE_VET}. | ||
* </p> | ||
* | ||
* @see User | ||
*/ | ||
|
||
@SuperBuilder | ||
@RequiredArgsConstructor | ||
@AllArgsConstructor | ||
@Entity | ||
@Table(name = "_vet") | ||
public class Vet extends User { | ||
private ClinicDetails clinicDetails; | ||
|
||
@Override | ||
@Transient | ||
public Collection<? extends GrantedAuthority> getAuthorities() { | ||
return List.of(new SimpleGrantedAuthority("ROLE_VET")); | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
.../backend/repositories/UserRepository.java → ...backend/repositories/OwnerRepository.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,20 +1,20 @@ | ||
package com.greenfoxacademy.backend.repositories; | ||
|
||
import com.greenfoxacademy.backend.models.Owner; | ||
import com.greenfoxacademy.backend.models.User; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
/** | ||
* Repository to manage {@link User} entities. | ||
*/ | ||
public interface UserRepository extends JpaRepository<User, Integer> { | ||
public interface OwnerRepository extends JpaRepository<Owner, Integer> { | ||
boolean existsByEmail(String email); | ||
|
||
Optional<User> findByEmail(String email); | ||
Optional<Owner> findByEmail(String email); | ||
|
||
void deleteByEmail(String email); | ||
|
||
Optional<User> findByVerificationId(UUID id); | ||
Optional<Owner> findByVerificationId(UUID id); | ||
} |
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/greenfoxacademy/backend/repositories/PetRepository.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,10 @@ | ||
package com.greenfoxacademy.backend.repositories; | ||
|
||
import com.greenfoxacademy.backend.models.Pet; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
/** | ||
* Repository to manage Pet entities. | ||
*/ | ||
public interface PetRepository extends JpaRepository<Pet, Integer> { | ||
} |
Oops, something went wrong.