Skip to content

Commit

Permalink
Merging the pull
Browse files Browse the repository at this point in the history
  • Loading branch information
aplantier committed Feb 11, 2022
2 parents 889044a + 7fa8d8b commit d2c4806
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
**/*~
.idea
*.properties
**/*.class
*.iml
target/*
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/Model/Controllers/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public String generateJwt(String userName, String password) {
}




@PostMapping("/a")
public ResponseEntity<?> authenticateUser(@RequestBody SignupRequest signupRequest){

Expand Down
45 changes: 31 additions & 14 deletions src/main/java/Model/Controllers/ModuleController.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/api/module")
@RequestMapping("/api/modules")
public class ModuleController {
@Autowired
AuthenticationManager authenticationManager;
Expand All @@ -49,22 +49,37 @@ public class ModuleController {
JwtUtils jwtUtils;


@GetMapping("/{name}/getModules")
public ArrayList<String> getmodules(@PathVariable String name){
ArrayList<String> strings = new ArrayList<>();
Optional<User> ouser = userRepository.findByUsername(name);
@PreAuthorize("hasRole('TEACHER')")
@GetMapping("/who")
public ArrayList<String> getPersonne(Principal principal) {
ArrayList<String> data = new ArrayList<>();
data.add("la personne connectée est " +principal.getName());
return data ;

}


@GetMapping("/{idUser}")
public ArrayList<String> getmodules(@PathVariable Long idUser){
ArrayList<String> userModules = new ArrayList<>();
Optional<User> ouser = userRepository.findById(idUser);
if (!ouser.isPresent()) {
return null;
}
User user= ouser.get();

Set<Module> modules = user.getModules();

for (Module module:modules) {
strings.add(module.name + "/" + module.id);
userModules.add("module name : "+module.name + "| id : " + module.id);
}
return strings;
return userModules;
}





@GetMapping("/{id}/getRessources")
public ArrayList<String> getRessources(@PathVariable long id){
ArrayList<String> strings = new ArrayList<>();
Expand Down Expand Up @@ -163,22 +178,24 @@ public ResponseEntity<?> addUser(Principal principal, @PathVariable long id, @Pa
User actor = userRepository.findByUsername(principal.getName()).get();

Set<User> participants = module.getParticipants();
if ((participants.isEmpty() && actor.equals(user))
|| participants.contains(actor)) {
// if ((participants.isEmpty() && actor.equals(user))
// || participants.contains(actor)) {
// verifie si user n'apartient pas déjà à participants
if(!participants.contains(user)) {
participants.add(user);
user.getModules().add(module);
}else{
return ResponseEntity
.badRequest()
.body(new MessageResponse("Error: User y apartient deja !"));
}
} else {
return ResponseEntity
.badRequest()
.body(new MessageResponse("Error: Not allowed to add user!"));
}
// } else {
// return ResponseEntity
// .badRequest()
// .body(new MessageResponse("Error: Not allowed to add user!"));
// }
moduleRepository.save(module);
userRepository.save(user);
return ResponseEntity.ok(new MessageResponse("User successfully added to module!"));
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/Model/Documents/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public class Module {
inverseJoinColumns = @JoinColumn(name = "ressource_id"))
public Set<Ressource> ressources = new HashSet<>();

@ManyToMany(fetch = FetchType.LAZY)
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable( name = "module_user",
joinColumns = @JoinColumn(name = "module_id"),
inverseJoinColumns = @JoinColumn(name = "user_id"))
public Set<User> users;
public Set<User> users = new HashSet<>();

public Module() {
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/Model/Repositories/ModuleRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@
public interface ModuleRepository extends JpaRepository<Module, Long> {
Optional<Module> findByName(String name);

Optional<Module> findById(String name);
}
5 changes: 2 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

spring.datasource.url= jdbc:postgresql://localhost:5432/postgres
spring.datasource.username= postgres
spring.datasource.password= p34kleiorntk09kslQ

spring.datasource.password= gestionduprojet
#logging.level.root=error
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation= true
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.PostgreSQLDialect

Expand Down
10 changes: 10 additions & 0 deletions src/test/resources/features/Get.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Feature: Get

Background:
Given a user with login "steve"
And a module named "Gestion de projet"
And a cours named "Gestion"

Scenario: user check all modules that he subsccribe to
When "steve" check his modules
Then return all modules names

0 comments on commit d2c4806

Please sign in to comment.