Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/main/java/com/podzilla/auth/seeder/DatabaseSeeder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,41 @@

import com.podzilla.auth.model.ERole;
import com.podzilla.auth.model.Role;
import com.podzilla.auth.repository.AddressRepository;
import com.podzilla.auth.repository.RefreshTokenRepository;
import com.podzilla.auth.repository.RoleRepository;
import com.podzilla.auth.repository.UserRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class DatabaseSeeder implements CommandLineRunner {

private final RoleRepository roleRepository;
private final RefreshTokenRepository refreshTokenRepository;
private final UserRepository userRepository;
private final AddressRepository addressRepository;

public DatabaseSeeder(final RoleRepository roleRepository) {
public DatabaseSeeder(final RoleRepository roleRepository,
final RefreshTokenRepository refreshTokenRepository,
final UserRepository userRepository,
final AddressRepository addressRepository) {
this.roleRepository = roleRepository;
this.refreshTokenRepository = refreshTokenRepository;
this.userRepository = userRepository;
this.addressRepository = addressRepository;
}

@Override
public void run(final String... args) throws Exception {
userRepository.findAll().forEach(user -> {
user.getRoles().clear();
userRepository.save(user);
});
userRepository.deleteAll();
roleRepository.deleteAll();
refreshTokenRepository.deleteAll();
addressRepository.deleteAll();
roleRepository.save(new Role(ERole.ROLE_USER));
roleRepository.save(new Role(ERole.ROLE_ADMIN));
roleRepository.save(new Role(ERole.ROLE_COURIER));
Expand Down