Merge pull request #24 from HediMjid/calendrier

calendrier : modif model + repository + controller
This commit is contained in:
Hédi 2022-02-09 12:05:12 +01:00 committed by GitHub
commit caa0e896bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 31 deletions

View File

@ -1,15 +1,14 @@
package fr.organizee.controller; package fr.organizee.controller;
import fr.organizee.model.Evenement; import fr.organizee.model.Evenement;
import fr.organizee.model.Membre; import fr.organizee.model.Menu;
import fr.organizee.model.Team;
import fr.organizee.repository.EvenementRepository; import fr.organizee.repository.EvenementRepository;
import fr.organizee.repository.TeamRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.persistence.EntityNotFoundException;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -21,17 +20,59 @@ public class EvenementController {
@Autowired @Autowired
private EvenementRepository evenementRepo; private EvenementRepository evenementRepo;
// Recupérer tout les evenements pour une team {id} // Recupérer tout les evenements pour une team {team_id}
@GetMapping(value = "/all/{id}") @GetMapping(value = "/team/{team_id}")
public ResponseEntity<?> getAll(){ public ResponseEntity<?> findByTeamId(@PathVariable int team_id){
List<Evenement> liste = null; List<Evenement> liste = null;
try try
{ {
liste = evenementRepo.findAll(); liste = evenementRepo.FindEvenementsByTeam(team_id);
} catch (Exception e) { } catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
} }
return ResponseEntity.status(HttpStatus.OK).body(liste); return ResponseEntity.status(HttpStatus.OK).body(liste);
} }
// Ajoute un evenement au calendrier
@PostMapping(value="/add", produces="application/json", consumes="application/json")
public ResponseEntity<?> addTache(@RequestBody Evenement event){
Evenement resultEvent = null;
try {
resultEvent = evenementRepo.saveAndFlush(event);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
}
return ResponseEntity.status(HttpStatus.CREATED).body(resultEvent);
}
//Mise a jour d'un evenement par son ID
@PutMapping("/update/{id}")
//@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> updateEvenement(@RequestBody Evenement event, @PathVariable Integer id) throws Exception {
Evenement resultEvenement = null;
try {
resultEvenement = evenementRepo.save(event);
} catch (Exception e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage());
}
return ResponseEntity.status(HttpStatus.OK).body(resultEvenement);
}
//Efface un evenement par son ID
@DeleteMapping(value = "/delete/{id}")
//@PreAuthorize("hasRole('ROLE_PARENT')")
public ResponseEntity<?> deleteEvenement(@PathVariable int id){
try {
evenementRepo.delete(evenementRepo.getById(id));
return ResponseEntity.status(HttpStatus.OK).body("Evenement effacé !");
} catch (EntityNotFoundException e) {
return ResponseEntity.status(HttpStatus.OK).body("Evenement introuvable !");
}
}
} }

View File

@ -11,10 +11,10 @@ public class Evenement {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private int id; private int id;
private LocalDateTime eventDebut; private LocalDateTime start;
private LocalDateTime eventFin; private LocalDateTime end;
private int allDay; private int allDay;
private String libelle; private String text;
@ManyToOne @ManyToOne
@JoinColumn(name="MEMBRE_ID") @JoinColumn(name="MEMBRE_ID")
@JsonIgnoreProperties("evenement") @JsonIgnoreProperties("evenement")
@ -27,12 +27,12 @@ public class Evenement {
public Evenement() { public Evenement() {
} }
public Evenement(int id, LocalDateTime eventDebut, LocalDateTime eventFin, int allDay, String libelle, Membre membre, Team team) { public Evenement(int id, LocalDateTime start, LocalDateTime end, int allDay, String text, Membre membre, Team team) {
this.id = id; this.id = id;
this.eventDebut = eventDebut; this.start = start;
this.eventFin = eventFin; this.end = end;
this.allDay = allDay; this.allDay = allDay;
this.libelle = libelle; this.text = text;
this.membre = membre; this.membre = membre;
this.team = team; this.team = team;
} }
@ -45,20 +45,20 @@ public class Evenement {
this.id = id; this.id = id;
} }
public LocalDateTime getEventDebut() { public LocalDateTime getStart() {
return eventDebut; return start;
} }
public void setEventDebut(LocalDateTime eventDebut) { public void setStart(LocalDateTime start) {
this.eventDebut = eventDebut; this.start = start;
} }
public LocalDateTime getEventFin() { public LocalDateTime getEnd() {
return eventFin; return end;
} }
public void setEventFin(LocalDateTime eventFin) { public void setEnd(LocalDateTime end) {
this.eventFin = eventFin; this.end = end;
} }
public int getAllDay() { public int getAllDay() {
@ -69,12 +69,12 @@ public class Evenement {
this.allDay = allDay; this.allDay = allDay;
} }
public String getLibelle() { public String getText() {
return libelle; return text;
} }
public void setLibelle(String libelle) { public void setText(String text) {
this.libelle = libelle; this.text = text;
} }
public Membre getMembre() { public Membre getMembre() {
@ -97,10 +97,10 @@ public class Evenement {
public String toString() { public String toString() {
return "Evenement{" + return "Evenement{" +
"id=" + id + "id=" + id +
", eventDebut=" + eventDebut + ", start=" + start +
", eventFin=" + eventFin + ", end=" + end +
", allDay=" + allDay + ", allDay=" + allDay +
", libelle='" + libelle + '\'' + ", text='" + text + '\'' +
", membre=" + membre + ", membre=" + membre +
", team=" + team + ", team=" + team +
'}'; '}';

View File

@ -2,8 +2,15 @@ package fr.organizee.repository;
import fr.organizee.model.Evenement; import fr.organizee.model.Evenement;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
@Repository @Repository
public interface EvenementRepository extends JpaRepository<Evenement, Integer> { public interface EvenementRepository extends JpaRepository<Evenement, Integer> {
@Query(value = "select * from evenement where team_id = :team_id", nativeQuery = true)
List<Evenement> FindEvenementsByTeam(@Param("team_id") int team_id);
} }

View File

@ -37,5 +37,10 @@ INSERT INTO `tache` (`id`, `etat`, `texte`, `todolist_id`) VALUES
(4, 0, 'Acheter un sapin', 3), (4, 0, 'Acheter un sapin', 3),
(5, 0, 'Trouver un repas', 3); (5, 0, 'Trouver un repas', 3);
INSERT INTO `evenement` (`id`, `all_day`, `event_debut`, `event_fin`, `libelle`, `membre_id`, `team_id`) VALUES INSERT INTO `evenement` (`id`, `all_day`, `start`, `end`, `text`, `membre_id`, `team_id`) VALUES
(1, 0, '2022-01-13 09:00:33', '2022-01-13 13:04:38', 'Simplon', 1, 1); (1, 0, '2022-02-04 09:00:00', '2022-02-04 13:00:00', 'Simplon', 1, 1),
(2, 0, '2022-02-03 12:00:00', '2022-02-03 13:00:00', 'Footing', 2, 1);
INSERT INTO `menu` (`id`, `date_menu`, `libelle`, `validation_proposition`, `team_id`) VALUES
(1, '2022-01-13', 'Lasagnes', 1, 1),
(2, '2022-01-03', 'Kebab', 1, 1);