feat: using hexstring for colors

This commit is contained in:
Laureηt 2022-05-20 11:37:54 +02:00
parent 211bbb3cb0
commit 575646ead2
No known key found for this signature in database
GPG key ID: D88C6B294FD40994
4 changed files with 117 additions and 146 deletions

View file

@ -1,107 +1,107 @@
CREATE TABLE Pixel ( CREATE TABLE Pixel (
id bigint(20) NOT NULL AUTO_INCREMENT, id bigint(20) NOT NULL AUTO_INCREMENT,
price int(11) DEFAULT NULL, price int(11) DEFAULT NULL,
color varchar(6) DEFAULT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE = InnoDB; ) ENGINE = InnoDB;
INSERT INTO Pixel(id, price, color)
INSERT INTO Pixel(id, price) VALUES VALUES (1, 1, "ffffff"),
(1,1), (2, 1, "ffffff"),
(2,1), (3, 1, "ffffff"),
(3,1), (4, 1, "ffffff"),
(4,1), (5, 1, "ffffff"),
(5,1), (6, 1, "ffffff"),
(6,1), (7, 1, "ffffff"),
(7,1), (8, 1, "ffffff"),
(8,1), (9, 1, "ffffff"),
(9,1), (10, 1, "ffffff"),
(10,1), (11, 1, "ffffff"),
(11,1), (12, 1, "ffffff"),
(12,1), (13, 1, "ffffff"),
(13,1), (14, 1, "ffffff"),
(14,1), (15, 1, "ffffff"),
(15,1), (16, 1, "ffffff"),
(16,1), (17, 1, "ffffff"),
(17,1), (18, 1, "ffffff"),
(18,1), (19, 1, "ffffff"),
(19,1), (20, 1, "ffffff"),
(20,1), (21, 1, "ffffff"),
(21,1), (22, 1, "ffffff"),
(22,1), (23, 1, "ffffff"),
(23,1), (24, 1, "ffffff"),
(24,1), (25, 1, "ffffff"),
(25,1), (26, 1, "ffffff"),
(26,1), (27, 1, "ffffff"),
(27,1), (28, 1, "ffffff"),
(28,1), (29, 1, "ffffff"),
(29,1), (30, 1, "ffffff"),
(30,1), (31, 1, "ffffff"),
(31,1), (32, 1, "ffffff"),
(32,1), (33, 1, "ffffff"),
(33,1), (34, 1, "ffffff"),
(34,1), (35, 1, "ffffff"),
(35,1), (36, 1, "ffffff"),
(36,1), (37, 1, "ffffff"),
(37,1), (38, 1, "ffffff"),
(38,1), (39, 1, "ffffff"),
(39,1), (40, 1, "ffffff"),
(40,1), (41, 1, "ffffff"),
(41,1), (42, 1, "ffffff"),
(42,1), (43, 1, "ffffff"),
(43,1), (44, 1, "ffffff"),
(44,1), (45, 1, "ffffff"),
(45,1), (46, 1, "ffffff"),
(46,1), (47, 1, "ffffff"),
(47,1), (48, 1, "ffffff"),
(48,1), (49, 1, "ffffff"),
(49,1), (50, 1, "ffffff"),
(50,1), (51, 1, "ffffff"),
(51,1), (52, 1, "ffffff"),
(52,1), (53, 1, "ffffff"),
(53,1), (54, 1, "ffffff"),
(54,1), (55, 1, "ffffff"),
(55,1), (56, 1, "ffffff"),
(56,1), (57, 1, "ffffff"),
(57,1), (58, 1, "ffffff"),
(58,1), (59, 1, "ffffff"),
(59,1), (60, 1, "ffffff"),
(60,1), (61, 1, "ffffff"),
(61,1), (62, 1, "ffffff"),
(62,1), (63, 1, "ffffff"),
(63,1), (64, 1, "ffffff"),
(64,1), (65, 1, "ffffff"),
(65,1), (66, 1, "ffffff"),
(66,1), (67, 1, "ffffff"),
(67,1), (68, 1, "ffffff"),
(68,1), (69, 1, "ffffff"),
(69,1), (70, 1, "ffffff"),
(70,1), (71, 1, "ffffff"),
(71,1), (72, 1, "ffffff"),
(72,1), (73, 1, "ffffff"),
(73,1), (74, 1, "ffffff"),
(74,1), (75, 1, "ffffff"),
(75,1), (76, 1, "ffffff"),
(76,1), (77, 1, "ffffff"),
(77,1), (78, 1, "ffffff"),
(78,1), (79, 1, "ffffff"),
(79,1), (80, 1, "ffffff"),
(80,1), (81, 1, "ffffff"),
(81,1), (82, 1, "ffffff"),
(82,1), (83, 1, "ffffff"),
(83,1), (84, 1, "ffffff"),
(84,1), (85, 1, "ffffff"),
(85,1), (86, 1, "ffffff"),
(86,1), (87, 1, "ffffff"),
(87,1), (88, 1, "ffffff"),
(88,1), (89, 1, "ffffff"),
(89,1), (90, 1, "ffffff"),
(90,1), (91, 1, "ffffff"),
(91,1), (92, 1, "ffffff"),
(92,1), (93, 1, "ffffff"),
(93,1), (94, 1, "ffffff"),
(94,1), (95, 1, "ffffff"),
(95,1), (96, 1, "ffffff"),
(96,1), (97, 1, "ffffff"),
(97,1), (98, 1, "ffffff"),
(98,1), (99, 1, "ffffff"),
(99,1), (100, 1, "ffffff");
(100,1);

View file

@ -3,14 +3,13 @@ package com.pixels.beans;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import java.awt.Color;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@ -32,8 +31,10 @@ public class Pixel implements Serializable {
// couleur du pixel sur la peinture // couleur du pixel sur la peinture
@NonNull @NonNull
@NotNull @NotBlank
private Integer color; @Column(length = 6)
@Size(min = 6, max = 6)
private String color;
// petit mot écrit par le user // petit mot écrit par le user
@NonNull @NonNull
@ -47,18 +48,4 @@ public class Pixel implements Serializable {
// liste des transactions associées au pixel // liste des transactions associées au pixel
@OneToMany(mappedBy = "pixel") @OneToMany(mappedBy = "pixel")
private List<Transaction> transactions; private List<Transaction> 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;
}
} }

