feat: début d'un backend
This commit is contained in:
parent
b4abd530e6
commit
033fc5851c
|
@ -4,12 +4,16 @@ import javax.persistence.*;
|
|||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@NamedQuery(name = "Groupe.list", query = "SELECT g FROM Groupe g")
|
||||
public class Groupe implements Serializable {
|
||||
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
package com.pixels.beans;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@NamedQuery(name = "Permission.list", query = "SELECT pe FROM Permission pe")
|
||||
public class Permission implements Serializable {
|
||||
|
||||
|
@ -18,5 +23,6 @@ public class Permission implements Serializable {
|
|||
|
||||
// type de la permission
|
||||
@NonNull
|
||||
@NotNull
|
||||
private Integer type;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
package com.pixels.beans;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
|
@ -12,6 +16,8 @@ import java.util.List;
|
|||
|
||||
@Data
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@NamedQuery(name = "Pixel.list", query = "SELECT p FROM Pixel p")
|
||||
public class Pixel implements Serializable {
|
||||
|
||||
|
@ -21,14 +27,17 @@ public class Pixel implements Serializable {
|
|||
|
||||
// prix du pixel à l'achat
|
||||
@NonNull
|
||||
@NotNull
|
||||
private Integer price;
|
||||
|
||||
// couleur du pixel sur la peinture
|
||||
@NonNull
|
||||
private Color color;
|
||||
@NotNull
|
||||
private Integer color;
|
||||
|
||||
// petit mot écrit par le user
|
||||
@NonNull
|
||||
@NotBlank
|
||||
private String description;
|
||||
|
||||
// propriétaire actuel du pixel
|
||||
|
@ -38,4 +47,18 @@ public class Pixel implements Serializable {
|
|||
// liste des transactions associées au pixel
|
||||
@OneToMany(mappedBy = "pixel")
|
||||
private List<Transaction> transactions;
|
||||
|
||||
Color getColor() {
|
||||
return new Color(color);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,19 @@
|
|||
package com.pixels.beans;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@NamedQuery(name = "Role.list", query = "SELECT r FROM Role r")
|
||||
public class Role implements Serializable {
|
||||
|
||||
|
@ -18,5 +23,6 @@ public class Role implements Serializable {
|
|||
|
||||
// type du role
|
||||
@NonNull
|
||||
@NotNull
|
||||
private Integer type;
|
||||
}
|
||||
|
|
|
@ -1,17 +1,22 @@
|
|||
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;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@NamedQuery(name = "Transaction.list", query = "SELECT t FROM Transaction t order by t.time desc")
|
||||
public class Transaction implements Serializable {
|
||||
|
||||
|
@ -21,14 +26,17 @@ public class Transaction implements Serializable {
|
|||
|
||||
// prix de la transaction*
|
||||
@NonNull
|
||||
@NotNull
|
||||
private Integer price;
|
||||
|
||||
// couleur du pixel de la transaction
|
||||
@NonNull
|
||||
private Color color;
|
||||
@NotNull
|
||||
private Integer color;
|
||||
|
||||
// date de la transaction
|
||||
@NonNull
|
||||
@NotNull
|
||||
private Date time;
|
||||
|
||||
@ManyToOne // wallet acheteur
|
||||
|
@ -36,4 +44,12 @@ public class Transaction implements Serializable {
|
|||
|
||||
@ManyToOne // pixel acheté
|
||||
private Pixel pixel;
|
||||
|
||||
Color getColor() {
|
||||
return new Color(color);
|
||||
}
|
||||
|
||||
void setColor(Color color) {
|
||||
this.color = color.getRGB();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,13 +6,17 @@ import javax.validation.constraints.NotBlank;
|
|||
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;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@NamedQuery(name = "User.list", query = "SELECT u FROM User u")
|
||||
public class User implements Serializable {
|
||||
|
||||
|
|
|
@ -4,13 +4,17 @@ import javax.persistence.*;
|
|||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@NamedQuery(name = "Wallet.list", query = "SELECT w FROM Wallet w")
|
||||
public class Wallet implements Serializable {
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.pixels.services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import javax.ejb.Singleton;
|
||||
|
@ -10,10 +8,14 @@ import javax.json.JsonObject;
|
|||
import javax.json.JsonObjectBuilder;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
|
@ -32,22 +34,44 @@ public class PixelService {
|
|||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String list() {
|
||||
List<Pixel> query = em.createNamedQuery("Pixel.list", Pixel.class).getResultList();
|
||||
return gson.toJson(query);
|
||||
TypedQuery<Pixel> query = em.createNamedQuery("Pixel.list", Pixel.class);
|
||||
return gson.toJson(query.getResultList());
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String single(@PathParam("id") Long id) {
|
||||
Pixel pixel = em.find(Pixel.class, id);
|
||||
return gson.toJson(pixel);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public JsonObject add() {
|
||||
|
||||
JsonObjectBuilder response = Json.createObjectBuilder();
|
||||
|
||||
Pixel pixel = new Pixel(10, new Color(255, 0, 0), "un pixel Poog");
|
||||
public String add(String json) {
|
||||
Pixel pixel = gson.fromJson(json, Pixel.class);
|
||||
em.persist(pixel);
|
||||
|
||||
response.add("status", "pixel created !");
|
||||
return response.build();
|
||||
return gson.toJson(pixel);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{id}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String update(@PathParam("id") Long id, String json) {
|
||||
Pixel pixel = gson.fromJson(json, Pixel.class);
|
||||
pixel.setId(id);
|
||||
em.merge(pixel);
|
||||
return gson.toJson(pixel);
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{id}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String remove(@PathParam("id") Long id) {
|
||||
Pixel pixel = em.find(Pixel.class, id);
|
||||
em.remove(pixel);
|
||||
return gson.toJson(pixel);
|
||||
}
|
||||
}
|
||||
|
|
3
src/main/webapp/WEB-INF/jboss-web.xml
Normal file
3
src/main/webapp/WEB-INF/jboss-web.xml
Normal file
|
@ -0,0 +1,3 @@
|
|||
<jboss-web>
|
||||
<context-root>/</context-root>
|
||||
</jboss-web>
|
Loading…
Reference in a new issue