From 575646ead2936edb1d658f0e7aa9122a7bf1565c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Fri, 20 May 2022 11:37:54 +0200 Subject: [PATCH] feat: using hexstring for colors --- docker/mariadb-init/pixels.sql | 212 +++++++++--------- src/main/java/com/pixels/beans/Pixel.java | 23 +- .../java/com/pixels/beans/Transaction.java | 14 +- src/main/java/com/pixels/beans/User.java | 14 +- 4 files changed, 117 insertions(+), 146 deletions(-) diff --git a/docker/mariadb-init/pixels.sql b/docker/mariadb-init/pixels.sql index 496535e..c7b1a2b 100644 --- a/docker/mariadb-init/pixels.sql +++ b/docker/mariadb-init/pixels.sql @@ -1,107 +1,107 @@ CREATE TABLE Pixel ( - id bigint(20) NOT NULL AUTO_INCREMENT, - price int(11) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB; - -INSERT INTO Pixel(id, price) VALUES -(1,1), -(2,1), -(3,1), -(4,1), -(5,1), -(6,1), -(7,1), -(8,1), -(9,1), -(10,1), -(11,1), -(12,1), -(13,1), -(14,1), -(15,1), -(16,1), -(17,1), -(18,1), -(19,1), -(20,1), -(21,1), -(22,1), -(23,1), -(24,1), -(25,1), -(26,1), -(27,1), -(28,1), -(29,1), -(30,1), -(31,1), -(32,1), -(33,1), -(34,1), -(35,1), -(36,1), -(37,1), -(38,1), -(39,1), -(40,1), -(41,1), -(42,1), -(43,1), -(44,1), -(45,1), -(46,1), -(47,1), -(48,1), -(49,1), -(50,1), -(51,1), -(52,1), -(53,1), -(54,1), -(55,1), -(56,1), -(57,1), -(58,1), -(59,1), -(60,1), -(61,1), -(62,1), -(63,1), -(64,1), -(65,1), -(66,1), -(67,1), -(68,1), -(69,1), -(70,1), -(71,1), -(72,1), -(73,1), -(74,1), -(75,1), -(76,1), -(77,1), -(78,1), -(79,1), -(80,1), -(81,1), -(82,1), -(83,1), -(84,1), -(85,1), -(86,1), -(87,1), -(88,1), -(89,1), -(90,1), -(91,1), -(92,1), -(93,1), -(94,1), -(95,1), -(96,1), -(97,1), -(98,1), -(99,1), -(100,1); + id bigint(20) NOT NULL AUTO_INCREMENT, + price int(11) DEFAULT NULL, + color varchar(6) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE = InnoDB; +INSERT INTO Pixel(id, price, color) +VALUES (1, 1, "ffffff"), + (2, 1, "ffffff"), + (3, 1, "ffffff"), + (4, 1, "ffffff"), + (5, 1, "ffffff"), + (6, 1, "ffffff"), + (7, 1, "ffffff"), + (8, 1, "ffffff"), + (9, 1, "ffffff"), + (10, 1, "ffffff"), + (11, 1, "ffffff"), + (12, 1, "ffffff"), + (13, 1, "ffffff"), + (14, 1, "ffffff"), + (15, 1, "ffffff"), + (16, 1, "ffffff"), + (17, 1, "ffffff"), + (18, 1, "ffffff"), + (19, 1, "ffffff"), + (20, 1, "ffffff"), + (21, 1, "ffffff"), + (22, 1, "ffffff"), + (23, 1, "ffffff"), + (24, 1, "ffffff"), + (25, 1, "ffffff"), + (26, 1, "ffffff"), + (27, 1, "ffffff"), + (28, 1, "ffffff"), + (29, 1, "ffffff"), + (30, 1, "ffffff"), + (31, 1, "ffffff"), + (32, 1, "ffffff"), + (33, 1, "ffffff"), + (34, 1, "ffffff"), + (35, 1, "ffffff"), + (36, 1, "ffffff"), + (37, 1, "ffffff"), + (38, 1, "ffffff"), + (39, 1, "ffffff"), + (40, 1, "ffffff"), + (41, 1, "ffffff"), + (42, 1, "ffffff"), + (43, 1, "ffffff"), + (44, 1, "ffffff"), + (45, 1, "ffffff"), + (46, 1, "ffffff"), + (47, 1, "ffffff"), + (48, 1, "ffffff"), + (49, 1, "ffffff"), + (50, 1, "ffffff"), + (51, 1, "ffffff"), + (52, 1, "ffffff"), + (53, 1, "ffffff"), + (54, 1, "ffffff"), + (55, 1, "ffffff"), + (56, 1, "ffffff"), + (57, 1, "ffffff"), + (58, 1, "ffffff"), + (59, 1, "ffffff"), + (60, 1, "ffffff"), + (61, 1, "ffffff"), + (62, 1, "ffffff"), + (63, 1, "ffffff"), + (64, 1, "ffffff"), + (65, 1, "ffffff"), + (66, 1, "ffffff"), + (67, 1, "ffffff"), + (68, 1, "ffffff"), + (69, 1, "ffffff"), + (70, 1, "ffffff"), + (71, 1, "ffffff"), + (72, 1, "ffffff"), + (73, 1, "ffffff"), + (74, 1, "ffffff"), + (75, 1, "ffffff"), + (76, 1, "ffffff"), + (77, 1, "ffffff"), + (78, 1, "ffffff"), + (79, 1, "ffffff"), + (80, 1, "ffffff"), + (81, 1, "ffffff"), + (82, 1, "ffffff"), + (83, 1, "ffffff"), + (84, 1, "ffffff"), + (85, 1, "ffffff"), + (86, 1, "ffffff"), + (87, 1, "ffffff"), + (88, 1, "ffffff"), + (89, 1, "ffffff"), + (90, 1, "ffffff"), + (91, 1, "ffffff"), + (92, 1, "ffffff"), + (93, 1, "ffffff"), + (94, 1, "ffffff"), + (95, 1, "ffffff"), + (96, 1, "ffffff"), + (97, 1, "ffffff"), + (98, 1, "ffffff"), + (99, 1, "ffffff"), + (100, 1, "ffffff"); \ No newline at end of file diff --git a/src/main/java/com/pixels/beans/Pixel.java b/src/main/java/com/pixels/beans/Pixel.java index 7232484..54b4713 100644 --- a/src/main/java/com/pixels/beans/Pixel.java +++ b/src/main/java/com/pixels/beans/Pixel.java @@ -3,14 +3,13 @@ package com.pixels.beans; import javax.persistence.*; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import java.awt.Color; - import java.io.Serializable; import java.util.List; @@ -32,8 +31,10 @@ public class Pixel implements Serializable { // couleur du pixel sur la peinture @NonNull - @NotNull - private Integer color; + @NotBlank + @Column(length = 6) + @Size(min = 6, max = 6) + private String color; // petit mot écrit par le user @NonNull @@ -47,18 +48,4 @@ public class Pixel implements Serializable { // liste des transactions associées au pixel @OneToMany(mappedBy = "pixel") private List transactions; - - public Color getColor() { - return new Color(color); - } - - public void setColor(Color color) { - this.color = color.getRGB(); - } - - public Pixel(Integer price, Color color, String description) { - this.price = price; - this.color = color.getRGB(); - this.description = description; - } } diff --git a/src/main/java/com/pixels/beans/Transaction.java b/src/main/java/com/pixels/beans/Transaction.java index 2938a34..58fe4a6 100644 --- a/src/main/java/com/pixels/beans/Transaction.java +++ b/src/main/java/com/pixels/beans/Transaction.java @@ -3,8 +3,6 @@ package com.pixels.beans; import javax.persistence.*; import javax.validation.constraints.NotNull; -import java.awt.Color; - import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; @@ -30,7 +28,7 @@ public class Transaction implements Serializable { // couleur du pixel de la transaction @NonNull @NotNull - private Integer color; + private String color; // date de la transaction @NonNull @@ -45,19 +43,11 @@ public class Transaction implements Serializable { @ManyToOne private Pixel pixel; - public Color getColor() { - return new Color(color); - } - - public void setColor(Color color) { - this.color = color.getRGB(); - } - public Transaction(Date time, Pixel pixel) { this.time = time; this.pixel = pixel; this.price = pixel.getPrice(); - this.color = pixel.getColor().getRGB(); + this.color = pixel.getColor(); this.buyer = pixel.getOwner(); } } diff --git a/src/main/java/com/pixels/beans/User.java b/src/main/java/com/pixels/beans/User.java index 373a1c9..133db83 100644 --- a/src/main/java/com/pixels/beans/User.java +++ b/src/main/java/com/pixels/beans/User.java @@ -9,7 +9,6 @@ import com.pixels.utils.Hash; import lombok.Data; import lombok.NoArgsConstructor; import lombok.NonNull; -import lombok.RequiredArgsConstructor; import java.io.Serializable; import java.util.List; @@ -17,18 +16,14 @@ import java.util.List; @Data @Entity @NoArgsConstructor -@RequiredArgsConstructor @NamedQuery(name = "User.list", query = "SELECT u FROM User u") public class User implements Serializable { - @Id // clé primaire - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - // nom d'utilisateur + @Id @NonNull @NotBlank - private String userName; + private String username; // addresse mail de l'utilisateur @NonNull @@ -52,9 +47,8 @@ public class User implements Serializable { @OneToMany(mappedBy = "owner") private List owned; - public User(Long id, String userName, String email, String password) { - this.id = id; - this.userName = userName; + public User(String username, String email, String password) { + this.username = username; this.email = email; this.hashPassword = Hash.sha256(password); }