Oui oui baguette
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -2,7 +2,7 @@ package be.naaturel.letsmeet.dto.httpRequest;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class ParticipantDTO {
|
||||
public class AttendeeDTO {
|
||||
|
||||
public String name;
|
||||
|
||||
@@ -5,6 +5,6 @@ import java.util.Set;
|
||||
public class EventDTO {
|
||||
|
||||
public String name;
|
||||
public Set<ParticipantDTO> participants;
|
||||
public Set<AttendeeDTO> attendees;
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user