Merge branch 'Arthur_API-Users' into Api_next-step2
continuous-integration/drone/push Build is failing Details

# Conflicts:
#	Sources/API/Quarkus/src/main/java/org/acme/Hibernates/entities/GameEntity.java
#	Sources/API/Quarkus/src/main/resources/application.properties
Api_next-step2
Arthur VALIN 2 years ago
commit 48550769cf

@ -8,6 +8,7 @@
<properties> <properties>
<compiler-plugin.version>3.10.1</compiler-plugin.version> <compiler-plugin.version>3.10.1</compiler-plugin.version>
<maven.compiler.release>11</maven.compiler.release> <maven.compiler.release>11</maven.compiler.release>
<maven.compiler.parameters>true</maven.compiler.parameters>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id> <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>

@ -0,0 +1,25 @@
package org.acme.Api.DTO;
import io.quarkus.hibernate.reactive.panache.common.ProjectedFieldName;
import io.quarkus.runtime.annotations.RegisterForReflection;
import org.acme.Hibernates.entities.UserStatsEntity;
@RegisterForReflection
public class UserDTO {
public Long id;
public String name;
public UserStatsDTO stats;
public UserDTO(Long id, String name,
@ProjectedFieldName("stats.nbVictories") Long nbVictories,
@ProjectedFieldName("stats.nbGames") Long nbGames,
@ProjectedFieldName("stats.highscore") Long highscore,
@ProjectedFieldName("stats.nbStrikes") Long nbStrikes,
@ProjectedFieldName("stats.nbSpares") Long nbSpares,
@ProjectedFieldName("stats.avgScore") Double avgScore,
@ProjectedFieldName("stats.avgPinsPerRound") Double avgPinsPerRound) {
this.id = id;
this.name = name;
this.stats = new UserStatsDTO(nbVictories, nbGames, highscore, nbStrikes, nbSpares, avgScore, avgPinsPerRound);
}
}

@ -0,0 +1,28 @@
package org.acme.Api.DTO;
import io.quarkus.runtime.annotations.RegisterForReflection;
import org.acme.Hibernates.entities.UserStatsEntity;
import org.hibernate.annotations.ColumnDefault;
@RegisterForReflection
public class UserStatsDTO {
public Long nbVictories;
public Long nbGames;
public Long highscore;
public Long nbStrikes;
public Long nbSpares;
public Double avgScore;
public Double avgPinsPerRound;
public UserStatsDTO(Long nbVictories, Long nbGames, Long highscore, Long nbStrikes, Long nbSpares, Double avgScore, Double avgPinsPerRound) {
this.nbVictories = nbVictories;
this.nbGames = nbGames;
this.highscore = highscore;
this.nbStrikes = nbStrikes;
this.nbSpares = nbSpares;
this.avgScore = avgScore;
this.avgPinsPerRound = avgPinsPerRound;
}
}

@ -0,0 +1,14 @@
package org.acme.Api.DTO;
import io.quarkus.hibernate.reactive.panache.common.ProjectedFieldName;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
public class UserTinyDTO {
public Long id;
public String name;
public UserTinyDTO(Long id, String name) {
this.id = id;
this.name = name;
}
}

