Merge pull request #4 from HediMjid/hedii

modif class membre et team
This commit is contained in:
Hédi 2022-01-08 18:34:20 +01:00 committed by GitHub
commit d4208af0e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 159 additions and 37 deletions

View File

@ -1,9 +1,9 @@
package fr.organizee.controller;
import fr.organizee.model.Membre;
import fr.organizee.model.Team;
//import fr.organizee.model.Team;
import fr.organizee.repository.MembreRepository;
import fr.organizee.repository.TeamRepository;
//import fr.organizee.repository.TeamRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@ -16,15 +16,16 @@ import java.util.Optional;
/* toto */
@RestController
@CrossOrigin("*")
@RequestMapping("/membres")
public class MembreController {
@Autowired
private MembreRepository membreRepo;
@Autowired
private TeamRepository teamRepo;
// @Autowired
// private TeamRepository teamRepo;
@RequestMapping("/")
// @RequestMapping("/membres")
@ResponseBody
public String home()
{
@ -34,7 +35,7 @@ public class MembreController {
return sb.toString();
}
@GetMapping(value = "/membres/all")
@GetMapping(value = "/all")
public ResponseEntity<?> getAll(){
List<Membre> liste = null;
try
@ -47,20 +48,20 @@ public class MembreController {
return ResponseEntity.status(HttpStatus.OK).body(liste);
}
@GetMapping(value = "/team/all")
public ResponseEntity<?> getAllTeam(){
List<Team> liste = null;
try
{
liste = teamRepo.findAll();
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
// @GetMapping(value = "/team/all")
// public ResponseEntity<?> getAllTeam(){
// List<Team> liste = null;
// try
// {
// liste = teamRepo.findAll();
// } catch (Exception e) {
// return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
// }
//
// return ResponseEntity.status(HttpStatus.OK).body(liste);
// }
return ResponseEntity.status(HttpStatus.OK).body(liste);
}
@GetMapping(value = "/membres/{id}")
@GetMapping(value = "/{id}")
public ResponseEntity<?> findById(@PathVariable int id){
Optional<Membre> membre = null;
try
@ -105,16 +106,64 @@ public class MembreController {
return ResponseEntity.status(HttpStatus.CREATED).body(resultMembre);
}
@GetMapping(value = "/team/{id}")
public ResponseEntity<?> findTeamById(@PathVariable int id){
Optional<Team> liste = null;
try
{
liste = teamRepo.findById(id);
@PutMapping("/update/{id}")
public ResponseEntity<?> updateMembre(@RequestBody Membre membre, @PathVariable Integer id) throws Exception {
Membre resultMembre = null;
try {
resultMembre = membreRepo.save(membre);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
}
return ResponseEntity.status(HttpStatus.OK).body(liste);
return ResponseEntity.status(HttpStatus.OK).body(resultMembre);
}
// UPDATE SUR UN CHAMPS
// @PutMapping("/update/{id}")
// public ResponseEntity<?> updateMembre(@RequestBody Membre membre, @PathVariable Integer id) throws Exception {
// Membre resultMembre = null;
// Membre oldMembre = membreRepo.getById(id);
// oldMembre.setNom(membre.getNom());
// //Membre resultMembre = membreRepo.getById(id);
// try {
// resultMembre = membreRepo.save(oldMembre);
//
// } catch (Exception e) {
// return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
// }
//
// return ResponseEntity.status(HttpStatus.OK).body(resultMembre);
// }
// @GetMapping(value = "/team/{id}")
// public ResponseEntity<?> findTeamById(@PathVariable int id){
// Optional<Team> liste = null;
// try
// {
// liste = teamRepo.findById(id);
// } catch (Exception e) {
// return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
// }
//
// return ResponseEntity.status(HttpStatus.OK).body(liste);
// }
@PostMapping(value="/login", produces="application/json", consumes="application/json")
public ResponseEntity<?> login(@RequestBody Membre membre){
Membre resultMembre = null;
try {
resultMembre = membreRepo.findByNom(membre.getNom());
if(resultMembre == null){
throw new RuntimeException("User inexistant.");
}
if(!resultMembre.getPassword().equals(membre.getPassword())){
throw new RuntimeException("mauvais password.");
}
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
}
return ResponseEntity.status(HttpStatus.CREATED).body(resultMembre);
}
}

View File

@ -0,0 +1,59 @@
package fr.organizee.controller;
import fr.organizee.model.Team;
import fr.organizee.repository.TeamRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.persistence.EntityNotFoundException;
import java.util.List;
import java.util.Optional;
/* toto */
@RestController
@CrossOrigin("*")
@RequestMapping("/teams")
public class TeamController {
@Autowired
private TeamRepository teamRepo;
// @RequestMapping("/teams")
@ResponseBody
public String home()
{
StringBuilder sb = new StringBuilder();
sb.append("<h1>Affichages des teams</h1>");
sb.append("<ul><li><a href='http://localhost:8080/teams/all'>Liste des <strong>teams</strong></a></li>");
return sb.toString();
}
@GetMapping(value = "/all")
public ResponseEntity<?> getAllTeam(){
List<Team> liste = null;
try
{
liste = teamRepo.findAll();
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
return ResponseEntity.status(HttpStatus.OK).body(liste);
}
@GetMapping(value = "/{id}")
public ResponseEntity<?> findTeamById(@PathVariable int id){
Optional<Team> liste = null;
try
{
liste = teamRepo.findById(id);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
return ResponseEntity.status(HttpStatus.OK).body(liste);
}
}

View File

@ -1,5 +1,7 @@
package fr.organizee.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import javax.persistence.*;
import java.time.LocalDate;
@ -14,20 +16,22 @@ public class Contact {
private String email;
private String adresse;
private LocalDate dateNaissance;
/* @ManyToOne(fetch= FetchType.EAGER)
@ManyToOne(cascade = CascadeType.MERGE)
@JoinColumn(name="TEAM_ID")
private Team team;*/
@JsonIgnoreProperties("contact")
private Team team;
public Contact() {
}
public Contact(String nom, String prenom, String telephone, String email, String adresse, LocalDate dateNaissance) {
public Contact(String nom, String prenom, String telephone, String email, String adresse, LocalDate dateNaissance, Team team) {
this.nom = nom;
this.prenom = prenom;
this.telephone = telephone;
this.email = email;
this.adresse = adresse;
this.dateNaissance = dateNaissance;
this.team = team;
}
public int getId() {
@ -86,6 +90,13 @@ public class Contact {
this.dateNaissance = dateNaissance;
}
public Team getTeam() {
return team;
}
public void setTeam(Team team) {
this.team = team;
}
@Override
public String toString() {
return "Contact{" +

View File

@ -1,5 +1,7 @@
package fr.organizee.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@ -10,11 +12,12 @@ public class Team {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String nom;
@OneToMany(mappedBy = "team", cascade = CascadeType.ALL, orphanRemoval = true)
//@OneToMany
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY)
@JsonIgnoreProperties("team")
private List<Membre> membres = new ArrayList<>();
@OneToMany
@JoinTable(name = "repertoire")
@OneToMany(mappedBy = "team", fetch=FetchType.LAZY)
@JsonIgnoreProperties("team")
//@JoinTable(name = "repertoire")
private List<Contact> contacts = new ArrayList<>();
@OneToMany
@JoinTable(name = "team_todolist")

View File

@ -6,5 +6,5 @@ import org.springframework.stereotype.Repository;
@Repository
public interface MembreRepository extends JpaRepository<Membre, Integer> {
Membre findByNom(String nom);
}

View File

@ -1,7 +1,7 @@
# base de données MySQL
spring.datasource.url=jdbc:mysql://192.168.1.16:3306/jpa?useSSL=false&zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=UTC
spring.datasource.username=
spring.datasource.password=
spring.datasource.username=desktop
spring.datasource.password=Cosmoc4t$77
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# log
#logging.level.root=INFO