feat: utilisation de lombok

This commit is contained in:
Laureηt 2022-04-21 09:25:39 +02:00
parent 7358efe1d0
commit e088a54fd2
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
8 changed files with 88 additions and 605 deletions

View file

@ -32,6 +32,13 @@ dependencies {
// Pour les tests
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
// pour des getters/setters auto
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
testCompileOnly 'org.projectlombok:lombok:1.18.24'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.24'
}
test {

View file

@ -1,93 +1,24 @@
package com.pixels.beans;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;
import lombok.Data;
import java.io.Serializable;
@Data
@Entity
@NamedQuery(name = "Group.list", query = "SELECT g FROM Group")
public class Group implements Serializable {
@Id
@Id // clé primaire
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // clé primaire
private Long id;
private String name; // le nom du groupe
// nom du groupe
private String name;
@OneToOne
private Wallet wallet; // le wallet commun à tous les membres du groupe
public Group() {
}
public Group(Long id, String name, Wallet wallet) {
this.id = id;
this.name = name;
this.wallet = wallet;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Wallet getWallet() {
return this.wallet;
}
public void setWallet(Wallet wallet) {
this.wallet = wallet;
}
public Group id(Long id) {
setId(id);
return this;
}
public Group name(String name) {
setName(name);
return this;
}
public Group wallet(Wallet wallet) {
setWallet(wallet);
return this;
}
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Group)) {
return false;
}
Group group = (Group) o;
return Objects.equals(id, group.id) && Objects.equals(name, group.name) && Objects.equals(wallet, group.wallet);
}
@Override
public int hashCode() {
return Objects.hash(id, name, wallet);
}
@Override
public String toString() {
return "{" +
" id='" + getId() + "'" +
", name='" + getName() + "'" +
", wallet='" + getWallet() + "'" +
"}";
}
@OneToOne // le wallet commun à tous les membres du groupe
private Wallet wallet;
}

View file

@ -2,66 +2,19 @@ package com.pixels.beans;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;
import lombok.Data;
import java.io.Serializable;
@Data
@Entity
@NamedQuery(name = "Permission.list", query = "SELECT pe FROM Permission pe")
public class Permission implements Serializable {
@Id
@Id // clé primaire
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // clé primaire du code
private Long id;
private int type; // type de la permission
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public int getType() {
return this.type;
}
public void setType(int type) {
this.type = type;
}
public Permission id(Long id) {
setId(id);
return this;
}
public Permission type(int type) {
setType(type);
return this;
}
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Permission)) {
return false;
}
Permission permission = (Permission) o;
return Objects.equals(id, permission.id) && type == permission.type;
}
@Override
public int hashCode() {
return Objects.hash(id, type);
}
@Override
public String toString() {
return "{" +
" id='" + getId() + "'" +
", balance='" + getType() + "'" +
"}";
}
// type de la permission
private int type;
}

View file

@ -1,131 +1,35 @@
package com.pixels.beans;
import javax.persistence.*;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
@Data
@Entity
@NamedQuery(name = "Pixel.list", query = "SELECT p FROM Pixel p order by p.dateTime desc")
public class Pixel implements Serializable {
@Id
@Id // clé primaire
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // clé primaire du code
private Long id;
private int price; // prix du pixel à l'achat
private int color; // couleur du pixel sur la peinture
private String description; // petit mot écrit par le user
// prix du pixel à l'achat
private int price;
// couleur du pixel sur la peinture
private int color;
// petit mot écrit par le user
private String description;
// propriétaire actuel du pixel
@ManyToOne(fetch = FetchType.EAGER)
private User owner;
// liste des transactions associées au pixel
@OneToMany(mappedBy = "pixel")
private List<Transaction> transactions;
public Pixel() {
}
public Pixel(Long id, int price, int color, String description, User owner) {
this.id = id;
this.price = price;
this.color = color;
this.description = description;
this.owner = owner;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public int getPrice() {
return this.price;
}
public void setPrice(int price) {
this.price = price;
}
public int getColor() {
return this.color;
}
public void setColor(int color) {
this.color = color;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public User getOwner() {
return this.owner;
}
public void setOwner(User owner) {
this.owner = owner;
}
public Pixel id(Long id) {
setId(id);
return this;
}
public Pixel price(int price) {
setPrice(price);
return this;
}
public Pixel color(int color) {
setColor(color);
return this;
}
public Pixel description(String description) {
setDescription(description);
return this;
}
public Pixel owner(User owner) {
setOwner(owner);
return this;
}
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Pixel)) {
return false;
}
Pixel pixel = (Pixel) o;
return Objects.equals(id, pixel.id) && price == pixel.price && color == pixel.color
&& Objects.equals(description, pixel.description) && Objects.equals(owner, pixel.owner)
&& Objects.equals(transactions, pixel.transactions);
}
@Override
public int hashCode() {
return Objects.hash(id, price, color, description, owner);
}
@Override
public String toString() {
return "{" +
" id='" + getId() + "'" +
", price='" + getPrice() + "'" +
", color='" + getColor() + "'" +
", description='" + getDescription() + "'" +
", owner='" + getOwner() + "'" +
"}";
}
}

