Mon premier commit
This commit is contained in:
123
src/main/java/com/lions/dev/entity/Events.java
Normal file
123
src/main/java/com/lions/dev/entity/Events.java
Normal file
@@ -0,0 +1,123 @@
|
||||
package com.lions.dev.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "Events")
|
||||
public class Events extends BaseEntity {
|
||||
|
||||
@NotNull
|
||||
@Size(max = 100)
|
||||
@Column(name = "title", nullable = false, length = 100)
|
||||
@JsonProperty("title")
|
||||
private String title;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 255)
|
||||
@Column(name = "description", nullable = false, length = 255)
|
||||
@JsonProperty("description")
|
||||
private String description;
|
||||
|
||||
@NotNull
|
||||
@Column(name = "event_date", nullable = false)
|
||||
@JsonProperty("date")
|
||||
private LocalDateTime eventDate;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 100)
|
||||
@Column(name = "location", nullable = false, length = 100)
|
||||
@JsonProperty("location")
|
||||
private String location;
|
||||
|
||||
@Size(max = 100)
|
||||
@Column(name = "category", length = 100)
|
||||
@JsonProperty("category")
|
||||
private String category;
|
||||
|
||||
@Column(name = "link", length = 255)
|
||||
@JsonProperty("link")
|
||||
private String link;
|
||||
|
||||
@Column(name = "image_url", length = 255)
|
||||
@JsonProperty("imageUrl")
|
||||
private String imageUrl;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "creator_id")
|
||||
@JsonProperty("creator")
|
||||
private Users creator;
|
||||
|
||||
@ManyToMany(mappedBy = "participatedEvents", fetch = FetchType.LAZY)
|
||||
@JsonIgnore
|
||||
private Set<Users> participants = new HashSet<>();
|
||||
|
||||
// Méthode pour ajouter un participant
|
||||
public void addParticipant(Users user) {
|
||||
if (participants == null) {
|
||||
participants = new HashSet<>();
|
||||
}
|
||||
if (!participants.contains(user)) {
|
||||
participants.add(user);
|
||||
user.getParticipatedEvents().add(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Méthode pour retirer un participant
|
||||
public void removeParticipant(Users user) {
|
||||
if (participants != null && participants.contains(user)) {
|
||||
participants.remove(user);
|
||||
user.getParticipatedEvents().remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Si vous avez une fonctionnalité de "like", vous pouvez ajouter une collection et des méthodes similaires
|
||||
@ManyToMany(fetch = FetchType.LAZY)
|
||||
@JoinTable(
|
||||
name = "event_likes",
|
||||
joinColumns = @JoinColumn(name = "event_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "user_id")
|
||||
)
|
||||
@JsonIgnore
|
||||
private Set<Users> likes = new HashSet<>();
|
||||
|
||||
public void addLike(Users user) {
|
||||
if (likes == null) {
|
||||
likes = new HashSet<>();
|
||||
}
|
||||
likes.add(user);
|
||||
}
|
||||
|
||||
public void removeLike(Users user) {
|
||||
if (likes != null) {
|
||||
likes.remove(user);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Events{" +
|
||||
"id=" + getId() +
|
||||
", title='" + title + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
", eventDate=" + eventDate +
|
||||
", location='" + location + '\'' +
|
||||
", category='" + category + '\'' +
|
||||
", link='" + link + '\'' +
|
||||
", imageUrl='" + imageUrl + '\'' +
|
||||
", creator=" + (creator != null ? creator.getId() : null) +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user