debut de tache controller
This commit is contained in:
parent
2c243ae900
commit
096e907446
|
@ -0,0 +1,37 @@
|
|||
package fr.organizee.controller;
|
||||
|
||||
import fr.organizee.model.Evenement;
|
||||
import fr.organizee.model.Membre;
|
||||
import fr.organizee.model.Team;
|
||||
import fr.organizee.repository.EvenementRepository;
|
||||
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 java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin("*")
|
||||
@RequestMapping("/evenements")
|
||||
public class EvenementController {
|
||||
|
||||
@Autowired
|
||||
private EvenementRepository evenementRepo;
|
||||
|
||||
// Recupérer tout les evenements pour une team {id}
|
||||
@GetMapping(value = "/all/{id}")
|
||||
public ResponseEntity<?> getAll(){
|
||||
List<Evenement> liste = null;
|
||||
try
|
||||
{
|
||||
liste = evenementRepo.findAll();
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
||||
}
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(liste);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package fr.organizee.controller;
|
||||
|
||||
import fr.organizee.model.Membre;
|
||||
import fr.organizee.model.Tache;
|
||||
import fr.organizee.repository.MembreRepository;
|
||||
import fr.organizee.repository.TacheRepository;
|
||||
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;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin("*")
|
||||
@RequestMapping("/taches")
|
||||
public class TacheController {
|
||||
@Autowired
|
||||
private TacheRepository tacheRepo;
|
||||
|
||||
@GetMapping(value = "/all")
|
||||
public ResponseEntity<?> getAll(){
|
||||
List<Tache> liste = null;
|
||||
try
|
||||
{
|
||||
liste = tacheRepo.findAll();
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
||||
}
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(liste);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/{id}")
|
||||
public ResponseEntity<?> findById(@PathVariable int id){
|
||||
Optional<Tache> tache = null;
|
||||
try
|
||||
{
|
||||
tache = tacheRepo.findById(id);
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
|
||||
}
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(tache);
|
||||
}
|
||||
|
||||
@DeleteMapping(value = "/delete/{id}")
|
||||
public ResponseEntity<?> deleteTache(@PathVariable int id){
|
||||
try {
|
||||
tacheRepo.delete(tacheRepo.getById(id));
|
||||
return ResponseEntity.status(HttpStatus.OK).body("Tache effacée !");
|
||||
|
||||
} catch (EntityNotFoundException e) {
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body("Tache introuvable !");
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping(value="/add", produces="application/json", consumes="application/json")
|
||||
public ResponseEntity<?> addTache(@RequestBody Tache tache){
|
||||
Tache resultTache = null;
|
||||
try {
|
||||
resultTache = tacheRepo.saveAndFlush(tache);
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
|
||||
}
|
||||
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(resultTache);
|
||||
}
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
public ResponseEntity<?> updateTache(@RequestBody Tache tache, @PathVariable Integer id) throws Exception {
|
||||
Tache resultTache = null;
|
||||
try {
|
||||
resultTache = tacheRepo.save(tache);
|
||||
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
|
||||
}
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(resultTache);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
package fr.organizee.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
public class Evenement {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private int id;
|
||||
private LocalDateTime eventDebut;
|
||||
private LocalDateTime eventFin;
|
||||
private int allDay;
|
||||
private String libelle;
|
||||
@ManyToOne(cascade = CascadeType.MERGE)
|
||||
@JoinColumn(name="MEMBRE_ID")
|
||||
@JsonIgnoreProperties("evenement")
|
||||
private Membre membre;
|
||||
@ManyToOne(cascade = CascadeType.MERGE)
|
||||
@JoinColumn(name="TEAM_ID")
|
||||
@JsonIgnoreProperties("evenement")
|
||||
private Team team;
|
||||
|
||||
public Evenement() {
|
||||
}
|
||||
|
||||
public Evenement(int id, LocalDateTime eventDebut, LocalDateTime eventFin, int allDay, String libelle, Membre membre, Team team) {
|
||||
this.id = id;
|
||||
this.eventDebut = eventDebut;
|
||||
this.eventFin = eventFin;
|
||||
this.allDay = allDay;
|
||||
this.libelle = libelle;
|
||||
this.membre = membre;
|
||||
this.team = team;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDateTime getEventDebut() {
|
||||
return eventDebut;
|
||||
}
|
||||
|
||||
public void setEventDebut(LocalDateTime eventDebut) {
|
||||
this.eventDebut = eventDebut;
|
||||
}
|
||||
|
||||
public LocalDateTime getEventFin() {
|
||||
return eventFin;
|
||||
}
|
||||
|
||||
public void setEventFin(LocalDateTime eventFin) {
|
||||
this.eventFin = eventFin;
|
||||
}
|
||||
|
||||
public int getAllDay() {
|
||||
return allDay;
|
||||
}
|
||||
|
||||
public void setAllDay(int allDay) {
|
||||
this.allDay = allDay;
|
||||
}
|
||||
|
||||
public String getLibelle() {
|
||||
return libelle;
|
||||
}
|
||||
|
||||
public void setLibelle(String libelle) {
|
||||
this.libelle = libelle;
|
||||
}
|
||||
|
||||
public Membre getMembre() {
|
||||
return membre;
|
||||
}
|
||||
|
||||
public void setMembre(Membre membre) {
|
||||
this.membre = membre;
|
||||
}
|
||||
|
||||
public Team getTeam() {
|
||||
return team;
|
||||
}
|
||||
|
||||
public void setTeam(Team team) {
|
||||
this.team = team;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Evenement{" +
|
||||
"id=" + id +
|
||||
", eventDebut=" + eventDebut +
|
||||
", eventFin=" + eventFin +
|
||||
", allDay=" + allDay +
|
||||
", libelle='" + libelle + '\'' +
|
||||
", membre=" + membre +
|
||||
", team=" + team +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package fr.organizee.repository;
|
||||
|
||||
import fr.organizee.model.Evenement;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface EvenementRepository extends JpaRepository<Evenement, Integer> {
|
||||
}
|
|
@ -1,4 +1,9 @@
|
|||
package fr.organizee.repository;
|
||||
|
||||
public interface TacheRepository {
|
||||
import fr.organizee.model.Tache;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface TacheRepository extends JpaRepository<Tache, Integer> {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue