Changeset c3278ac


Ignore:
Timestamp:
03/09/23 16:11:48 (21 months ago)
Author:
GitHub <noreply@…>
Branches:
main
Children:
0078d84, 4ab3aae
Parents:
8b7dd7f (diff), 264d675 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
SazdovaEkaterina <74919977+SazdovaEkaterina@…> (03/09/23 16:11:48)
git-committer:
GitHub <noreply@…> (03/09/23 16:11:48)
Message:

Merge pull request #9 from SazdovaEkaterina/fix-foreign-keys

Fix Database Mapping in Models

Location:
Prototype Application/Paw5/src/main
Files:
26 edited

Legend:

Unmodified
Added
Removed
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/Admin.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
    56
    67import java.time.LocalDate;
     
    89@Data
    910@Entity
     11@RequiredArgsConstructor
    1012@Table(name = "admin_table")
    1113@PrimaryKeyJoinColumn(name = "id_user")
    1214public class Admin extends User {
    1315
    14     public Admin(LocalDate dateCreated, String name, String email, String password, String telephone) {
     16    public Admin(LocalDate dateCreated, String name, String email,
     17                 String password, String telephone) {
    1518        super(dateCreated, name, email, password, telephone);
    1619    }
    17 
    18     public Admin() {
    19     }
    2020}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/Adopter.java

    r8b7dd7f rc3278ac  
    77import jakarta.persistence.*;
    88import lombok.Data;
     9import lombok.RequiredArgsConstructor;
    910
    1011import java.time.LocalDate;
     
    1314@Entity
    1415@Table(name = "adopter")
     16@RequiredArgsConstructor
    1517@PrimaryKeyJoinColumn(name = "id_user")
    1618public class Adopter extends User {
     
    4042    private Boolean verified;
    4143
    42     @Column(name = "verified_by_employee")
    43     private Integer verifiedByEmployeeId;
     44    @ManyToOne
     45    @JoinColumn(name = "verified_by_employee")
     46    Employee employeeVerificator;
    4447
    4548    public Adopter(LocalDate dateCreated, String name, String email, String password, String telephone,
     
    5760    }
    5861
    59     public Adopter(FreeTime freeTime, Funds funds, boolean hasOtherPets, boolean hasKids, Housing housing,
    60                    PhysicalActivity physicalActivity, boolean willFoster, boolean verified, int verifiedByEmployeeId) {
    61         this.freeTime = freeTime;
    62         this.funds = funds;
    63         this.hasOtherPets = hasOtherPets;
    64         this.hasKids = hasKids;
    65         this.housing = housing;
    66         this.physicalActivity = physicalActivity;
    67         this.willFoster = willFoster;
    68         this.verified = verified;
    69         this.verifiedByEmployeeId = verifiedByEmployeeId;
    70     }
    71 
    72     public Adopter() {
    73     }
    7462}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/Adoption.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
    56
    67import java.time.LocalDate;
     
    89@Data
    910@Entity
     11@RequiredArgsConstructor
    1012@Table(name = "adoption")
    1113public class Adoption {
     
    2325
    2426    @Column(name = "approved", nullable = false)
    25     private boolean approved;
     27    private Boolean approved;
    2628
    27     @Column(name = "id_adopter", nullable = false)
    28     private Integer adopterId;
     29    @ManyToOne
     30    @JoinColumn(name = "id_adopter", nullable = false)
     31    private Adopter adopter;
    2932
    30     public Adoption(LocalDate startDate, LocalDate endDateFoster, boolean approved, Integer adopterId) {
     33    public Adoption(LocalDate startDate, LocalDate endDateFoster, Boolean approved,
     34                    Adopter adopter) {
    3135        this.startDate = startDate;
    3236        this.endDateFoster = endDateFoster;
    3337        this.approved = approved;
    34         this.adopterId = adopterId;
    35     }
    36 
    37     public Adoption() {
     38        this.adopter = adopter;
    3839    }
    3940}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/Category.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
     6
     7import java.util.List;
    58
    69@Data
    710@Entity
     11@RequiredArgsConstructor
    812@Table(name = "category")
    913public class Category {
     
    1721    private String name;
    1822
     23    @ManyToMany
     24    @JoinTable(name = "pet_belongs_to_category",
     25            joinColumns = @JoinColumn(name = "id_category"),
     26            inverseJoinColumns = @JoinColumn(name = "id_pet"))
     27    List<Pet> pets;
     28
    1929    public Category(String name) {
    2030        this.name = name;
    2131    }
    2232
    23     public Category() {
    24     }
    2533}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/Donor.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
    56
    67import java.time.LocalDate;
     8import java.util.List;
    79
    810@Data
    911@Entity
     12@RequiredArgsConstructor
    1013@Table(name = "donor")
    1114@PrimaryKeyJoinColumn(name = "id_user")
     
    1316
    1417    @Column(name = "is_from_organisation", nullable = false)
    15     private boolean fromOrganisation;
     18    private Boolean fromOrganisation;
    1619
    1720    @Column(name = "name_organisation_donor", nullable = true, length = 100)
    1821    private String organisationName;
    1922
    20     public Donor(LocalDate dateCreated, String name, String email, String password, String telephone, boolean fromOrganisation, String organisationName) {
     23    @ManyToMany
     24    @JoinTable(name = "donor_donates_to_organisation",
     25            joinColumns = @JoinColumn(name = "id_user"),
     26            inverseJoinColumns = @JoinColumn(name = "id_organisation"))
     27    List<Organisation> donatedToOrganisations;
     28
     29    public Donor(LocalDate dateCreated, String name, String email,
     30                 String password, String telephone, Boolean fromOrganisation,
     31                 String organisationName) {
    2132        super(dateCreated, name, email, password, telephone);
    2233        this.fromOrganisation = fromOrganisation;
     
    2435    }
    2536
    26     public Donor(boolean fromOrganisation, String organisationName) {
    27         this.fromOrganisation = fromOrganisation;
    28         this.organisationName = organisationName;
    29     }
    30 
    31     public Donor() {
    32     }
    33 
    3437}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/Employee.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
    56
    67import java.time.LocalDate;
     
    89@Data
    910@Entity
     11@RequiredArgsConstructor
    1012@Table(name = "employee")
    1113@PrimaryKeyJoinColumn(name = "id_user")
     
    1517    private String position;
    1618
    17     @Column(name = "id_shelter", nullable = false)
    18     private Integer shelterId;
     19    @ManyToOne
     20    @JoinColumn(name = "id_shelter", nullable = false)
     21    private Shelter shelter;
    1922
    2023    @Column(name = "is_verified", nullable = false)
    21     private boolean verified;
     24    private Boolean verified;
    2225
    23     @Column(name = "verified_by_admin")
    24     private Integer verifiedByAdminId;
     26    @ManyToOne
     27    @JoinColumn(name = "verified_by_admin")
     28    private Admin adminVerificator;
    2529
    2630    public Employee(LocalDate dateCreated, String name, String email, String password, String telephone,
    27                     String position, int shelterId, boolean verified) {
     31                    String position, Shelter shelter, Boolean verified) {
    2832        super(dateCreated, name, email, password, telephone);
    2933        this.position = position;
    30         this.shelterId = shelterId;
     34        this.shelter = shelter;
    3135        this.verified = verified;
    3236    }
    3337
    34     public Employee(String position, int shelterId, boolean verified, int verifiedByAdminId) {
    35         this.position = position;
    36         this.shelterId = shelterId;
    37         this.verified = verified;
    38         this.verifiedByAdminId = verifiedByAdminId;
    39     }
    40 
    41     public Employee() {
    42 
    43     }
    44 
    4538}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/Food.java

    r8b7dd7f rc3278ac  
    44import jakarta.persistence.*;
    55import lombok.Data;
     6import lombok.RequiredArgsConstructor;
     7
     8import java.util.List;
    69
    710@Data
    811@Entity
     12@RequiredArgsConstructor
    913@Table(name = "food")
    1014public class Food {
     
    2428    private FoodType type;
    2529
     30    @ManyToMany
     31    @JoinTable(name = "pet_preferably_eats_food",
     32            joinColumns = @JoinColumn(name = "id_food"),
     33            inverseJoinColumns = @JoinColumn(name = "id_pet"))
     34    List<Pet> pets;
     35
    2636    public Food(String manufacturer, String name, FoodType type) {
    2737        this.manufacturer = manufacturer;
     
    2939        this.type = type;
    3040    }
    31 
    32     public Food() {
    33     }
    3441}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/Organisation.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
     6
     7import java.util.List;
    58
    69@Data
    710@Entity
     11@RequiredArgsConstructor
    812@Table(name = "organisation")
    913public class Organisation {
     
    2327    private String billingInformation;
    2428
     29    @ManyToMany
     30    @JoinTable(name = "donor_donates_to_organisation",
     31            joinColumns = @JoinColumn(name = "id_organisation"),
     32            inverseJoinColumns = @JoinColumn(name = "id_user"))
     33    List<Donor> donors;
     34
    2535    public Organisation(String name, String email, String billingInformation) {
    2636        this.name = name;
     
    2838        this.billingInformation = billingInformation;
    2939    }
    30 
    31     public Organisation() {
    32     }
    3340}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/PersonalProfile.java

    r8b7dd7f rc3278ac  
    22
    33import finki.paw5.model.enumerations.*;
    4 import jakarta.persistence.Column;
    5 import jakarta.persistence.Entity;
    6 import jakarta.persistence.Id;
    7 import jakarta.persistence.Table;
     4import jakarta.persistence.*;
    85import lombok.Data;
     6import lombok.RequiredArgsConstructor;
    97
    108@Data
    119@Entity
     10@RequiredArgsConstructor
    1211@Table(name = "personal_profile")
    1312public class PersonalProfile {
     
    1615    @Column(name = "id_pet", nullable = false)
    1716    private Integer id;
     17
     18    @OneToOne
     19    @JoinColumn(name = "id_pet", nullable = false)
     20    private Pet pet;
    1821
    1922    @Column(name = "friendly_to_kids", nullable = false)
     
    3235    private GroomingNeed groomingNeed;
    3336
    34     public PersonalProfile(Integer id, FriendlyToKids friendlyToKids, FriendlyToPets friendlyToPets, AttentionNeed attentionNeed, PhysicalActivity physicalActivity, GroomingNeed groomingNeed) {
     37    public PersonalProfile(Integer id, Pet pet, FriendlyToKids friendlyToKids, FriendlyToPets friendlyToPets, AttentionNeed attentionNeed, PhysicalActivity physicalActivity, GroomingNeed groomingNeed) {
    3538        this.id = id;
     39        this.pet = pet;
    3640        this.friendlyToKids = friendlyToKids;
    3741        this.friendlyToPets = friendlyToPets;
     
    4044        this.groomingNeed = groomingNeed;
    4145    }
    42 
    43     public PersonalProfile() {
    44     }
    4546}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/Pet.java

    r8b7dd7f rc3278ac  
    77import jakarta.persistence.*;
    88import lombok.Data;
     9import lombok.RequiredArgsConstructor;
     10
     11import java.util.List;
    912
    1013@Data
    1114@Entity
     15@RequiredArgsConstructor
    1216@Table(name = "pet")
    1317public class Pet {
     
    1721    @Column(name = "id_pet")
    1822    private Integer id;
     23
     24    @OneToOne
     25    @JoinColumn(name = "id_pet", nullable = false)
     26    private PersonalProfile personalProfile;
    1927
    2028    @Column(name = "url_pet_image", length = 200)
     
    4048
    4149    @Column(name = "can_be_fostered", nullable = false)
    42     private boolean canBeFostered;
     50    private Boolean canBeFostered;
    4351
    44     @Column(name = "id_adoption")
    45     private Integer adoptionId;
     52    @ManyToOne
     53    @JoinColumn(name = "id_adoption")
     54    private Adoption adoption;
    4655
    47     @Column(name = "id_shelter")
    48     private Integer shelterId;
     56    @ManyToOne
     57    @JoinColumn(name = "id_shelter")
     58    private Shelter shelter;
    4959
    50     public Pet(String imageUrl, AgeGroup ageGroup, Size size, String breed, String name, Species species, Gender gender, boolean canBeFostered, Integer adoptionId, Integer shelterId) {
     60    @ManyToMany
     61    @JoinTable(name = "pet_belongs_to_category",
     62            joinColumns = @JoinColumn(name = "id_pet"),
     63            inverseJoinColumns = @JoinColumn(name = "id_category"))
     64    List<Category> categories;
     65
     66    @ManyToMany
     67    @JoinTable(name = "pet_needs_intervention_in_vet_clinic",
     68            joinColumns = @JoinColumn(name = "id_pet"),
     69            inverseJoinColumns = @JoinColumn(name = "id_vet_clinic"))
     70    List<VetClinic> vetClinicsTreatedIn;
     71
     72    @ManyToMany
     73    @JoinTable(name = "pet_needs_therapy",
     74            joinColumns = @JoinColumn(name = "id_pet"),
     75            inverseJoinColumns = @JoinColumn(name = "id_therapy"))
     76    List<Therapy> therapies;
     77
     78    @ManyToMany
     79    @JoinTable(name = "pet_preferably_eats_food",
     80            joinColumns = @JoinColumn(name = "id_pet"),
     81            inverseJoinColumns = @JoinColumn(name = "id_food"))
     82    List<Food> preferredFoods;
     83
     84    public Pet(String imageUrl, AgeGroup ageGroup, Size size, String breed,
     85               String name, Species species, Gender gender, Boolean canBeFostered,
     86               Adoption adoption, Shelter shelter) {
    5187        this.imageUrl = imageUrl;
    5288        this.ageGroup = ageGroup;
     
    5793        this.gender = gender;
    5894        this.canBeFostered = canBeFostered;
    59         this.adoptionId = adoptionId;
    60         this.shelterId = shelterId;
    61     }
    62 
    63     public Pet() {
     95        this.adoption = adoption;
     96        this.shelter = shelter;
    6497    }
    6598}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/Post.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
    56
    67import java.time.LocalDate;
     
    89@Data
    910@Entity
     11@RequiredArgsConstructor
    1012@Table(name = "post")
    1113public class Post {
     
    2224    private String thumbnailUrl;
    2325
    24     @Column(name="id_pet", nullable = false)
    25     private Integer petId;
     26    @OneToOne
     27    @JoinColumn(name="id_pet", nullable = false)
     28    private Pet pet;
    2629
    27     @Column(name="id_surendee")
    28     private Integer surendeeId;
     30    @ManyToOne
     31    @JoinColumn(name="id_surendee")
     32    private Surendee surendeePoster;
    2933
    30     @Column(name="id_employee")
    31     private Integer employeeId;
     34    @ManyToOne
     35    @JoinColumn(name="id_employee")
     36    private Employee employeePoster;
    3237
    33     public Post(LocalDate dateCreated, String thumbnailUrl, Integer petId, Integer surendeeId, Integer employeeId) {
     38    public Post(LocalDate dateCreated, String thumbnailUrl,
     39                Pet pet, Surendee surendeePoster, Employee employeePoster) {
    3440        this.dateCreated = dateCreated;
    3541        this.thumbnailUrl = thumbnailUrl;
    36         this.petId = petId;
    37         this.surendeeId = surendeeId;
    38         this.employeeId = employeeId;
    39     }
    40 
    41     public Post() {
     42        this.pet = pet;
     43        this.surendeePoster = surendeePoster;
     44        this.employeePoster = employeePoster;
    4245    }
    4346}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/Shelter.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
    56
    67@Data
    78@Entity
     9@RequiredArgsConstructor
    810@Table(name = "shelter")
    911public class Shelter {
     
    2022    private String telephone;
    2123
    22     @Column(name = "id_organisation")
    23     private Integer organisationId;
     24    @ManyToOne
     25    @JoinColumn(name = "id_organisation")
     26    private Organisation organisation;
    2427
    2528    @Column(name = "name_shelter", nullable = false, length = 100)
     
    2932    private String email;
    3033
    31     public Shelter(String address, String telephone, Integer organisationId, String name, String email) {
     34    public Shelter(String address, String telephone, Organisation organisation,
     35                   String name, String email) {
    3236        this.address = address;
    3337        this.telephone = telephone;
    34         this.organisationId = organisationId;
     38        this.organisation = organisation;
    3539        this.name = name;
    3640        this.email = email;
    3741    }
    38 
    39     public Shelter() {
    40     }
    4142}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/Surendee.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
    56
    67import java.time.LocalDate;
     
    89@Data
    910@Entity
     11@RequiredArgsConstructor
    1012@Table(name = "surendee")
    1113@PrimaryKeyJoinColumn(name = "id_user")
     
    1618    }
    1719
    18     public Surendee() {
    19     }
    20 
    2120}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/Therapy.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
    56
    67import java.time.LocalDate;
    78import java.util.Date;
     9import java.util.List;
    810
    911@Data
    1012@Entity
     13@RequiredArgsConstructor
    1114@Table(name = "therapy")
    1215public class Therapy {
     
    2629    private LocalDate endDate;
    2730
     31    @ManyToMany
     32    @JoinTable(name = "pet_needs_therapy",
     33            joinColumns = @JoinColumn(name = "id_therapy"),
     34            inverseJoinColumns = @JoinColumn(name = "id_pet"))
     35    List<Pet> pets;
     36
    2837    public Therapy(String healthProblem, LocalDate startDate, LocalDate endDate) {
    2938        this.healthProblem = healthProblem;
     
    3140        this.endDate = endDate;
    3241    }
    33 
    34     public Therapy() {
    35     }
    3642}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/User.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
    56
    67import java.time.LocalDate;
     
    910@Data
    1011@Entity
     12@RequiredArgsConstructor
    1113@Table(name = "user_table")
    1214@Inheritance(strategy = InheritanceType.JOINED)
     
    4042        this.telephone = telephone;
    4143    }
    42 
    43     public User() {
    44     }
    4544}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/entities/VetClinic.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
     6
     7import java.util.List;
    58
    69@Data
    710@Entity
     11@RequiredArgsConstructor
    812@Table(name = "vet_clinic")
    913public class VetClinic {
     
    2327    private String name;
    2428
     29    @ManyToMany
     30    @JoinTable(name = "pet_needs_intervention_in_vet_clinic",
     31            joinColumns = @JoinColumn(name = "id_vet_clinic"),
     32            inverseJoinColumns = @JoinColumn(name = "id_pet"))
     33    List<Pet> pets;
     34
    2535    public VetClinic(String telephone, String address, String name) {
    2636        this.telephone = telephone;
     
    2838        this.name = name;
    2939    }
    30 
    31     public VetClinic() {
    32     }
    3340}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/relations/DonorDonatesToOrganisation.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
    56
    67@Data
    78@Entity
     9@RequiredArgsConstructor
    810@Table(name = "donor_donates_to_organisation")
    911@IdClass(DonorDonatesToOrganisationId.class)
     
    2224        this.organisationId = organisationId;
    2325    }
    24 
    25     public DonorDonatesToOrganisation() {
    26        
    27     }
    2826}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/relations/PetBelongsToCategory.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
    56
    67@Data
    78@Entity
     9@RequiredArgsConstructor
    810@Table(name = "pet_belongs_to_category")
    911@IdClass(PetBelongsToCategoryId.class)
     
    2224        this.categoryId = categoryId;
    2325    }
    24 
    25     public PetBelongsToCategory() {
    26 
    27     }
    2826}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/relations/PetNeedsInterventionInVetClinic.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
    56
    67import java.time.LocalDate;
     
    910@Data
    1011@Entity
     12@RequiredArgsConstructor
    1113@Table(name = "pet_needs_intervention_in_vet_clinic")
    1214@IdClass(PetNeedsInterventionInVetClinicId.class)
     
    3335        this.description = description;
    3436    }
    35 
    36     public PetNeedsInterventionInVetClinic() {
    37 
    38     }
    3937}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/relations/PetNeedsTherapy.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
    56
    67@Data
    78@Entity
     9@RequiredArgsConstructor
    810@Table(name = "pet_needs_therapy")
    911@IdClass(PetNeedsTherapyId.class)
     
    2224        this.therapyId = therapyId;
    2325    }
    24 
    25     public PetNeedsTherapy() {
    26     }
    2726}
  • Prototype Application/Paw5/src/main/java/finki/paw5/model/relations/PetPreferablyEatsFood.java

    r8b7dd7f rc3278ac  
    33import jakarta.persistence.*;
    44import lombok.Data;
     5import lombok.RequiredArgsConstructor;
    56
    67@Data
    78@Entity
     9@RequiredArgsConstructor
    810@Table(name = "pet_preferably_eats_food")
    911@IdClass(PetPreferablyEatsFoodId.class)
     
    2628        this.quantityPerDay = quantityPerDay;
    2729    }
    28 
    29     public PetPreferablyEatsFood() {
    30     }
    3130}
  • Prototype Application/Paw5/src/main/java/finki/paw5/service/implementation/AuthServiceImplementation.java

    r8b7dd7f rc3278ac  
    33import finki.paw5.model.entities.Adopter;
    44import finki.paw5.model.entities.Employee;
     5import finki.paw5.model.entities.Shelter;
    56import finki.paw5.model.entities.User;
    67import finki.paw5.model.enumerations.FreeTime;
     
    1011import finki.paw5.repository.AdopterRepository;
    1112import finki.paw5.repository.EmployeeRepository;
     13import finki.paw5.repository.ShelterRepository;
    1214import finki.paw5.repository.UserRepository;
    1315import finki.paw5.service.AuthService;
     
    2224    private final AdopterRepository adopterRepository;
    2325    private final EmployeeRepository employeeRepository;
     26    private final ShelterRepository shelterRepository;
    2427
    25     public AuthServiceImplementation(UserRepository userRepository, AdopterRepository adopterRepository, EmployeeRepository employeeRepository) {
     28    public AuthServiceImplementation(UserRepository userRepository, AdopterRepository adopterRepository, EmployeeRepository employeeRepository, ShelterRepository shelterRepository) {
    2629        this.userRepository = userRepository;
    2730        this.adopterRepository = adopterRepository;
    2831        this.employeeRepository = employeeRepository;
     32        this.shelterRepository = shelterRepository;
    2933    }
    3034
     
    4751    @Override
    4852    public Employee registerEmployee(String name, String email, String password, String telephone, String position, Integer shelterId) {
    49         Employee employee = new Employee(LocalDate.now(),name, email,password,telephone,position,shelterId,false);
     53        Shelter shelter = this.shelterRepository.findById(shelterId).get();
     54        Employee employee = new Employee(LocalDate.now(),name, email,password,telephone,position,shelter,false);
    5055        return employeeRepository.save(employee);
    5156    }
  • Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PetController.java

    r8b7dd7f rc3278ac  
    11package finki.paw5.web.controllers;
    22
     3import finki.paw5.model.entities.Adopter;
    34import finki.paw5.model.entities.Adoption;
    45import finki.paw5.model.entities.Pet;
    5 import finki.paw5.model.entities.User;
    6 import finki.paw5.model.exceptions.InvalidPetIdException;
    76import finki.paw5.service.AdoptionService;
    87import finki.paw5.service.PetService;
     
    2524    }
    2625
    27     @PostMapping("/submit-adopton-{id}")
     26    @PostMapping("/submit-adoption-{id}")
    2827    public String saveAdoption(@PathVariable Integer id, HttpServletRequest request) {
    2928
    3029        Pet pet = this.petService.findById(id);
    3130       
    32         User user = (User) request.getSession().getAttribute("user");
     31        Adopter adopter = (Adopter) request.getSession().getAttribute("user");
    3332
    34         Adoption adoption = new Adoption(LocalDate.now(), null, false, user.getId());
     33        Adoption adoption = new Adoption(LocalDate.now(), null, false, adopter);
    3534        this.adoptionService.save(adoption);
    3635
    37         pet.setAdoptionId(adoption.getId());
     36        pet.setAdoption(adoption);
    3837        this.petService.save(pet);
    3938
  • Prototype Application/Paw5/src/main/java/finki/paw5/web/controllers/PostController.java

    r8b7dd7f rc3278ac  
    5858        if(newPetCheckbox == true){
    5959
    60             Pet newPet = new Pet(imageUrl, AgeGroup.valueOf(ageGroup), Size.valueOf(size), breed, name, Species.valueOf(species), Gender.valueOf(gender), canBeFostered, null, employee.getShelterId());
     60            Pet newPet = new Pet(imageUrl, AgeGroup.valueOf(ageGroup), Size.valueOf(size), breed, name, Species.valueOf(species), Gender.valueOf(gender), canBeFostered, null, employee.getShelter());
    6161            this.petService.save(newPet);
    6262
    63             Post post = new Post(LocalDate.now(), imageUrl, newPet.getId(), null, employee.getId());
     63            Post post = new Post(LocalDate.now(), imageUrl, newPet, null, employee);
    6464            this.postService.save(post);
    6565
     
    6868            Pet selectedPet = this.petService.findById(petId);
    6969
    70             Post post = new Post(LocalDate.now(), imageUrl, selectedPet.getId(), null, employee.getId());
     70            Post post = new Post(LocalDate.now(), imageUrl, selectedPet, null, employee);
    7171            this.postService.save(post);
    7272
     
    9292
    9393        Post post = this.postService.findById(id).get();
    94         Pet pet = this.petService.findById(post.getPetId());
     94        Pet pet = post.getPet();
    9595
    9696        model.addAttribute("pet", pet);
  • Prototype Application/Paw5/src/main/resources/templates/list-posts-adoption.html

    r8b7dd7f rc3278ac  
    4747    <tr th:each = "post : ${posts}">
    4848        <td th:text = "${post.getId()}"></td>
    49         <td th:each = "pet : ${pets}" th:if="${post.getPetId()==pet.getId()}" th:text = "${pet.getName()}"></td>
    50         <td th:each = "pet : ${pets}" th:if="${post.getPetId()==pet.getId()}" th:text = "${pet.getSpecies()}"></td>
     49        <td th:text = "${post.getPet().getName()}"></td>
     50        <td th:text = "${post.getPet().getSpecies()}"></td>
    5151        <td>
    5252            <form th:action="@{'/pet-details-{id}' (id=${post.getId()})}"
  • Prototype Application/Paw5/src/main/resources/templates/pet-details.html

    r8b7dd7f rc3278ac  
    6868</table>
    6969<form method="POST"
    70       th:action="@{'/submit-adopton-{id}' (id=${pet.getId()})}"
    71       th:if="${pet.getAdoptionId()==null}">
     70      th:action="@{'/submit-adoption-{id}' (id=${pet.getId()})}"
     71      th:if="${pet.getAdoption()==null}">
    7272    <button id="submit"
    7373            type="submit"
Note: See TracChangeset for help on using the changeset viewer.