From 305ddb61124e26336d266784c12a7a58806d6670 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melaine=20G=C3=A9rard?= Date: Wed, 20 Nov 2024 22:39:15 +0100 Subject: [PATCH] =?UTF-8?q?:sparkles:=20Ajout=20des=20entit=C3=A9s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../studio/gachamelia/models/Element.java | 43 +++++++++++++++ .../studio/gachamelia/models/Role.java | 55 +++++++++++++++++++ .../studio/gachamelia/models/Stat.java | 34 ++++++++++++ .../studio/gachamelia/models/User.java | 13 +++++ 4 files changed, 145 insertions(+) create mode 100644 src/main/java/org/camelia/studio/gachamelia/models/Element.java create mode 100644 src/main/java/org/camelia/studio/gachamelia/models/Role.java create mode 100644 src/main/java/org/camelia/studio/gachamelia/models/Stat.java diff --git a/src/main/java/org/camelia/studio/gachamelia/models/Element.java b/src/main/java/org/camelia/studio/gachamelia/models/Element.java new file mode 100644 index 0000000..3a9c774 --- /dev/null +++ b/src/main/java/org/camelia/studio/gachamelia/models/Element.java @@ -0,0 +1,43 @@ +package org.camelia.studio.gachamelia.models; + +import jakarta.persistence.*; +import org.camelia.studio.gachamelia.interfaces.IEntity; + +import java.util.List; + +@Entity +@Table(name = "elements") +public class Element implements IEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String name; + + @OneToMany(mappedBy = "element") + private List users; + + public Long getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getUsers() { + return users; + } + + public Element() { + } + + public Element(String name) { + this.name = name; + } +} diff --git a/src/main/java/org/camelia/studio/gachamelia/models/Role.java b/src/main/java/org/camelia/studio/gachamelia/models/Role.java new file mode 100644 index 0000000..263fa87 --- /dev/null +++ b/src/main/java/org/camelia/studio/gachamelia/models/Role.java @@ -0,0 +1,55 @@ +package org.camelia.studio.gachamelia.models; + +import jakarta.persistence.*; +import org.camelia.studio.gachamelia.interfaces.IEntity; + +import java.util.List; + +@Entity +@Table(name = "roles") +public class Role implements IEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String name; + + @Column(nullable = false) + private int percentage; + + @OneToMany(mappedBy = "role") + private List users; + + public List getUsers() { + return users; + } + + public Long getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getPercentage() { + return percentage; + } + + public void setPercentage(int percentage) { + this.percentage = percentage; + } + + public Role() { + } + + public Role(String name, int percentage) { + this.name = name; + this.percentage = percentage; + } +} diff --git a/src/main/java/org/camelia/studio/gachamelia/models/Stat.java b/src/main/java/org/camelia/studio/gachamelia/models/Stat.java new file mode 100644 index 0000000..9bcbdd6 --- /dev/null +++ b/src/main/java/org/camelia/studio/gachamelia/models/Stat.java @@ -0,0 +1,34 @@ +package org.camelia.studio.gachamelia.models; + +import jakarta.persistence.*; +import org.camelia.studio.gachamelia.interfaces.IEntity; + +@Entity +@Table(name = "stats") +public class Stat implements IEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false) + private String name; + + public Long getId() { + return id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Stat() { + } + + public Stat(String name) { + this.name = name; + } +} diff --git a/src/main/java/org/camelia/studio/gachamelia/models/User.java b/src/main/java/org/camelia/studio/gachamelia/models/User.java index d0c769d..2251486 100644 --- a/src/main/java/org/camelia/studio/gachamelia/models/User.java +++ b/src/main/java/org/camelia/studio/gachamelia/models/User.java @@ -28,6 +28,19 @@ public class User implements IEntity { @Column(name = "updatedAt") private LocalDateTime updatedAt; + @ManyToOne(fetch = FetchType.EAGER) + private Element element; + + @ManyToOne(fetch = FetchType.EAGER) + private Role role; + + public Element getElement() { + return element; + } + + public Role getRole() { + return role; + } public User() { }