Mon premier commit
This commit is contained in:
44
src/main/java/com/lions/dev/entity/BaseEntity.java
Normal file
44
src/main/java/com/lions/dev/entity/BaseEntity.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package com.lions.dev.entity;
|
||||
|
||||
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
|
||||
import jakarta.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.UuidGenerator;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@MappedSuperclass
|
||||
public abstract class BaseEntity extends PanacheEntityBase {
|
||||
|
||||
@Id
|
||||
@UuidGenerator
|
||||
@Column(name = "id", updatable = false, nullable = false)
|
||||
private UUID id;
|
||||
|
||||
@Column(name = "created_at", updatable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Column(name = "updated_at")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Column(name = "created_by")
|
||||
private String createdBy;
|
||||
|
||||
@Column(name = "updated_by")
|
||||
private String updatedBy;
|
||||
|
||||
@PrePersist
|
||||
protected void onCreate() {
|
||||
this.createdAt = LocalDateTime.now();
|
||||
// Logique pour définir `createdBy` à partir du contexte utilisateur
|
||||
}
|
||||
|
||||
@PreUpdate
|
||||
protected void onUpdate() {
|
||||
this.updatedAt = LocalDateTime.now();
|
||||
// Logique pour définir `updatedBy` à partir du contexte utilisateur
|
||||
}
|
||||
}
|
||||
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) +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
104
src/main/java/com/lions/dev/entity/Users.java
Normal file
104
src/main/java/com/lions/dev/entity/Users.java
Normal file
@@ -0,0 +1,104 @@
|
||||
package com.lions.dev.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.Email;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "Users")
|
||||
public class Users extends BaseEntity {
|
||||
|
||||
@NotNull
|
||||
@Size(max = 100)
|
||||
@Column(name = "nom", nullable = false, length = 100)
|
||||
@JsonProperty("nom")
|
||||
private String nom;
|
||||
|
||||
@NotNull
|
||||
@Size(max = 100)
|
||||
@Column(name = "prenoms", nullable = false, length = 100)
|
||||
@JsonProperty("prenoms")
|
||||
private String prenoms;
|
||||
|
||||
@NotNull
|
||||
@Email
|
||||
@Size(max = 100)
|
||||
@Column(name = "email", nullable = false, length = 100, unique = true)
|
||||
@JsonProperty("email")
|
||||
private String email;
|
||||
|
||||
@NotNull
|
||||
@Size(min = 8, max = 255)
|
||||
@Column(name = "mot_de_passe", nullable = false, length = 255)
|
||||
@JsonProperty(access = JsonProperty.Access.READ_WRITE)
|
||||
private String motDePasse;
|
||||
|
||||
@Size(max = 50)
|
||||
@Column(name = "role", nullable = false, length = 50)
|
||||
@JsonProperty("role")
|
||||
private String role;
|
||||
|
||||
@OneToMany(mappedBy = "creator", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
@JsonIgnore
|
||||
private List<Events> createdEvents;
|
||||
|
||||
@ManyToMany(fetch = FetchType.LAZY)
|
||||
@JoinTable(
|
||||
name = "User_Event_Participation",
|
||||
joinColumns = @JoinColumn(name = "user_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "event_id")
|
||||
)
|
||||
@JsonIgnore
|
||||
private List<Events> participatedEvents;
|
||||
|
||||
// Méthode pour définir un mot de passe haché avec SHA-256
|
||||
public void setMotDePasse(String motDePasse) {
|
||||
this.motDePasse = hashPasswordSHA256(motDePasse);
|
||||
}
|
||||
|
||||
// Hachage du mot de passe avec SHA-256
|
||||
private String hashPasswordSHA256(String motDePasse) {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
byte[] encodedhash = digest.digest(motDePasse.getBytes(StandardCharsets.UTF_8));
|
||||
return bytesToHex(encodedhash);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private String bytesToHex(byte[] hash) {
|
||||
StringBuilder hexString = new StringBuilder(2 * hash.length);
|
||||
for (byte b : hash) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Users{" +
|
||||
"id=" + getId() +
|
||||
", nom='" + nom + '\'' +
|
||||
", prenoms='" + prenoms + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", role='" + role + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user