-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial Data Seeding and Some QoL Improvements
- Loading branch information
Showing
11 changed files
with
337 additions
and
20 deletions.
There are no files selected for viewing
160 changes: 160 additions & 0 deletions
160
src/main/java/com/production/ehayvanbackendapi/Configurations/InitialDataSeeding.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,160 @@ | ||
package com.production.ehayvanbackendapi.Configurations; | ||
|
||
import com.production.ehayvanbackendapi.Entities.*; | ||
import com.production.ehayvanbackendapi.Repositories.*; | ||
import net.sf.jsqlparser.expression.DateTimeLiteralExpression; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.security.core.parameters.P; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Configuration | ||
public class InitialDataSeeding implements ApplicationListener<ContextRefreshedEvent> { | ||
private final PetOwnerRepository petOwnerRepository; | ||
private final MedTypeRepository medTypeRepository; | ||
private final PetTypeRepository petTypeRepository; | ||
private final UserTypeRepository userTypeRepository; | ||
private final AppointmentRepository appointmentRepository; | ||
private final MedicationRepository medicationRepository; | ||
private final PetRepository petRepository; | ||
private final ScheduleRepository scheduleRepository; | ||
private final VeterinarianRepository veterinarianRepository; | ||
public InitialDataSeeding(PetOwnerRepository petOwnerRepo, | ||
MedTypeRepository medTypeRepo, | ||
PetTypeRepository petTypeRepo, | ||
UserTypeRepository userTypeRepo, | ||
CustomerRepository customerRepo, | ||
AppointmentRepository appointmentRepo, | ||
MedicationRepository medicationRepo, | ||
PetRepository petRepo, | ||
ScheduleRepository scheduleRepo, | ||
VeterinarianRepository veterinarianRepo){ | ||
petOwnerRepository = petOwnerRepo; | ||
medTypeRepository = medTypeRepo; | ||
petTypeRepository = petTypeRepo; | ||
userTypeRepository = userTypeRepo; | ||
appointmentRepository = appointmentRepo; | ||
medicationRepository = medicationRepo; | ||
petRepository = petRepo; | ||
scheduleRepository = scheduleRepo; | ||
veterinarianRepository = veterinarianRepo; | ||
} | ||
@Override | ||
public void onApplicationEvent(ContextRefreshedEvent event) { | ||
// List<UserType> userTypes = userTypeRepository.findAll(); | ||
// List<PetOwner> petOwners = petOwnerRepository.findAll(); | ||
// if(!userTypes.isEmpty()){ | ||
// if(petOwners.isEmpty()){ | ||
// //Create Customer for PetOwner | ||
// Customer exampleCustomer = new Customer(); | ||
// exampleCustomer.setName("exampleName"); | ||
// exampleCustomer.setSurname("exampleSurname"); | ||
// exampleCustomer.setEmail("[email protected]"); | ||
// exampleCustomer.setPassword("example"); | ||
// exampleCustomer.setUserTypeID(userTypeRepository.findById(1).get()); | ||
// | ||
// //Create Customer for Veterinarian | ||
// Customer exampleCustomerVet = new Customer(); | ||
// exampleCustomerVet.setName("exampleVetName"); | ||
// exampleCustomerVet.setSurname("exampleVetSurname"); | ||
// exampleCustomerVet.setEmail("[email protected]"); | ||
// exampleCustomerVet.setPassword("example"); | ||
// exampleCustomerVet.setUserTypeID(userTypeRepository.findById(2).get()); | ||
// | ||
// //Create PetOwner | ||
// PetOwner exampleOwner = new PetOwner(); | ||
// | ||
// //Connect Customer Profile of PetOwner | ||
// exampleOwner.setUser(exampleCustomer); | ||
// | ||
// //Create Veterinarian | ||
// Veterinarian exampleVeterinarian = new Veterinarian(); | ||
// exampleVeterinarian.setClinic("Example Clinic"); | ||
// | ||
// //Connect Veterinarian and PetOwner | ||
// List<PetOwner> exampleOwners = new ArrayList<>(); | ||
// exampleOwners.add(exampleOwner); | ||
// exampleVeterinarian.setPetOwners(exampleOwners); | ||
// | ||
// //Connect Customer Profile of Veterinarian | ||
// exampleVeterinarian.setUser(exampleCustomerVet); | ||
// exampleCustomerVet.setVet(exampleVeterinarian); | ||
// | ||
// //Connect Veterinarian and PetOwner | ||
// exampleOwner.setVet(exampleVeterinarian); | ||
// | ||
// //Create an example Pet | ||
// Pet examplePet = new Pet(); | ||
// examplePet.setPetName("examplePet"); | ||
// examplePet.setAge(2); | ||
// examplePet.setDescription("example description"); | ||
// examplePet.setPetTypeID(petTypeRepository.findById(2).get()); | ||
// | ||
// //Connect Pet with PetOwner | ||
// examplePet.setPetOwnerID(exampleOwner); | ||
// | ||
// //Connect PetOwner with Pet | ||
// List<Pet> examplePets = new ArrayList<>(); | ||
// examplePets.add(examplePet); | ||
// exampleOwner.setPets(examplePets); | ||
// | ||
// //Create an Appointment | ||
// Appointment exampleAppointment = new Appointment(); | ||
// Date date = new Date(); | ||
// exampleAppointment.setAppointmentDate(date); | ||
// exampleAppointment.setVetID(exampleVeterinarian); | ||
// exampleAppointment.setPetID(examplePet); | ||
// exampleAppointment.setPetOwnerID(exampleOwner); | ||
// | ||
// //Connect Veterinarian, Owner and Pet with Appointment | ||
// List<Appointment> appointmentsVeterinarian = new ArrayList<>(); | ||
// appointmentsVeterinarian.add(exampleAppointment); | ||
// exampleVeterinarian.setAppointments(appointmentsVeterinarian); | ||
// | ||
// List<Appointment> appointmentsOwner = new ArrayList<>(); | ||
// appointmentsOwner.add(exampleAppointment); | ||
// exampleOwner.setAppointments(appointmentsOwner); | ||
// | ||
// List<Appointment> appointmentsPet = new ArrayList<>(); | ||
// appointmentsPet.add(exampleAppointment); | ||
// examplePet.setAppointments(appointmentsPet); | ||
// | ||
// //Create Schedule | ||
// Schedule exampleSchedule = new Schedule(); | ||
// exampleSchedule.setBeginningDate(new Date()); | ||
// exampleSchedule.setDoseCount(1); | ||
// exampleSchedule.setDoseFrequency(1); | ||
// | ||
// //Create Medication | ||
// Medication exampleMedication = new Medication(); | ||
// exampleMedication.setMedicationName("exampleMedication"); | ||
// exampleMedication.setMedTypeID(medTypeRepository.findById(1).get()); | ||
// | ||
// //Connect Medication with Schedule | ||
// exampleMedication.setScheduleID(exampleSchedule); | ||
// List<Medication> medicationsSchedule = new ArrayList<>(); | ||
// medicationsSchedule.add(exampleMedication); | ||
// exampleSchedule.setMedications(medicationsSchedule); | ||
// | ||
// //Connect Pet with Medication | ||
// List<Medication> medicationsPet = new ArrayList<>(); | ||
// medicationsPet.add(exampleMedication); | ||
// examplePet.setMedications(medicationsPet); | ||
// | ||
// //Connect Medication with Pet | ||
// exampleMedication.setPetID(examplePet); | ||
// | ||
// veterinarianRepository.save(exampleVeterinarian); | ||
// petOwnerRepository.save(exampleOwner); | ||
// petRepository.save(examplePet); | ||
// appointmentRepository.save(exampleAppointment); | ||
// scheduleRepository.save(exampleSchedule); | ||
// medicationRepository.save(exampleMedication); | ||
// } | ||
// } | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/production/ehayvanbackendapi/Configurations/MedTypeSeeding.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,34 @@ | ||
package com.production.ehayvanbackendapi.Configurations; | ||
|
||
import com.production.ehayvanbackendapi.Entities.MedType; | ||
import com.production.ehayvanbackendapi.Repositories.MedTypeRepository; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import java.util.List; | ||
|
||
@Configuration | ||
public class MedTypeSeeding implements ApplicationListener<ContextRefreshedEvent> { | ||
private final MedTypeRepository medTypeRepository; | ||
public MedTypeSeeding(MedTypeRepository repository){ | ||
medTypeRepository = repository; | ||
} | ||
|
||
@Override | ||
public void onApplicationEvent(ContextRefreshedEvent event) { | ||
List<MedType> medTypes = medTypeRepository.findAll(); | ||
if(medTypes.isEmpty()){ | ||
MedType vaccine = new MedType(); | ||
MedType drop = new MedType(); | ||
MedType medication = new MedType(); | ||
|
||
vaccine.setMedType("Vaccine"); | ||
drop.setMedType("Drop"); | ||
medication.setMedType("Medication"); | ||
|
||
medTypeRepository.save(vaccine); | ||
medTypeRepository.save(drop); | ||
medTypeRepository.save(medication); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/production/ehayvanbackendapi/Configurations/PetTypeSeeding.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,38 @@ | ||
package com.production.ehayvanbackendapi.Configurations; | ||
|
||
import com.production.ehayvanbackendapi.Entities.Pet; | ||
import com.production.ehayvanbackendapi.Entities.PetType; | ||
import com.production.ehayvanbackendapi.Repositories.PetTypeRepository; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
|
||
import java.util.List; | ||
|
||
@Configuration | ||
public class PetTypeSeeding implements ApplicationListener<ContextRefreshedEvent> { | ||
private final PetTypeRepository petTypeRepository; | ||
public PetTypeSeeding(PetTypeRepository repository){ | ||
petTypeRepository = repository; | ||
} | ||
@Override | ||
public void onApplicationEvent(ContextRefreshedEvent event) { | ||
List<PetType> petTypes = petTypeRepository.findAll(); | ||
if(petTypes.isEmpty()){ | ||
PetType cat = new PetType(); | ||
PetType dog = new PetType(); | ||
PetType bird = new PetType(); | ||
PetType other = new PetType(); | ||
|
||
cat.setType("Cat"); | ||
dog.setType("Dog"); | ||
bird.setType("Bird"); | ||
other.setType("Other"); | ||
|
||
petTypeRepository.save(cat); | ||
petTypeRepository.save(dog); | ||
petTypeRepository.save(bird); | ||
petTypeRepository.save(other); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/production/ehayvanbackendapi/Configurations/UserTypeSeeding.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,36 @@ | ||
package com.production.ehayvanbackendapi.Configurations; | ||
|
||
import com.production.ehayvanbackendapi.Entities.UserType; | ||
import com.production.ehayvanbackendapi.Repositories.UserTypeRepository; | ||
import org.springframework.context.ApplicationListener; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Configuration | ||
public class UserTypeSeeding implements ApplicationListener<ContextRefreshedEvent> { | ||
private final UserTypeRepository userTypeRepository; | ||
public UserTypeSeeding(UserTypeRepository repository){ | ||
userTypeRepository = repository; | ||
} | ||
|
||
@Override | ||
public void onApplicationEvent(ContextRefreshedEvent event) { | ||
List<UserType> userTypes = userTypeRepository.findAll(); | ||
if(userTypes.isEmpty()){ | ||
UserType petOwner = new UserType(); | ||
UserType veterinarian = new UserType(); | ||
UserType administrator = new UserType(); | ||
|
||
petOwner.setType("Pet Owner"); | ||
veterinarian.setType("Veterinarian"); | ||
administrator.setType("Administrator"); | ||
|
||
userTypeRepository.save(petOwner); | ||
userTypeRepository.save(veterinarian); | ||
userTypeRepository.save(administrator); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.