added the possibility to remove the mocks
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 2m6s
Build and test backend / Test-backend (pull_request) Successful in 1m58s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 21s

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.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.CrossOrigin; 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.PostMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import ovh.herisson.Clyde.Repositories.TokenRepository; import ovh.herisson.Clyde.Repositories.TokenRepository;
@ -23,6 +24,8 @@ public class MockController {
public final UserRepository userRepo; public final UserRepository userRepo;
public final TokenRepository tokenRepo; public final TokenRepository tokenRepo;
ArrayList<User> mockUsers;
public MockController(UserRepository userRepo, TokenRepository tokenRepo){ public MockController(UserRepository userRepo, TokenRepository tokenRepo){
this.tokenRepo = tokenRepo; this.tokenRepo = tokenRepo;
@ -35,7 +38,7 @@ public class MockController {
* They all have silly names * They all have silly names
*/ */
@PostMapping("/generateMock") @PostMapping("/mock")
public void postMock(){ public void postMock(){
User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand",new Date(0), Role.Admin,passwordEncoder.encode("admin")); 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 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")); 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: mockUsers){
for (User user: users){
tokenRepo.save(new Token(user,user.getPassword())); 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> { public interface TokenRepository extends CrudRepository<Token,Long> {
Token getByToken(String token); Token getByToken(String token);
Iterable<Token> getByUser(User user);
} }