View file

@ -3,8 +3,6 @@ package com.pixels.beans;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.awt.Color;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
@ -30,7 +28,7 @@ public class Transaction implements Serializable {
// couleur du pixel de la transaction // couleur du pixel de la transaction
@NonNull @NonNull
@NotNull @NotNull
private Integer color; private String color;
// date de la transaction // date de la transaction
@NonNull @NonNull
@ -45,19 +43,11 @@ public class Transaction implements Serializable {
@ManyToOne @ManyToOne
private Pixel pixel; 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) { public Transaction(Date time, Pixel pixel) {
this.time = time; this.time = time;
this.pixel = pixel; this.pixel = pixel;
this.price = pixel.getPrice(); this.price = pixel.getPrice();
this.color = pixel.getColor().getRGB(); this.color = pixel.getColor();
this.buyer = pixel.getOwner(); this.buyer = pixel.getOwner();
} }
} }

View file

@ -9,7 +9,6 @@ import com.pixels.utils.Hash;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull; import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@ -17,18 +16,14 @@ import java.util.List;
@Data @Data
@Entity @Entity
@NoArgsConstructor @NoArgsConstructor
@RequiredArgsConstructor
@NamedQuery(name = "User.list", query = "SELECT u FROM User u") @NamedQuery(name = "User.list", query = "SELECT u FROM User u")
public class User implements Serializable { public class User implements Serializable {
@Id // clé primaire
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
// nom d'utilisateur // nom d'utilisateur
@Id
@NonNull @NonNull
@NotBlank @NotBlank
private String userName; private String username;
// addresse mail de l'utilisateur // addresse mail de l'utilisateur
@NonNull @NonNull
@ -52,9 +47,8 @@ public class User implements Serializable {
@OneToMany(mappedBy = "owner") @OneToMany(mappedBy = "owner")
private List<Pixel> owned; private List<Pixel> owned;
public User(Long id, String userName, String email, String password) { public User(String username, String email, String password) {
this.id = id; this.username = username;
this.userName = userName;
this.email = email; this.email = email;
this.hashPassword = Hash.sha256(password); this.hashPassword = Hash.sha256(password);
} }