1
0
forked from PGL/Clyde

added the possibility to remove the mocks

This commit is contained in:
Bartha Maxime 2024-03-07 17:29:31 +01:00
parent 6b58c852a2
commit 2f2a72bfa0
2 changed files with 17 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package ovh.herisson.Clyde.EndPoints;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import ovh.herisson.Clyde.Repositories.TokenRepository;
@ -23,6 +24,8 @@ public class MockController {
public final UserRepository userRepo;
public final TokenRepository tokenRepo;
ArrayList<User> mockUsers;
public MockController(UserRepository userRepo, TokenRepository tokenRepo){
this.tokenRepo = tokenRepo;
@ -35,7 +38,7 @@ public class MockController {
* They all have silly names
*/
@PostMapping("/generateMock")
@PostMapping("/mock")
public void postMock(){
User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand",new Date(0), Role.Admin,passwordEncoder.encode("admin"));
@ -43,13 +46,20 @@ public class MockController {
User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), Role.Teacher,passwordEncoder.encode("secretary"));
User joke = new User("CthemBalls","Lemme","teacher@teacher.com","lab","faculty",new Date(0), Role.Teacher,passwordEncoder.encode("teacher"));
mockUsers = new ArrayList<User>(Arrays.asList(herobrine,joe,meh,joke));
ArrayList<User> users = new ArrayList<User>(Arrays.asList(herobrine,joe,meh,joke));
userRepo.saveAll(mockUsers);
userRepo.saveAll(users);
for (User user: users){
for (User user: mockUsers){
tokenRepo.save(new Token(user,user.getPassword()));
}
}
@DeleteMapping("/mock")
public void deleteMock(){
for (User user:mockUsers){
tokenRepo.deleteAll(tokenRepo.getByUser(user));
}
userRepo.deleteAll(mockUsers);
}
}

View File

@ -7,4 +7,6 @@ import ovh.herisson.Clyde.Tables.User;
public interface TokenRepository extends CrudRepository<Token,Long> {
Token getByToken(String token);
Iterable<Token> getByUser(User user);
}