feat: fin de petite session au calme tkt, kestufou à lire mes messages batard ?

Co-authored-by: Damien <damguillotin@gmail.com>
Co-authored-by: pejour <pejour@users.noreply.github.com>
Co-authored-by: Tom Heurtebise <theurt@users.noreply.github.com>
This commit is contained in:
Laureηt 2022-04-14 09:53:29 +02:00
parent 8a7fdc8ae9
commit 733d77d7bd
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
10 changed files with 758 additions and 3 deletions

View file

@ -21,10 +21,10 @@ dependencies {
compileOnly 'javax:javaee-api:8.0.1' compileOnly 'javax:javaee-api:8.0.1'
// Pour pouvoir parser le JSON // Pour pouvoir parser le JSON
// implementation 'com.google.code.gson:gson:2.8.6' implementation 'com.google.code.gson:gson:2.8.6'
// implementation 'org.hibernate:hibernate-core:5.4.30.Final' implementation 'org.hibernate:hibernate-core:5.4.30.Final'
// implementation 'mysql:mysql-connector-java:8.0.24' implementation 'mysql:mysql-connector-java:8.0.24'
// Pour les tests // Pour les tests
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'

View file

@ -10,6 +10,7 @@ import javax.servlet.http.HttpServletResponse;
@WebServlet(name = "HelloServlet", urlPatterns = { "hello" }, loadOnStartup = 1) @WebServlet(name = "HelloServlet", urlPatterns = { "hello" }, loadOnStartup = 1)
public class HelloServlet extends HttpServlet { public class HelloServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { throws ServletException, IOException {
response.getWriter().print("Hello, World!"); response.getWriter().print("Hello, World!");

View file

@ -0,0 +1,93 @@
package com.pixels.beans;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;
@Entity
@NamedQuery(name = "Group.list", query = "SELECT g FROM Group")
public class Group implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // clé primaire
private String name; // le nom du groupe
@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() + "'" +
"}";
}
}

View file

@ -0,0 +1,67 @@
package com.pixels.beans;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;
@Entity
@NamedQuery(name = "Permission.list", query = "SELECT pe FROM Permission pe")
public class Permission implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // clé primaire du code
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() + "'" +
"}";
}
}

View file

@ -0,0 +1,130 @@
package com.pixels.beans;
import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
@Entity
@NamedQuery(name = "Pixel.list", query = "SELECT p FROM Pixel p order by p.dateTime desc")
public class Pixel implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // clé primaire du code
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
@ManyToOne(fetch = FetchType.EAGER)
private User owner;
@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 id.equals(pixel.id) && price == pixel.price && color == pixel.color
&& description.equals(pixel.description) && owner.equals(pixel.owner);
}
@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

@ -0,0 +1,67 @@
package com.pixels.beans;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;
@Entity
@NamedQuery(name = "Role.list", query = "SELECT r FROM Role r")
public class Role implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // clé primaire du code
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() + "'" +
"}";
}
}

View file

@ -0,0 +1,146 @@
package com.pixels.beans;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
@Entity
@NamedQuery(name = "Transaction.list", query = "SELECT t FROM Transaction t order by t.dateTime desc") // TO DO :
// Vérifier
public class Transaction implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // clé primaire
private int price;
private int color; // couleur du pixel sur la peinture
private Date time;
@ManyToOne
private Wallet wallet;
@ManyToOne
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

@ -0,0 +1,130 @@
package com.pixels.beans;
import javax.persistence.*;
import com.pixels.utils.Hash;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
@Entity
@NamedQuery(name = "User.list", query = "SELECT u FROM User u")
public class User implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // clé primaire du code
private String userName;
private String email;
private String hashPassword; // sha256
@OneToOne
private Wallet wallet;
@ManyToOne
private Permission permission;
@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

@ -0,0 +1,96 @@
package com.pixels.beans;
import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
@Entity
@NamedQuery(name = "Wallet.list", query = "SELECT w FROM Wallet w")
public class Wallet implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id; // clé primaire du code
private int balance;
@OneToMany(mappedBy = "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() + "'" +
"}";
}
}

View file

@ -0,0 +1,25 @@
package com.pixels.utils;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Hash {
public static String sha256(String password) {
String hash = "";
byte[] hashBytes;
try {
hashBytes = MessageDigest.getInstance("SHA-256")
.digest(password.getBytes(StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
for (byte b : hashBytes) {
sb.append(String.format("%02X", b));
}
hash = sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return hash;
}
}