View file

@ -2,66 +2,19 @@ package com.pixels.beans;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;
import lombok.Data;
import java.io.Serializable;
@Data
@Entity
@NamedQuery(name = "Role.list", query = "SELECT r FROM Role r")
public class Role implements Serializable {
@Id
@Id // clé primaire du code
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // clé primaire du code
private Long id;
private int type; // type du role
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public int getType() {
return this.type;
}
public void setType(int type) {
this.type = type;
}
public Role id(Long id) {
setId(id);
return this;
}
public Role type(int type) {
setType(type);
return this;
}
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Role)) {
return false;
}
Role role = (Role) o;
return Objects.equals(id, role.id) && type == role.type;
}
@Override
public int hashCode() {
return Objects.hash(id, type);
}
@Override
public String toString() {
return "{" +
" id='" + getId() + "'" +
", balance='" + getType() + "'" +
"}";
}
// type du role
private int type;
}

View file

@ -1,146 +1,33 @@
package com.pixels.beans;
import javax.persistence.*;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
@Data
@Entity
@NamedQuery(name = "Transaction.list", query = "SELECT t FROM Transaction t order by t.dateTime desc") // TO DO :
// Vérifier
@NamedQuery(name = "Transaction.list", query = "SELECT t FROM Transaction t order by t.dateTime desc")
public class Transaction implements Serializable {
@Id
@Id // clé primaire
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // clé primaire
private Long id;
// prix de la transaction
private int price;
private int color; // couleur du pixel sur la peinture
// couleur du pixel de la transaction
private int color;
// date de la transaction
private Date time;
@ManyToOne
@ManyToOne // wallet acheteur
private Wallet wallet;
@ManyToOne
@ManyToOne // pixel acheté
private Pixel pixel;
public Transaction() {
}
public Transaction(Long id, int price, int color, Date time, Wallet wallet, Pixel pixel) {
this.id = id;
this.price = price;
this.color = color;
this.time = time;
this.wallet = wallet;
this.pixel = pixel;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public int getPrice() {
return this.price;
}
public void setPrice(int price) {
this.price = price;
}
public int getColor() {
return this.color;
}
public void setColor(int color) {
this.color = color;
}
public Date getTime() {
return this.time;
}
public void setTime(Date time) {
this.time = time;
}
public Wallet getWallet() {
return this.wallet;
}
public void setWallet(Wallet wallet) {
this.wallet = wallet;
}
public Pixel getPixel() {
return this.pixel;
}
public void setPixel(Pixel pixel) {
this.pixel = pixel;
}
public Transaction id(Long id) {
setId(id);
return this;
}
public Transaction price(int price) {
setPrice(price);
return this;
}
public Transaction color(int color) {
setColor(color);
return this;
}
public Transaction time(Date time) {
setTime(time);
return this;
}
public Transaction wallet(Wallet wallet) {
setWallet(wallet);
return this;
}
public Transaction pixel(Pixel pixel) {
setPixel(pixel);
return this;
}
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Transaction)) {
return false;
}
Transaction transaction = (Transaction) o;
return Objects.equals(id, transaction.id) && price == transaction.price && color == transaction.color
&& Objects.equals(time, transaction.time) && Objects.equals(wallet, transaction.wallet)
&& Objects.equals(pixel, transaction.pixel);
}
@Override
public int hashCode() {
return Objects.hash(id, price, color, time, wallet, pixel);
}
@Override
public String toString() {
return "{" +
" id='" + getId() + "'" +
", price='" + getPrice() + "'" +
", color='" + getColor() + "'" +
", time='" + getTime() + "'" +
", wallet='" + getWallet() + "'" +
", pixel='" + getPixel() + "'" +
"}";
}
}

