Ajout class+controller

This commit is contained in:
Hedi 2021-12-14 16:11:23 +01:00
parent 75dbe1c4b8
commit 8895d30b22
8 changed files with 95 additions and 63 deletions

View File

@ -1,16 +1,17 @@
package fr.organizee.controller;
import fr.organizee.model.Membre;
import fr.organizee.model.Team;
import fr.organizee.repository.MembreRepository;
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.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Optional;
/* toto */
@RestController
@CrossOrigin("*")
@ -19,17 +20,20 @@ public class MembreController {
@Autowired
private MembreRepository membreRepo;
@Autowired
private TeamRepository teamRepo;
@GetMapping("/")
@ResponseBody
public String home()
{
StringBuilder sb = new StringBuilder();
sb.append("<h1>Affichages des membres</h1>");
sb.append("<ul><li><a href='http://localhost:8080/membres'>Liste des <strong>membres</strong></a></li>");
sb.append("<ul><li><a href='http://localhost:8080/membres/all'>Liste des <strong>membres</strong></a></li>");
return sb.toString();
}
@GetMapping(value = "/membres")
@GetMapping(value = "/membres/all")
public ResponseEntity<?> getAll(){
List<Membre> liste = null;
try
@ -41,4 +45,50 @@ 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);
}
return ResponseEntity.status(HttpStatus.OK).body(liste);
}
@GetMapping(value = "/membres/{id}")
public ResponseEntity<?> findById(@PathVariable int id){
Optional<Membre> membre = null;
try
{
membre = membreRepo.findById(id);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
}
return ResponseEntity.status(HttpStatus.OK).body(membre);
}
@GetMapping(value = "/membres/delete/{id}")
public void deleteMembreId(@PathVariable("id") Integer id) {
membreRepo.deleteById(id);
}
@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);
}
}

View File

@ -16,16 +16,15 @@ public class Membre {
private String password;
private String isAdmin;
private String couleur;
/* @ManyToOne(fetch= FetchType.EAGER)
private String smiley;
@ManyToOne
@JoinColumn(name="TEAM_ID")
private Team team;*/
// @ManyToOne
// private Smiley smiley;
private Team team;
public Membre() {
}
public Membre(String nom, String prenom, LocalDate dateNaissance, String email, String password, String isAdmin, String couleur, Team team) {
public Membre(String nom, String prenom, LocalDate dateNaissance, String email, String password, String isAdmin, String couleur, String smiley, Team team) {
this.nom = nom;
this.prenom = prenom;
this.dateNaissance = dateNaissance;
@ -33,6 +32,7 @@ public class Membre {
this.password = password;
this.isAdmin = isAdmin;
this.couleur = couleur;
this.smiley = smiley;
/* this.team = team;*/
}
@ -78,12 +78,13 @@ public class Membre {
public void setIsAdmin(String isAdmin) {
this.isAdmin = isAdmin;
}
/* public Team getTeam() {
public Team getTeam() {
return team;
}
public void setTeam(Team team) {
this.team = team;
}*/
}
public String getCouleur() {
return couleur;
@ -93,6 +94,14 @@ public class Membre {
this.couleur = couleur;
}
public String getSmiley() {
return smiley;
}
public void setSmiley(String smiley) {
this.smiley = smiley;
}
@Override
public String toString() {
return "Membre{" +
@ -104,6 +113,7 @@ public class Membre {
", password='" + password + '\'' +
", isAdmin='" + isAdmin + '\'' +
", couleur='" + couleur + '\'' +
", smiley='" + smiley + '\'' +
/*", team=" + team +*/
'}';
}

View File

@ -10,7 +10,10 @@ public class Menu {
private int id;
private String libelle;
private LocalDate dateMenu;
@ManyToOne
private Team team;
@ManyToOne
private Membre membre;
public Menu() {
}

View File

@ -1,46 +0,0 @@
package fr.organizee.model;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
public class Smiley {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String smileyUrl;
@OneToMany
private List<Membre> membres = new ArrayList<>();
public Smiley() {
}
public Smiley(String smileyUrl) {
this.smileyUrl = smileyUrl;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getSmileyUrl() {
return smileyUrl;
}
public void setSmileyUrl(String smileyUrl) {
this.smileyUrl = smileyUrl;
}
@Override
public String toString() {
return "Smiley{" +
"id=" + id +
", smileyUrl='" + smileyUrl + '\'' +
'}';
}
}

View File

@ -10,7 +10,8 @@ public class Team {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String nom;
@OneToMany
@OneToMany(mappedBy = "team", cascade = CascadeType.ALL, orphanRemoval = true)
//@OneToMany
private List<Membre> membres = new ArrayList<>();
@OneToMany
@JoinTable(name = "repertoire")
@ -18,6 +19,9 @@ public class Team {
@OneToMany
@JoinTable(name = "team_todolist")
private List<TodoList> todolists = new ArrayList<>();
@OneToMany
@JoinTable(name="team_menu")
private List<Menu> menus = new ArrayList<>();
public Team() {
super();

View File

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

View File

@ -1,4 +1,9 @@
package fr.organizee.repository;
public interface TeamRepository {
import fr.organizee.model.Team;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface TeamRepository extends JpaRepository<Team, Integer> {
}

View File

@ -1,4 +1,9 @@
package fr.organizee.repository;
public interface TodoListRepository {
import fr.organizee.model.TodoList;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface TodoListRepository extends JpaRepository<TodoList, Integer> {
}