From e24b43626fd628ef57dafb6086fb88137bf5ea90 Mon Sep 17 00:00:00 2001 From: Irfankcss <114685092+Irfankcss@users.noreply.github.com> Date: Thu, 9 May 2024 16:23:33 +0200 Subject: [PATCH] Default volunteer --- .../demo/config/DBInitialization.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/cat/udl/eps/softarch/demo/config/DBInitialization.java b/src/main/java/cat/udl/eps/softarch/demo/config/DBInitialization.java index f2fd97f6..3d36db86 100644 --- a/src/main/java/cat/udl/eps/softarch/demo/config/DBInitialization.java +++ b/src/main/java/cat/udl/eps/softarch/demo/config/DBInitialization.java @@ -1,8 +1,12 @@ package cat.udl.eps.softarch.demo.config; + +import cat.udl.eps.softarch.demo.domain.ShelterVolunteer; import cat.udl.eps.softarch.demo.domain.User; import cat.udl.eps.softarch.demo.repository.UserRepository; +import cat.udl.eps.softarch.demo.repository.ShelterVolunteerRepository; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; + import jakarta.annotation.PostConstruct; import java.util.Arrays; @@ -13,9 +17,11 @@ public class DBInitialization { @Value("${spring.profiles.active:}") private String activeProfiles; private final UserRepository userRepository; + private final ShelterVolunteerRepository shelterVolunteerRepository; - public DBInitialization(UserRepository userRepository) { + public DBInitialization(UserRepository userRepository, ShelterVolunteerRepository shelterVolunteerRepository) { this.userRepository = userRepository; + this.shelterVolunteerRepository = shelterVolunteerRepository; } @PostConstruct @@ -29,6 +35,17 @@ public void initializeDatabase() { user.encodePassword(); userRepository.save(user); } + + // Default ShelterVolunteer + if (!shelterVolunteerRepository.existsById("volunteer")) { + ShelterVolunteer volunteer = new ShelterVolunteer(); + volunteer.setEmail("volunteer@sample.app"); + volunteer.setId("volunteer"); + volunteer.setPassword("test1234"); + volunteer.encodePassword(); + shelterVolunteerRepository.save(volunteer); + } + if (Arrays.asList(activeProfiles.split(",")).contains("test")) { // Testing instances if (!userRepository.existsById("test")) {