Correct get users 🐛
continuous-integration/drone/push Build is passing Details

Quarkus_Continue
root 2 years ago
parent a921345f49
commit a336610308

@ -73,10 +73,6 @@
<groupId>io.quarkus</groupId> <groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId> <artifactId>quarkus-smallrye-openapi</artifactId>
</dependency> </dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi-ui</artifactId>
</dependency>
<!-- Dependency for openID --> <!-- Dependency for openID -->
<!-- <dependency> <!-- <dependency>
<groupId>io.quarkus</groupId> <groupId>io.quarkus</groupId>

@ -18,5 +18,4 @@ public class BowlDbContext {
public ParticipeRepository participeRepository; public ParticipeRepository participeRepository;
@Inject @Inject
public ThrowRepository throwRepository; public ThrowRepository throwRepository;
} }

@ -10,9 +10,18 @@ import org.eclipse.microprofile.openapi.annotations.media.Schema;
public class UserDTO { public class UserDTO {
public Long id; public Long id;
public String name; public String name;
public UserStatsDTO stats; public String image;
public String mail;
//public UserStatsDTO stats;
public UserDTO(Long id, String name, public UserDTO(Long id, String name, String image, String mail) {
this.id = id;
this.name = name;
this.image = image;
this.mail = mail;
}
/*public UserDTO(Long id, String name,
@ProjectedFieldName("stats.nbVictories") Long nbVictories, @ProjectedFieldName("stats.nbVictories") Long nbVictories,
@ProjectedFieldName("stats.nbGames") Long nbGames, @ProjectedFieldName("stats.nbGames") Long nbGames,
@ProjectedFieldName("stats.highscore") Long highscore, @ProjectedFieldName("stats.highscore") Long highscore,
@ -23,5 +32,5 @@ public class UserDTO {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.stats = new UserStatsDTO(nbVictories, nbGames, highscore, nbStrikes, nbSpares, avgScore, avgPinsPerRound); this.stats = new UserStatsDTO(nbVictories, nbGames, highscore, nbStrikes, nbSpares, avgScore, avgPinsPerRound);
} }*/
} }

@ -6,12 +6,13 @@ import org.acme.Hibernates.entities.UserEntity;
public class UserMappeur { public class UserMappeur {
public static UserDTO toUserDto(UserEntity entity) { public static UserDTO toUserDto(UserEntity entity) {
return new UserDTO(entity.id, entity.name, entity.stats.getNbVictories(), entity.stats.getNbGames(), /*return new UserDTO(entity.id, entity.name, entity.stats.getNbVictories(), entity.stats.getNbGames(),
entity.stats.getHighscore(), entity.stats.getNbStrikes(), entity.stats.getNbSpares(), entity.stats.getHighscore(), entity.stats.getNbStrikes(), entity.stats.getNbSpares(),
entity.stats.getAvgScore(), entity.stats.getAvgPinsPerRound()); entity.stats.getAvgScore(), entity.stats.getAvgPinsPerRound());*/
return new UserDTO((long)2, "f","fd","fd");
} }
public static UserTinyDTO toUserTinyDTO(UserEntity entity) { public static UserTinyDTO toUserTinyDTO(UserEntity entity) {
return new UserTinyDTO(entity.id, entity.name); return new UserTinyDTO(entity.id, entity.getName());
} }
} }

@ -1,32 +0,0 @@
package org.acme.Api.controllers;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
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;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import io.smallrye.mutiny.Uni;
@ApplicationScoped
@Path("/test")
public class TestController {
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/po")
public String hello() {
return "Hello from RESTEasy Reactive";
}
}

@ -40,6 +40,7 @@ import io.smallrye.mutiny.Uni;
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Path("/users") @Path("/users")
public class UserController { public class UserController {
private static final Logger LOGGER = Logger.getLogger(UserController.class.getName()); private static final Logger LOGGER = Logger.getLogger(UserController.class.getName());
@Inject @Inject
@ -69,7 +70,7 @@ public class UserController {
} }
@POST @POST
@Operation(summary = "Create a new User") @Operation(summary = "Create a new user")
@APIResponse(responseCode = "201", description = "User successfully created") @APIResponse(responseCode = "201", description = "User successfully created")
@APIResponse(responseCode = "422", description = "User invalidly set on request") @APIResponse(responseCode = "422", description = "User invalidly set on request")
@ReactiveTransactional @ReactiveTransactional
@ -87,7 +88,7 @@ public class UserController {
} }
@PUT @PUT
@Operation(summary = "Update a User") @Operation(summary = "Update a user")
@APIResponse(responseCode = "200", description = "OK") @APIResponse(responseCode = "200", description = "OK")
@APIResponse(responseCode = "404", description = "User not found") @APIResponse(responseCode = "404", description = "User not found")
@Path("/{id}") @Path("/{id}")
@ -103,7 +104,7 @@ public class UserController {
} }
@DELETE @DELETE
@Operation(summary = "Delete a User") @Operation(summary = "Delete a user")
@APIResponse(responseCode = "200", description = "User successfully deleted") @APIResponse(responseCode = "200", description = "User successfully deleted")
@APIResponse(responseCode = "404", description = "User not found") @APIResponse(responseCode = "404", description = "User not found")
@Path("/{id}") @Path("/{id}")

@ -13,6 +13,7 @@ import io.smallrye.mutiny.Uni;
@ApplicationScoped @ApplicationScoped
public class UserRepository implements PanacheRepository<UserEntity> { public class UserRepository implements PanacheRepository<UserEntity> {
// public Uni<UserEntity> getUserByName(String name) { // public Uni<UserEntity> getUserByName(String name) {
// return UserEntity.find("name", name).firstResult(); // return UserEntity.find("name", name).firstResult();
// } // }
@ -28,4 +29,5 @@ public class UserRepository implements PanacheRepository<UserEntity> {
// public Uni<Long> deleteUser() { // public Uni<Long> deleteUser() {
// return delete("name", "Stef"); // return delete("name", "Stef");
// } // }
} }

@ -1,5 +0,0 @@
package org.acme.Api.service;
public class UserService {
}

@ -9,7 +9,7 @@ import javax.persistence.*;
import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.ColumnDefault;
@Entity @Entity
@Table(name = "games") @Table(name = "Game")
public class GameEntity { public class GameEntity {
@Id @Id

@ -7,77 +7,6 @@ import javax.persistence.*;
import org.eclipse.microprofile.openapi.annotations.media.Schema; import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.ColumnDefault;
// @Entity
// @Table(name = "participe")
// public class ParticipeEntity {
// // @EmbeddedId
// // @Schema(description = "Composite primary key of the entity")
// // private ParticipeId id;
// // @Id
// // @ManyToOne
// // @JoinColumn(name = "game_id", referencedColumnName = "id")
// // @Schema(description = "The Game entity that this Participe belongs to")
// // private GameEntity game;
// @Id
// @Schema(description = "The position of the player in the game")
// private int position2;
// @Id
// @Schema(description = "The position of the player in the game")
// private int position;
// @ManyToOne
// @JoinColumn(name = "id_user", referencedColumnName = "id")
// @Schema(description = "The User entity that this Participe belongs to")
// private UserEntity user;
// @Column(name = "guest_name")
// @Schema(description = "Name of the guest")
// private String guestName;
// @Column(name = "total_points")
// @Schema(description = "Total points of the player in the game")
// private int totalPoints;
// // @MapsId
// // @OneToOne
// // @JoinColumn(name = "user_id", referencedColumnName = "id", insertable =
// // false, updatable = false)
// // private UserEntity user;
// // public ParticipeId getId() {
// // return id;
// // }
// // public void setId(ParticipeId id) {
// // this.id = id;
// // }
// public String getGuestName() {
// return guestName;
// }
// public void setGuestName(String guestName) {
// this.guestName = guestName;
// }
// public int getTotalPoints() {
// return totalPoints;
// }
// public void setTotalPoints(int totalPoints) {
// this.totalPoints = totalPoints;
// }
// public UserEntity getUser() {
// return user;
// }
// public void setUser(UserEntity user) {
// this.user = user;
// }
// }
@Entity @Entity
@Table(name = "participe") @Table(name = "participe")
public class ParticipeEntity { public class ParticipeEntity {
@ -86,18 +15,18 @@ public class ParticipeEntity {
public ParticipeId id; public ParticipeId id;
@ManyToOne @ManyToOne
@JoinColumn(name = "iduser", referencedColumnName = "id") @JoinColumn(name = "idUser", referencedColumnName = "id")
public UserEntity user; public UserEntity user;
/// luii
@ManyToOne @ManyToOne
@JoinColumn(name = "idGame", referencedColumnName = "id", insertable = false, updatable = false) @JoinColumn(name = "idGame", referencedColumnName = "id", insertable = false, updatable = false)
public GameEntity game; public GameEntity game;
@Column(name = "guestname") @Column(name = "guestName")
public String guestName; public String guestName;
@ColumnDefault("0") @ColumnDefault("0")
@Column(name = "totalpoints") @Column(name = "totalPoints")
public Integer totalPoints = 0; public Integer totalPoints = 0;
public ParticipeEntity() { public ParticipeEntity() {

@ -138,7 +138,7 @@ import javax.persistence.*;
// // constructors, getters and setters // // constructors, getters and setters
// } // }
@Entity @Entity
@Table(name = "round") @Table(name = "Round")
public class RoundEntity { public class RoundEntity {
@EmbeddedId @EmbeddedId

@ -5,7 +5,7 @@ import javax.persistence.*;
import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.ColumnDefault;
@Entity @Entity
@Table(name = "throwtable") @Table(name = "Throw")
public class ThrowEntity { public class ThrowEntity {
@EmbeddedId @EmbeddedId

@ -6,22 +6,30 @@ import java.util.List;
import javax.persistence.*; import javax.persistence.*;
@Entity @Entity
@Table(name = "users") @Table(name = "Users")
public class UserEntity { public class UserEntity {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id; public Long id;
@Column(length = 100)
public String name;
@Column(length = 100) @Column(length = 64)
private String name;
@Column(length = 255)
private String image;
@Column(length = 255)
private String mail;
@Column(length = 144)
private String password; private String password;
@OneToOne(cascade = CascadeType.ALL, mappedBy = "user", orphanRemoval = true) //@OneToOne(cascade = CascadeType.ALL, mappedBy = "user", orphanRemoval = true)
public UserStatsEntity stats; //public UserStatsEntity stats;
public UserEntity() { public UserEntity() {
this.stats = new UserStatsEntity(this); //this.stats = new UserStatsEntity(this);
} }
// return name as uppercase in the model // return name as uppercase in the model

@ -7,13 +7,13 @@ import java.io.Serializable;
import java.util.UUID; import java.util.UUID;
@Entity @Entity
@Table(name = "user_stats") @Table(name = "UserStats")
public class UserStatsEntity { public class UserStatsEntity {
@Id @Id
private Long id; private Long id;
@MapsId @MapsId
@OneToOne(fetch = FetchType.LAZY) @OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", referencedColumnName = "id", insertable = false, updatable = false) @JoinColumn(name = "userId", referencedColumnName = "id", insertable = false, updatable = false)
private UserEntity user; private UserEntity user;
@ColumnDefault("0") @ColumnDefault("0")

@ -1,8 +1,8 @@
# achanger
quarkus.datasource.db-kind = postgresql quarkus.datasource.db-kind = postgresql
quarkus.datasource.username = Garderie quarkus.datasource.username = postgres
quarkus.datasource.password = mdp quarkus.datasource.password = achanger
quarkus.datasource.reactive.url = vertx-reactive:postgresql://bowldev-postgresql:5432/BowlInDB quarkus.datasource.reactive.url = vertx-reactive:postgresql://localhost:5432/BowlInDB
#BowlDev-postgresql #BowlDev-postgresql
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

@ -1,61 +1,12 @@
-- INSERT INTO users(id, name,password) VALUES (nextval('hibernate_sequence'), 'Emre','Emre'); INSERT INTO
-- INSERT INTO users(id, name,password) VALUES (nextval('hibernate_sequence'), 'Arthur','Arthur'); Users (name, password, image, mail)
-- INSERT INTO users(id, name,password) VALUES (nextval('hibernate_sequence'), 'Lucas','Lucas'); VALUES
-- INSERT INTO users(id, name,password) VALUES (nextval('hibernate_sequence'), 'Louison','Louison'); ('David', 'password123','','david.d_almeida@etu.uca.fr'),
-- INSERT INTO users (Id, Name, Password) VALUES (1, 'Alice', 'password1'), ('Emre', 'password2','','emre.kartal@etu.uca.fr'),
-- (2, 'Bob', 'password2'), ('Arthur', 'password3','','arthur.valin@etu.uca.fr');
-- (3, 'Charlie', 'password3');
-- INSERT INTO user_stats (user_id, nbVictories, nbGames) VALUES
-- (1, 2, 5),
-- (2, 3, 7),
-- (3, 1, 3);
-- INSERT INTO games (Id, host_id) VALUES
-- (1, 1),
-- (2, 2);
-- INSERT INTO participe (idGame, position, iduser, guestname, totalPoints) VALUES
-- (1, 1, 1, NULL, 0),
-- (1, 2, 2, NULL, 0),
-- (2, 1, 2, NULL, 0),
-- (2, 2, NULL, 'guest1', 0),
-- (2, 3, NULL, 'guest2', 0);
-- INSERT INTO round (game_id, PlayerPosition, TurnNumber, points) VALUES
-- (1, 1, 1, 10),
-- (1, 2, 1, 7),
-- (1, 1, 2, 9),
-- (1, 2, 2, 1),
-- (1, 1, 3, 3),
-- (1, 2, 3, 10),
-- (2, 1, 1, 9),
-- (2, 2, 1, 1),
-- (2, 1, 2, 8),
-- (2, 2, 2, 2),
-- (2, 3, 2, 0),
-- (2, 1, 3, 10),
-- (2, 2, 3, 10),
-- (2, 3, 3, 7);
-- INSERT INTO ThrowTable (Order, idGame, position, , pins) VALUES /*INSERT INTO games (isFinished, nbPoints, time, winner, host_id) VALUES (false, 0, CURRENT_TIMESTAMP, 0, 1);
-- (1, 1, 1, 10),
-- (1, 1, 2, 7),
-- (2, 1, 1, 9),
-- (2, 1, 2, 1),
-- (3, 1, 1, 3),
-- (3, 1, 2, 10),
-- (1, 2, 1, 9),
-- (1, 2, 2, 1),
-- (2, 2, 1, 8),
-- (2, 2, 2, 2),
-- (3, 2, 3, 0),
-- (3, 2, 1, 10),
-- (4, 2, 2, 10),
-- (4, 2, 3, 7);
INSERT INTO users (name, password) VALUES ('Alice', 'password123');
INSERT INTO users (name, Password) VALUES
('Bob', 'password2'),
('Charlie', 'password3');
INSERT INTO games (isFinished, nbPoints, time, winner, host_id) VALUES (false, 0, CURRENT_TIMESTAMP, 0, 1);
INSERT INTO participe (idGame, position, guestname, totalpoints, iduser) VALUES (1, 1, 'Alice', 0, 1); INSERT INTO participe (idGame, position, guestname, totalpoints, iduser) VALUES (1, 1, 'Alice', 0, 1);
INSERT INTO round (game_id, idGame, position, turnNumber, points) VALUES (1, 1, 1, 1, 0); INSERT INTO round (game_id, idGame, position, turnNumber, points) VALUES (1, 1, 1, 1, 0);
INSERT INTO throwtable (OrderTrhow, game_id, idGame, position, turnNumber, pins) VALUES (1, 1, 1, 1, 1, 0); INSERT INTO throwtable (OrderTrhow, game_id, idGame, position, turnNumber, pins) VALUES (1, 1, 1, 1, 1, 0);
INSERT INTO user_stats (user_id, avgPinsPerRound, avgScore, highscore, nbGames, nbSpares, nbStrikes, nbVictories) VALUES (1, 0, 0, 0, 0, 0, 0, 0); INSERT INTO user_stats (user_id, avgPinsPerRound, avgScore, highscore, nbGames, nbSpares, nbStrikes, nbVictories) VALUES (1, 0, 0, 0, 0, 0, 0, 0);*/

@ -1,56 +0,0 @@
// package org.acme;
// import java.util.List;
// import org.acme.Api.controllers.UserController;
// import org.acme.Api.service.UserService;
// import org.acme.Hibernates.entities.UserEntity;
// @ExtendWith(MockitoExtension.class)
// public class UserCtrlTest {
// @Mock
// private UserService userService;
// @InjectMocks
// private UserController userController;
// @TestFactory
// Stream<DynamicTest> shouldReturnUserById() {
// List<UserEntity> users = Arrays.asList(
// new UserEntity(1L, "John", "password"),
// new UserEntity(2L, "Jane", "password"));
// return DynamicTest.stream(
// users.iterator(),
// user -> "should return user with id " + user.getId(),
// user -> {
// // Given
// Mockito.when(userService.findByBowlinId(user.getId()))
// .thenReturn(CompletableFuture.completedFuture(user));
// // When
// Uni<Response> response = userController.getUserById(user.getId());
// // Then
// response.subscribe().with(result -> {
// assertEquals(Response.Status.OK.getStatusCode(), result.getStatus());
// assertEquals(user, result.getEntity());
// });
// });
// }
// @Test
// void shouldReturn404IfUserNotFound() {
// // Given
// Long id = 1L;
// Mockito.when(userService.findByBowlinId(id)).thenReturn(CompletableFuture.completedFuture(null));
// // When
// Uni<Response> response = userController.getUserById(id);
// // Then
// response.subscribe().with(result -> {
// assertEquals(Response.Status.NOT_FOUND.getStatusCode(), result.getStatus());
// });
// }
// }
Loading…
Cancel
Save