View file

@ -4,127 +4,47 @@ import javax.persistence.*;
import com.pixels.utils.Hash;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
@Data
@Entity
@NamedQuery(name = "User.list", query = "SELECT u FROM User u")
public class User implements Serializable {
@Id
@Id // clé primaire
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // clé primaire du code
private Long id;
// nom d'utilisateur
private String userName;
private String email;
private String hashPassword; // sha256
@OneToOne
// addresse mail de l'utilisateur
private String email;
// mot de passe hashé en sha256
private String hashPassword;
@OneToOne // portefeuille
private Wallet wallet;
@ManyToOne
@ManyToOne // permission
private Permission permission;
// pixels possédés
@OneToMany(mappedBy = "owner")
private List<Pixel> owned;
public User() {
}
public User(Long id, String userName, String email, String password) {
this.id = id;
this.userName = userName;
this.email = email;
this.hashPassword = Hash.sha256(password);
;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getUserName() {
return this.userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public Wallet getWallet() {
return this.wallet;
}
public void setWallet(Wallet wallet) {
this.wallet = wallet;
}
public String getHashPassword() {
return this.hashPassword;
}
public void setHashPassword(String password) {
this.hashPassword = Hash.sha256(password);
}
public User id(Long id) {
setId(id);
return this;
}
public User userName(String userName) {
setUserName(userName);
return this;
}
public User email(String email) {
setEmail(email);
return this;
}
public User hashPassword(String hashPassword) {
setHashPassword(hashPassword);
return this;
}
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof User)) {
return false;
}
User user = (User) o;
return Objects.equals(id, user.id) && Objects.equals(userName, user.userName)
&& Objects.equals(email, user.email) && Objects.equals(hashPassword, user.hashPassword);
}
@Override
public int hashCode() {
return Objects.hash(id, userName, email, hashPassword);
}
@Override
public String toString() {
return "{" +
" id='" + getId() + "'" +
", userName='" + getUserName() + "'" +
", email='" + getEmail() + "'" +
", hashPassword='" + getHashPassword() + "'" +
"}";
}
}

View file

@ -2,95 +2,23 @@ package com.pixels.beans;
import javax.persistence.*;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
@Data
@Entity
@NamedQuery(name = "Wallet.list", query = "SELECT w FROM Wallet w")
public class Wallet implements Serializable {
@Id
@Id // clé primaire du code
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // clé primaire du code
private Long id;
// solde du wallet
private int balance;
@OneToMany(mappedBy = "wallet")
@OneToMany(mappedBy = "wallet") // transactions associées au wallet
private List<Transaction> transactions;
public Wallet() {
}
public Wallet(Long id, int balance, List<Transaction> transactions) {
this.id = id;
this.balance = balance;
this.transactions = transactions;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public int getBalance() {
return this.balance;
}
public void setBalance(int balance) {
this.balance = balance;
}
public List<Transaction> getTransactions() {
return this.transactions;
}
public void setTransactions(List<Transaction> transactions) {
this.transactions = transactions;
}
public Wallet id(Long id) {
setId(id);
return this;
}
public Wallet balance(int balance) {
setBalance(balance);
return this;
}
public Wallet transactions(List<Transaction> transactions) {
setTransactions(transactions);
return this;
}
@Override
public boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof Wallet)) {
return false;
}
Wallet wallet = (Wallet) o;
return Objects.equals(id, wallet.id) && balance == wallet.balance
&& Objects.equals(transactions, wallet.transactions);
}
@Override
public int hashCode() {
return Objects.hash(id, balance, transactions);
}
@Override
public String toString() {
return "{" +
" id='" + getId() + "'" +
", balance='" + getBalance() + "'" +
", transactions='" + getTransactions() + "'" +
"}";
}
}