@ -20,6 +20,9 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.Response.Status;
import io.quarkus.hibernate.reactive.panache.PanacheQuery;
import org.acme.Api.DTO.UserDTO;
import org.acme.Api.DTO.UserTinyDTO;
import org.acme.Api.service.UserService; import org.acme.Api.service.UserService;
import org.acme.Hibernates.entities.UserEntity; import org.acme.Hibernates.entities.UserEntity;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -40,10 +43,9 @@ public class UserController {
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Uni<List<UserEntity>> getUsers() { public Uni<List<UserTinyDTO>> getUsers() {
LOGGER.info("Getting all users and ordering it by name"); LOGGER.info("Getting all users and ordering it by name");
Uni<List<UserEntity>> allUsers = service.listAll(Sort.by("name")); return service.findAll().project(UserTinyDTO.class).list();
return allUsers;
} }
// @GET // @GET
@ -64,7 +66,7 @@ public class UserController {
@Path("/{id}") @Path("/{id}")
public Uni<Response> getUserById(@PathParam("id") Long id) { public Uni<Response> getUserById(@PathParam("id") Long id) {
LOGGER.info("Get user with id : " + id); LOGGER.info("Get user with id : " + id);
return service.findById(id) return service.findByBowlinId(id)
.onItem() .onItem()
.transform( .transform(
entity -> entity == null ? Response.status(Status.NOT_FOUND) : Response.ok(entity).status(200)) entity -> entity == null ? Response.status(Status.NOT_FOUND) : Response.ok(entity).status(200))

@ -4,6 +4,7 @@ import java.util.List;
import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.ApplicationScoped;
import org.acme.Api.DTO.UserDTO;
import org.acme.Hibernates.entities.UserEntity; import org.acme.Hibernates.entities.UserEntity;
import io.quarkus.hibernate.reactive.panache.PanacheRepository; import io.quarkus.hibernate.reactive.panache.PanacheRepository;
@ -19,6 +20,10 @@ public class UserService implements PanacheRepository<UserEntity> {
return list("name", name); return list("name", name);
} }
public Uni<List<UserDTO>> findByBowlinId(Long id) {
return find("id", id).project(UserDTO.class).list();
}
// public Uni<Long> deleteUser() { // public Uni<Long> deleteUser() {
// return delete("name", "Stef"); // return delete("name", "Stef");
// } // }

@ -6,9 +6,8 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import javax.persistence.*; import javax.persistence.*;
@Entity
// @Entity @Table(name="games")
// @Table(name = "games")
public class GameEntity { public class GameEntity {
@Id @Id
@ -87,7 +86,7 @@ public class GameEntity {
return this.isFinished; return this.isFinished;
} }
@OneToMany(mappedBy = "game", cascade = CascadeType.ALL, orphanRemoval = true) // @OneToMany(mappedBy = "game", cascade = CascadeType.ALL, orphanRemoval = true)
public List<RoundEntity> rounds = new ArrayList<>(); // public List<RoundEntity> rounds = new ArrayList<>();
} }

@ -1,5 +0,0 @@
package org.acme.Hibernates.entities;
public class StatEntity {
}

@ -12,7 +12,7 @@ public class UserStatsEntity {
@Id @Id
private Long id; private Long id;
@MapsId @MapsId
@OneToOne(fetch = FetchType.LAZY) @OneToOne
@JoinColumn (name = "user_id", referencedColumnName = "id", insertable = false, updatable = false) @JoinColumn (name = "user_id", referencedColumnName = "id", insertable = false, updatable = false)
private UserEntity user; private UserEntity user;
@ColumnDefault("0") @ColumnDefault("0")
@ -26,9 +26,9 @@ public class UserStatsEntity {
@ColumnDefault("0") @ColumnDefault("0")
private Long nbSpares = 0L; private Long nbSpares = 0L;
@ColumnDefault("-1") @ColumnDefault("-1")
private double avgScore = -1; private Double avgScore = 0d;
@ColumnDefault("-1") @ColumnDefault("-1")
private double avgPinsPerRound = -1; private Double avgPinsPerRound = 0d;
public UserStatsEntity() { public UserStatsEntity() {
} }

@ -1,8 +1,8 @@
# achanger # achanger
quarkus.datasource.db-kind = postgresql quarkus.datasource.db-kind = postgresql
quarkus.datasource.username = postgres quarkus.datasource.username = bowlin_team
quarkus.datasource.password = achanger quarkus.datasource.password = bowlin
quarkus.datasource.reactive.url = vertx-reactive:postgresql://localhost:5432/postgres quarkus.datasource.reactive.url = vertx-reactive:postgresql://localhost:5432/bowlin
quarkus.hibernate-orm.log.sql=true quarkus.hibernate-orm.log.sql=true
quarkus.hibernate-orm.sql-load-script=import.sql quarkus.hibernate-orm.sql-load-script=import.sql

Loading…
Cancel
Save