Oui oui baguette

This commit is contained in:
Laurent
2025-03-19 14:27:15 +01:00
parent 83a0a23268
commit 9cea2c3239
21 changed files with 165 additions and 157 deletions

View File

@@ -4,17 +4,17 @@ import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
public class Participant {
public class Attendee {
private String name;
private Set<EventDate> dates;
public Participant(String name){
public Attendee(String name){
this(name, new HashSet<>());
}
public Participant(String name, Set<EventDate> dates){
public Attendee(String name, Set<EventDate> dates){
this.name = name;
this.dates = dates;
}
@@ -37,7 +37,7 @@ public class Participant {
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
Participant date = (Participant) obj;
Attendee date = (Attendee) obj;
return Objects.equals(name, date.name);
}

View File

@@ -5,24 +5,24 @@ import java.util.*;
public class Event {
private String name;
private Set<Participant> participants;
private Set<Attendee> attendees;
public Event(String name, Set<Participant> participants){
public Event(String name, Set<Attendee> attendees){
this.name = name;
this.participants = participants;
this.attendees = attendees;
}
public String getName() {
return name;
}
public Set<Participant> getParticipants(){
return new HashSet<>(this.participants);
public Set<Attendee> getAttendees(){
return new HashSet<>(this.attendees);
}
public Set<EventDate> getDates() {
Set<EventDate> dates = new HashSet<>();
for (Participant p : this.participants) {
for (Attendee p : this.attendees) {
dates.addAll(p.getDates());
}
return dates;

View File

@@ -4,8 +4,8 @@ import jakarta.persistence.*;
import java.util.Set;
@Entity
public class ParticipantEntity {
@Entity(name = "Attendees")
public class AttendeeEntity {
@Id
@GeneratedValue(strategy = GenerationType.UUID)

View File

@@ -23,7 +23,7 @@ public class EventDateEntity {
public EventEntity event;
@ManyToMany(mappedBy = "dates")
public Set<ParticipantEntity> participants;
public Set<AttendeeEntity> attendees;
@Override
public boolean equals(Object obj) {

View File

@@ -22,8 +22,8 @@ public class EventEntity {
public Set<EventDateEntity> dates;
@Column
@OneToMany(targetEntity=ParticipantEntity.class, cascade=CascadeType.ALL, mappedBy="event")
public Set<ParticipantEntity> participants;
@OneToMany(targetEntity=AttendeeEntity.class, cascade=CascadeType.ALL, mappedBy="event")
public Set<AttendeeEntity> attendees;
public void linkDates(){
for (EventDateEntity date : this.dates) {
@@ -31,16 +31,16 @@ public class EventEntity {
}
}
public void linkParticipants(){
for (ParticipantEntity participant : this.participants) {
participant.event = this;
public void linkAttendees(){
for (AttendeeEntity attendee : this.attendees) {
attendee.event = this;
}
}
public void removeDuplicatedDates(){
for (EventDateEntity ede: dates) {
for (ParticipantEntity pe : participants) {
for (AttendeeEntity pe : attendees) {
if(pe.dates.contains(ede)){
pe.dates.remove(ede);
pe.dates.add(ede);

View File

@@ -3,31 +3,31 @@ package be.naaturel.letsmeet.dto.database.factories;
import be.naaturel.letsmeet.core.helpers.TokenGenerator;
import be.naaturel.letsmeet.dto.database.EventDateEntity;
import be.naaturel.letsmeet.dto.database.EventEntity;
import be.naaturel.letsmeet.dto.database.ParticipantEntity;
import be.naaturel.letsmeet.dto.database.AttendeeEntity;
import java.util.HashSet;
import java.util.Set;
public class DatabasePropsFactory {
public static EventEntity createEvent(String name, Set<ParticipantEntity> participants){
public static EventEntity createEvent(String name, Set<AttendeeEntity> attendees){
EventEntity entity = new EventEntity();
entity.name = name;
entity.token = TokenGenerator.generate();
entity.participants = participants;
entity.attendees = attendees;
entity.dates = new HashSet<>();
for (ParticipantEntity pe : entity.participants) {
for (AttendeeEntity pe : entity.attendees) {
entity.dates.addAll(pe.dates);
}
entity.linkDates();
entity.linkParticipants();
entity.linkAttendees();
entity.removeDuplicatedDates();
return entity;
}
public static ParticipantEntity createParticipant(String name, Set<EventDateEntity> dates){
ParticipantEntity entity = new ParticipantEntity();
public static AttendeeEntity createAttendee(String name, Set<EventDateEntity> dates){
AttendeeEntity entity = new AttendeeEntity();
entity.name = name;
entity.dates = dates;
return entity;

View File

@@ -2,7 +2,7 @@ package be.naaturel.letsmeet.dto.httpRequest;
import java.util.Set;
public class ParticipantDTO {
public class AttendeeDTO {
public String name;

View File

@@ -5,6 +5,6 @@ import java.util.Set;
public class EventDTO {
public String name;
public Set<ParticipantDTO> participants;
public Set<AttendeeDTO> attendees;
}

View File

@@ -0,0 +1,46 @@
package be.naaturel.letsmeet.mappers.database;
import be.naaturel.letsmeet.dto.database.EventDateEntity;
import be.naaturel.letsmeet.dto.database.AttendeeEntity;
import be.naaturel.letsmeet.dto.database.factories.DatabasePropsFactory;
import be.naaturel.letsmeet.mappers.Mapper;
import be.naaturel.letsmeet.core.models.EventDate;
import be.naaturel.letsmeet.core.models.Attendee;
import java.util.Collection;
import java.util.HashSet;
import java.util.function.Supplier;
public class AttendeeMapper implements Mapper<Attendee, AttendeeEntity> {
private final Mapper<EventDate, EventDateEntity> dateMapper;
public AttendeeMapper(){
dateMapper = new EventDateMapper();
}
@Override
public AttendeeEntity toEntity(Attendee d) {
return DatabasePropsFactory.createAttendee(d.getName(), dateMapper.toEntities(d.getDates(), HashSet::new));
}
@Override
public Attendee toModel(AttendeeEntity d) {
return new Attendee(d.name, dateMapper.toModels(d.dates, HashSet::new));
}
@Override
public <C extends Collection<AttendeeEntity>> C toEntities(Collection<Attendee> attendees, Supplier<C> collectionSupplier) {
C result = collectionSupplier.get();
attendees.forEach(p -> result.add(toEntity(p)));
return result;
}
@Override
public <C extends Collection<Attendee>> C toModels(Collection<AttendeeEntity> attendees, Supplier<C> collectionSupplier) {
C result = collectionSupplier.get();
attendees.forEach(p -> result.add(toModel(p)));
return result;
}
}

View File

@@ -1,31 +1,31 @@
package be.naaturel.letsmeet.mappers.database;
import be.naaturel.letsmeet.dto.database.EventEntity;
import be.naaturel.letsmeet.dto.database.ParticipantEntity;
import be.naaturel.letsmeet.dto.database.AttendeeEntity;
import be.naaturel.letsmeet.dto.database.factories.DatabasePropsFactory;
import be.naaturel.letsmeet.mappers.Mapper;
import be.naaturel.letsmeet.core.models.Event;
import be.naaturel.letsmeet.core.models.Participant;
import be.naaturel.letsmeet.core.models.Attendee;
import java.util.*;
import java.util.function.Supplier;
public class EventMapper implements Mapper<Event, EventEntity> {
private final Mapper<Participant, ParticipantEntity> participantMapper;
private final Mapper<Attendee, AttendeeEntity> attendeeMapper;
public EventMapper(){
this.participantMapper = new ParticipantMapper();
this.attendeeMapper = new AttendeeMapper();
}
@Override
public EventEntity toEntity(Event event) {
return DatabasePropsFactory.createEvent(event.getName(), participantMapper.toEntities(event.getParticipants(), HashSet::new));
return DatabasePropsFactory.createEvent(event.getName(), attendeeMapper.toEntities(event.getAttendees(), HashSet::new));
}
@Override
public Event toModel(EventEntity eventEntity) {
return new Event(eventEntity.name, participantMapper.toModels(eventEntity.participants, HashSet::new));
return new Event(eventEntity.name, attendeeMapper.toModels(eventEntity.attendees, HashSet::new));
}
@Override

View File

@@ -1,46 +0,0 @@
package be.naaturel.letsmeet.mappers.database;
import be.naaturel.letsmeet.dto.database.EventDateEntity;
import be.naaturel.letsmeet.dto.database.ParticipantEntity;
import be.naaturel.letsmeet.dto.database.factories.DatabasePropsFactory;
import be.naaturel.letsmeet.mappers.Mapper;
import be.naaturel.letsmeet.core.models.EventDate;
import be.naaturel.letsmeet.core.models.Participant;
import java.util.Collection;
import java.util.HashSet;
import java.util.function.Supplier;
public class ParticipantMapper implements Mapper<Participant, ParticipantEntity> {
private final Mapper<EventDate, EventDateEntity> dateMapper;
public ParticipantMapper(){
dateMapper = new EventDateMapper();
}
@Override
public ParticipantEntity toEntity(Participant d) {
return DatabasePropsFactory.createParticipant(d.getName(), dateMapper.toEntities(d.getDates(), HashSet::new));
}
@Override
public Participant toModel(ParticipantEntity d) {
return new Participant(d.name, dateMapper.toModels(d.dates, HashSet::new));
}
@Override
public <C extends Collection<ParticipantEntity>> C toEntities(Collection<Participant> participants, Supplier<C> collectionSupplier) {
C result = collectionSupplier.get();
participants.forEach(p -> result.add(toEntity(p)));
return result;
}
@Override
public <C extends Collection<Participant>> C toModels(Collection<ParticipantEntity> participants, Supplier<C> collectionSupplier) {
C result = collectionSupplier.get();
participants.forEach(p -> result.add(toModel(p)));
return result;
}
}

View File

@@ -0,0 +1,47 @@
package be.naaturel.letsmeet.mappers.requests;
import be.naaturel.letsmeet.dto.httpRequest.EventDateDTO;
import be.naaturel.letsmeet.dto.httpRequest.AttendeeDTO;
import be.naaturel.letsmeet.mappers.Mapper;
import be.naaturel.letsmeet.core.models.EventDate;
import be.naaturel.letsmeet.core.models.Attendee;
import java.util.Collection;
import java.util.HashSet;
import java.util.function.Supplier;
public class AttendeeDTOMapper implements Mapper<Attendee, AttendeeDTO> {
private final Mapper<EventDate, EventDateDTO> dateMapper;
public AttendeeDTOMapper(){
this.dateMapper = new EventDateDTOMapper();
}
@Override
public AttendeeDTO toEntity(Attendee d) {
AttendeeDTO dto = new AttendeeDTO();
dto.name = d.getName();
dto.dates = dateMapper.toEntities(d.getDates(), HashSet::new);
return dto;
}
@Override
public Attendee toModel(AttendeeDTO d) {
return new Attendee(d.name, dateMapper.toModels(d.dates, HashSet::new));
}
@Override
public <C extends Collection<AttendeeDTO>> C toEntities(Collection<Attendee> attendees, Supplier<C> collectionSupplier) {
C result = collectionSupplier.get();
attendees.forEach(p -> result.add(toEntity(p)));
return result;
}
@Override
public <C extends Collection<Attendee>> C toModels(Collection<AttendeeDTO> attendeeDTOS, Supplier<C> collectionSupplier) {
C result = collectionSupplier.get();
attendeeDTOS.forEach(p -> result.add(toModel(p)));
return result;
}
}

View File

@@ -1,10 +1,10 @@
package be.naaturel.letsmeet.mappers.requests;
import be.naaturel.letsmeet.dto.httpRequest.EventDTO;
import be.naaturel.letsmeet.dto.httpRequest.ParticipantDTO;
import be.naaturel.letsmeet.dto.httpRequest.AttendeeDTO;
import be.naaturel.letsmeet.mappers.Mapper;
import be.naaturel.letsmeet.core.models.Event;
import be.naaturel.letsmeet.core.models.Participant;
import be.naaturel.letsmeet.core.models.Attendee;
import java.util.Collection;
import java.util.HashSet;
@@ -12,19 +12,19 @@ import java.util.function.Supplier;
public class EventDTOMapper implements Mapper<Event, EventDTO> {
private final Mapper<Participant, ParticipantDTO> participantMapper = new ParticipantDTOMapper();
private final Mapper<Attendee, AttendeeDTO> attendeeMapper = new AttendeeDTOMapper();
@Override
public EventDTO toEntity(Event event) {
EventDTO eventDTO = new EventDTO();
eventDTO.name = event.getName();
eventDTO.participants = participantMapper.toEntities(event.getParticipants(), HashSet::new);
eventDTO.attendees = attendeeMapper.toEntities(event.getAttendees(), HashSet::new);
return eventDTO;
}
@Override
public Event toModel(EventDTO dto) {
return new Event(dto.name, participantMapper.toModels(dto.participants, HashSet::new));
return new Event(dto.name, attendeeMapper.toModels(dto.attendees, HashSet::new));
}
@Override

View File

@@ -1,47 +0,0 @@
package be.naaturel.letsmeet.mappers.requests;
import be.naaturel.letsmeet.dto.httpRequest.EventDateDTO;
import be.naaturel.letsmeet.dto.httpRequest.ParticipantDTO;
import be.naaturel.letsmeet.mappers.Mapper;
import be.naaturel.letsmeet.core.models.EventDate;
import be.naaturel.letsmeet.core.models.Participant;
import java.util.Collection;
import java.util.HashSet;
import java.util.function.Supplier;
public class ParticipantDTOMapper implements Mapper<Participant, ParticipantDTO> {
private final Mapper<EventDate, EventDateDTO> dateMapper;
public ParticipantDTOMapper(){
this.dateMapper = new EventDateDTOMapper();
}
@Override
public ParticipantDTO toEntity(Participant d) {
ParticipantDTO dto = new ParticipantDTO();
dto.name = d.getName();
dto.dates = dateMapper.toEntities(d.getDates(), HashSet::new);
return dto;
}
@Override
public Participant toModel(ParticipantDTO d) {
return new Participant(d.name, dateMapper.toModels(d.dates, HashSet::new));
}
@Override
public <C extends Collection<ParticipantDTO>> C toEntities(Collection<Participant> participants, Supplier<C> collectionSupplier) {
C result = collectionSupplier.get();
participants.forEach(p -> result.add(toEntity(p)));
return result;
}
@Override
public <C extends Collection<Participant>> C toModels(Collection<ParticipantDTO> participantDTOS, Supplier<C> collectionSupplier) {
C result = collectionSupplier.get();
participantDTOS.forEach(p -> result.add(toModel(p)));
return result;
}
}

View File

@@ -1,6 +1,6 @@
import type {TimeStampDto} from "@/dto/TimeStampDto.ts";
export class ParticipantDto {
export class AttendeeDto {
public name: string;
public dates: TimeStampDto[];

View File

@@ -1,17 +1,17 @@
import type {Participant} from "@/models/Participant.ts";
import type {Attendee} from "@/models/Attendee.ts";
import type {TimeStamp} from "@/models/TimeStamp.ts";
import type {ParticipantDto} from "@/dto/ParticipantDto.ts";
import type {AttendeeDto} from "@/dto/AttendeeDto.ts";
export class EventDto {
public name: string;
public token: string;
public participants: ParticipantDto[];
public attendees: AttendeeDto[];
public constructor(name: string, token: string, participants: ParticipantDto[]) {
public constructor(name: string, token: string, attendees: AttendeeDto[]) {
this.name = name;
this.token = token;
this.participants = participants;
this.attendees = attendees;
}
}

View File

@@ -1,6 +1,6 @@
import type {TimeStamp, TimeStampState} from "@/models/TimeStamp.ts";
export class Participant {
export class Attendee {
private name: string;
private dates: TimeStamp[];
@@ -19,7 +19,7 @@ export class Participant {
}
}
export interface ParticipantState {
export interface AttendeeState {
name : String
dates : TimeStampState[]
}

View File

@@ -1,16 +1,15 @@
import type {Participant, ParticipantState} from "@/models/Participant.ts";
import type {TimeStampState} from "@/models/TimeStamp.ts";
import type {Attendee, AttendeeState} from "@/models/Attendee.ts";
export class Event {
private name: string;
private token: string;
private participants: Participant[];
private attendees: Attendee[];
public constructor(name: string, token: string, participants: Participant[]) {
public constructor(name: string, token: string, attendees: Attendee[]) {
this.name = name;
this.token = token;
this.participants = participants;
this.attendees = attendees;
}
public getName() : string {
@@ -21,8 +20,8 @@ export class Event {
return this.token;
}
public getParticipants() : Participant[] {
return this.participants;
public getAttendees() : Attendee[] {
return this.attendees;
}
}
@@ -30,6 +29,6 @@ export class Event {
export interface EventState {
name : String
token : String
participants: ParticipantState[];
attendees: AttendeeState[];
}

View File

@@ -24,7 +24,7 @@ export class EventRequests {
let url = this.formatUrl([this.baseUrl, this.endpoints.EVENTS, token]);
return fetch(url)
.then(response => response.json())
.then(data => new EventDto(data.name, data.token, data.participants))
.then(data => new EventDto(data.name, data.token, data.attendees))
.catch(error => console.error(error));
}
}

View File

@@ -2,8 +2,8 @@ import {defineStore} from 'pinia'
import {EventRequests} from "@/requests/EventRequests.ts";
import type {EventDto} from "@/dto/EventDto.ts";
import type {EventState} from "@/models/Event.ts";
import type {ParticipantDto} from "@/dto/ParticipantDto.ts";
import type {ParticipantState} from "@/models/Participant.ts";
import type {AttendeeDto} from "@/dto/AttendeeDto.ts";
import type {AttendeeState} from "@/models/Attendee.ts";
import type {TimeStamp, TimeStampState} from "@/models/TimeStamp.ts";
import type {TimeStampDto} from "@/dto/TimeStampDto.ts";
@@ -15,7 +15,7 @@ export const eventStore = defineStore('eventStore', {
event : {
name: "",
token: "",
participants: [] as ParticipantState[]
attendees: [] as AttendeeState[]
}};
},
getters : {
@@ -30,7 +30,7 @@ export const eventStore = defineStore('eventStore', {
this.event.name = data.name;
this.event.token = data.token;
this.event.participants = data.participants.map((p: ParticipantDto) => ({
this.event.attendees = data.attendees.map((p: AttendeeDto) => ({
name: p.name,
dates: p.dates.map((date: TimeStampDto) => ({
value: date.timestamp

View File

@@ -16,16 +16,25 @@ function extractToken() : string {
return Array.isArray(route.params.token) ? route.params.token[0] : route.params.token;
}
function attendeesByDates(){
}
function formatDate(timestamp : number) : String{
let date = DateHelper.toDate(timestamp)
return `${date.getDate()}-${date.getMonth() + 1}-${date.getFullYear()}`;
}
</script>
<template>
Name : {{ store.event.name }}
Participants :
<div v-for="(p) in store.event.participants" >
Name : {{ store.event.name }} <br>
attendees :
<div v-for="(p) in store.event.attendees" >
{{ p.name }}
<div v-for="(d) in p.dates">
{{ DateHelper.toDate(d.value) }}
{{ formatDate(d.value) }}
</div>
</div>
</template>