Skip to content

Commit

Permalink
Default volunteer
Browse files Browse the repository at this point in the history
  • Loading branch information
Irfankcss committed May 9, 2024
1 parent 038d1c5 commit e24b436
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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
Expand All @@ -29,6 +35,17 @@ public void initializeDatabase() {
user.encodePassword();
userRepository.save(user);
}

// Default ShelterVolunteer
if (!shelterVolunteerRepository.existsById("volunteer")) {
ShelterVolunteer volunteer = new ShelterVolunteer();
volunteer.setEmail("[email protected]");
volunteer.setId("volunteer");
volunteer.setPassword("test1234");
volunteer.encodePassword();
shelterVolunteerRepository.save(volunteer);
}

if (Arrays.asList(activeProfiles.split(",")).contains("test")) {
// Testing instances
if (!userRepository.existsById("test")) {
Expand Down

0 comments on commit e24b436

Please sign in to comment.