diff --git a/back-end/src/main/java/tenders/evenement/Evenement.java b/back-end/src/main/java/tenders/evenement/Evenement.java index 9a9ac10b091d0851316c093a923bb88638264717..9f4225d34464c7dca8b1561897f10d579a18440f 100644 --- a/back-end/src/main/java/tenders/evenement/Evenement.java +++ b/back-end/src/main/java/tenders/evenement/Evenement.java @@ -1,7 +1,5 @@ package tenders.evenement; -import java.util.Date; - import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -24,9 +22,10 @@ public class Evenement { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String title; - private Date date; + private String date; private Boolean isPublic; private Boolean isAnonyme; + private Integer nombre; @ManyToOne(optional = false) @JoinColumn(name = "user_id", nullable = false) @@ -63,17 +62,31 @@ public class Evenement { this.title = Title; } + /** + * @return the number max + */ + public Integer getNombre() { + return this.nombre; + } + + /** + * @param nombre the number max to set + */ + public void setNombre(Integer nombre) { + this.nombre = nombre; + } + /** * @return the date */ - public Date getDate() { + public String getDate() { return this.date; } /** * @param date the date to set */ - public void setDate(Date date) { + public void setDate(String date) { this.date = date; } diff --git a/back-end/src/main/java/tenders/notifications/Notification.java b/back-end/src/main/java/tenders/notifications/Notification.java index b494e8e5d01152303e5601bcc829d12d798dd7e7..19360872b96ce151fb159733160a063f78a91795 100644 --- a/back-end/src/main/java/tenders/notifications/Notification.java +++ b/back-end/src/main/java/tenders/notifications/Notification.java @@ -22,7 +22,7 @@ public class Notification { @Enumerated(EnumType.STRING) private Type type; - + private String eventName; private Long typeId; @ManyToOne(optional = false) @@ -89,6 +89,20 @@ public class Notification { this.auteur = auteur; } + /** + * @return the event name + */ + public String getEventName() { + return eventName; + } + + /** + * @param eventName the eventName to set + */ + public void setEventName(String eventName) { + this.eventName = eventName; + } + /** * @return the destinataire */ diff --git a/back-end/src/main/java/tenders/notifications/NotificationController.java b/back-end/src/main/java/tenders/notifications/NotificationController.java index 1a8c05f4211e3e4c0ec46300db7f913d68d2505d..aa4bace3ef01bfcd3ba7e8023d0431e8f89401ad 100644 --- a/back-end/src/main/java/tenders/notifications/NotificationController.java +++ b/back-end/src/main/java/tenders/notifications/NotificationController.java @@ -86,11 +86,14 @@ public class NotificationController { } @PostMapping("/users/{username}/invitations") - public void envoyerInvitation(@PathVariable(name = "username") String username, + public Notification envoyerInvitation(@PathVariable(name = "username") String username, @RequestBody Notification notification, Authentication authentication) { + Evenement evenement = this.evenementRepository.findById(notification.getTypeId()).get(); notification.setAuteur(this.userRepository.findByUsername(authentication.getName())); - notification.setAuteur(this.userRepository.findByUsername(username)); + notification.setDestinataire(this.userRepository.findByUsername(username)); + notification.setEventName(evenement.getTitle()); notification.setType(Type.EVT); + return this.notificationRepository.save(notification); } @GetMapping("/users/me/notifications") diff --git a/back-end/src/main/java/tenders/user/UserController.java b/back-end/src/main/java/tenders/user/UserController.java index f87d4e477cefa822623d6bb92b4adbe0836e1545..19ca47b7dcb95a257897d07a973bf301ee794ee7 100644 --- a/back-end/src/main/java/tenders/user/UserController.java +++ b/back-end/src/main/java/tenders/user/UserController.java @@ -61,7 +61,7 @@ public class UserController { return this.applicationUserRepository.save(user); } - @PostMapping("/me") + @PostMapping("/me/profil") public ApplicationUser changeInfos(@RequestBody ApplicationUser form, Authentication authentication) { ApplicationUser user = this.applicationUserRepository.findByUsername(authentication.getName()); user.setAdresse(form.getAdresse()); diff --git a/front-end/src/components/ItemEvenement.vue b/front-end/src/components/ItemEvenement.vue index fc104fc0f82a6940c38df6286c6d88adfd4ca019..2ab20c437e90ce69c6e36c024366dd584ac983f5 100644 --- a/front-end/src/components/ItemEvenement.vue +++ b/front-end/src/components/ItemEvenement.vue @@ -6,8 +6,8 @@ <v-icon v-else>visibility</v-icon> </v-list-tile-avatar> <v-list-tile-content> - <v-list-tile-title>{{ event.nom }} ({{ event.date }})</v-list-tile-title> - <v-list-tile-sub-title>{{ event.nbMembres }}/{{ event.nbMax }} participants dont {{ event.ratio }} de femmes</v-list-tile-sub-title> + <v-list-tile-title>{{ event.title }} ({{ event.date }})</v-list-tile-title> + <v-list-tile-sub-title>{{ event.nbMembres }}/{{ event.nombre }} participants dont {{ event.nbFemmes }} femme(s) et {{ event.nbHommes }} homme(s)</v-list-tile-sub-title> </v-list-tile-content> <v-list-tile-action> <v-btn icon ripple v-if="inscrit" @click.stop="$emit('onExit', event.id)"> diff --git a/front-end/src/views/Accueil.vue b/front-end/src/views/Accueil.vue index 8fb9b7c199bdc80a03bd01ac50572f4376c36e17..ee2ac2882cb1a648b18baef4b7bbf919ca188f39 100644 --- a/front-end/src/views/Accueil.vue +++ b/front-end/src/views/Accueil.vue @@ -14,10 +14,14 @@ <v-list-tile v-for="item in notifications" :key="item.titre"> <v-list-tile-avatar> <v-icon v-if="item.type == 'AMI'">person_add</v-icon> + <v-icon v-if="item.type == 'EVT'">event</v-icon> </v-list-tile-avatar> <v-list-tile-content v-if="item.type == 'AMI'"> <v-list-tile-title>{{ item.auteur.nom }} vous a envoyé une demande de relation</v-list-tile-title> </v-list-tile-content> + <v-list-tile-content v-if="item.type == 'EVT'"> + <v-list-tile-title>{{ item.auteur.nom }} vous a invité à l'évènement {{ item.eventName }}</v-list-tile-title> + </v-list-tile-content> <v-list-tile-action> <v-btn icon ripple @click.stop="acceptNotification(item.id)"> <v-icon>check</v-icon> diff --git a/front-end/src/views/Evenements.vue b/front-end/src/views/Evenements.vue index dab3839672c596a603046fd7619f2e3ba218e3df..56b6160ff4627be2fcdf8fc3f9d2754d3d760b42 100644 --- a/front-end/src/views/Evenements.vue +++ b/front-end/src/views/Evenements.vue @@ -13,27 +13,40 @@ <v-icon>add</v-icon> </v-tab> <v-tab-item> - <v-list v-for="item in event_dispo" :key="item.id"> - <ItemEvenement :event="item" :inscrit="false" @onAdd="inscrireAEvenement"></ItemEvenement> + <v-list v-if="eventDispoShow.length > 0"> + <ItemEvenement + v-for="item in eventDispoShow" + :key="item.id" + :event="item" + :inscrit="false" + @onAdd="inscrireAEvenement" + ></ItemEvenement> </v-list> + <div + class="text-xs-center pt-3" + v-else + >Aucun évènement disponible pour le moment</div> </v-tab-item> <v-tab-item> - <v-list v-for="item in event_membre" :key="item.id"> + <v-list v-if="event_membre.length > 0"> <ItemEvenement + v-for="item in event_membre" + :key="item.id" :event="item" :inscrit="true" @onExit="quitterEvenement" @selected="viewEventDialog" ></ItemEvenement> </v-list> + <div class="text-xs-center pt-3" v-else>Aucun évènement membre pour le moment</div> </v-tab-item> <v-tab-item> <v-form ref="formCreer" v-model="creer.isValid" lazy-validation> <v-card> <v-card-text> <v-text-field - v-model="creer.name.value" - :label="creer.name.label" + v-model="creer.title.value" + :label="creer.title.label" :rules="creer.rules" required ></v-text-field> @@ -53,12 +66,12 @@ required ></v-text-field> <v-checkbox - v-model="creer.anonyme.value" - :label="creer.anonyme.label" + v-model="creer.isAnonyme.value" + :label="creer.isAnonyme.label" ></v-checkbox> <v-checkbox - v-model="creer.public.value" - :label="creer.public.label" + v-model="creer.isPublic.value" + :label="creer.isPublic.label" ></v-checkbox> </v-card-text> <v-card-actions> @@ -93,7 +106,7 @@ </v-btn> <v-list v-if="!currentEvent.isAnonyme"> <ItemPersonne - v-for="item in currentEvent.personnes" + v-for="item in currentEvent.discussion.participants" :key="item.id" :personne="item" ></ItemPersonne> @@ -134,11 +147,11 @@ export default { event_membre: [], creer: { isValid: true, - name: { value: null, label: "Nom" }, + title: { value: null, label: "Nom" }, date: { value: null, label: "Date" }, nombre: { value: null, label: "Nombre max de participants" }, - anonyme: { value: false, label: "Anonyme ?" }, - public: { value: true, label: "Public ?" }, + isAnonyme: { value: false, label: "Anonyme ?" }, + isPublic: { value: true, label: "Public ?" }, rules: [v => !!v || "Ce champs est requis !"] }, eventView: { @@ -162,94 +175,63 @@ export default { }, methods: { inscrireAEvenement(id) { - // A COMPLETER AVEC AXIOS - console.log("inscrit à l'évènement ID=" + id); + axios.post("/evenements/" + id + "/participants").then(rep => { + this.refreshAll(); + }); }, quitterEvenement(id) { - // A COMPLETER AVEC AXIOS - console.log("quitte l'évènement ID=" + id); + axios.post("/evenements/" + id + "/quitter").then(rep => { + this.refreshAll(); + }); }, creerEvenement() { - // A COMPLETER AVEC AXIOS if (this.$refs.formCreer.validate()) { - console.log("creer evenement " + this.creer.name.value); + axios + .post("/evenements", { + title: this.creer.title.value, + date: this.creer.date.value, + nombre: this.creer.nombre.value, + isPublic: this.creer.isPublic.value, + isAnonyme: this.creer.isAnonyme.value + }) + .then(rep => { + this.refreshAll(); + }); } }, refreshEventDispo() { - // A COMPLETER AVEC AXIOS - this.event_dispo = [ - { - id: 1, - nom: "Bazoom", - date: "12/01/2019", - isPublic: true, - nbMembres: 12, - nbMax: 50, - isAnonyme: true, - ratio: "23%" - }, - { - id: 2, - nom: "Anniversaire", - date: "12/01/2019", - isPublic: true, - nbMembres: 1, - nbMax: 3, - isAnonyme: false, - ratio: "50%" - } - ]; + axios.get("/evenements").then(rep => { + this.event_dispo = rep.data; + this.event_dispo.forEach(this.computeEvent); + }); }, refreshEventMembre() { - // A COMPLETER AVEC AXIOS - this.event_membre = [ - { - id: 3, - nom: "Amour", - date: "14/03/2019", - isPublic: false, - nbMembres: 4, - nbMax: 5, - isAnonyme: false, - ratio: "20%", - personnes: [ - { - id: 1, - photo: "https://picsum.photos/1", - nom: "Roger" - }, - { - id: 2, - photo: "https://picsum.photos/2", - nom: "Ginette" - }, - { - id: 3, - photo: "https://picsum.photos/3", - nom: "Léo" - } - ] - }, - { - id: 4, - nom: "Sexe", - date: "20/03/2019", - isPublic: false, - nbMembres: 50, - nbMax: 60, - isAnonyme: true, - ratio: "30%" - } - ]; + axios.get("/users/me/evenements").then(rep => { + this.event_membre = rep.data; + this.event_membre.forEach(this.computeEvent); + }); }, inviterPersonne(personne) { - // A COMPLETER AVEC AXIOS - console.log(personne.nom, this.eventView.currentEventId); - this.inviteView.toggle = false; + axios.post("/users/" + personne.username + "/invitations", { + typeId: this.eventView.currentEventId + }); }, viewEventDialog(id) { this.eventView.currentEventId = id; this.eventView.toggle = true; + }, + computeEvent(element, index, array) { + element.nbMembres = element.discussion.participants.length; + element.nbFemmes = element.discussion.participants.filter(item => { + return item.genre === "FEMININ"; + }).length; + element.nbHommes = element.discussion.participants.filter(item => { + return item.genre === "MASCULIN"; + }).length; + }, + refreshAll() { + this.refreshEventDispo(); + this.refreshEventMembre(); } }, computed: { @@ -257,6 +239,14 @@ export default { return this.event_membre.find( x => x.id == this.eventView.currentEventId ); + }, + eventDispoShow() { + var mapped = this.event_membre.map(item => item.id); + return this.event_dispo.filter(event => { + return ( + !mapped.includes(event.id) && event.nombre > event.nbMembres + ); + }); } } };