Compare commits

..

10 Commits

Author SHA1 Message Date
root 91b2ad7e90 Added user stats
continuous-integration/drone/push Build is passing Details
2 years ago
Emre KARTAL 968497e1b1 Add naming conventions
continuous-integration/drone/push Build is passing Details
2 years ago
Emre KARTAL 46ae14a55e just for test
continuous-integration/drone/push Build is failing Details
2 years ago
Emre KARTAL 468a877ece fixed naming convention errors 🐛
continuous-integration/drone/push Build is failing Details
2 years ago
Emre KARTAL 4011ff18c6 Put and post methods work with error handling 🔨
continuous-integration/drone/push Build is failing Details
2 years ago
root 2d23793eb0 Merge branch 'Quarkus_Continue' of https://codefirst.iut.uca.fr/git/BowlDev/Bowl_in into Quarkus_Continue
continuous-integration/drone/push Build is passing Details
2 years ago
Emre KARTAL b61e33dde7 Better cleanliness of the code (removal of unused dependencies and application of naming conventions) and improvement of the user controller (with addition of 2 new routes)
2 years ago
Emre KARTAL c1b8eca526 Mise à jour de 'Sources/API/Quarkus/src/main/resources/application.properties'
continuous-integration/drone/push Build is passing Details
2 years ago
root a336610308 Correct get users 🐛
continuous-integration/drone/push Build is passing Details
2 years ago
Emre KARTAL a921345f49 Add swagger-ui
continuous-integration/drone/push Build is failing Details
2 years ago

@ -1,13 +0,0 @@
package org.acme.Api.Mappeur;
import org.acme.Api.DTO.ParticipeDto;
import org.acme.Api.DTO.RoundDto;
import org.acme.Hibernates.entities.ParticipeEntity;
public class ParticipeMappeur {
public static ParticipeDto toDto(ParticipeEntity entity) {
return new ParticipeDto(entity.user.id, UserMappeur.toUserDto(entity.user), entity.totalPoints,
entity.guestName);
}
}

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

@ -1,17 +0,0 @@
package org.acme.Api.Mappeur;
import org.acme.Api.DTO.UserDTO;
import org.acme.Api.DTO.UserTinyDTO;
import org.acme.Hibernates.entities.UserEntity;
public class UserMappeur {
public static UserDTO toUserDto(UserEntity entity) {
return new UserDTO(entity.id, entity.name, entity.stats.getNbVictories(), entity.stats.getNbGames(),
entity.stats.getHighscore(), entity.stats.getNbStrikes(), entity.stats.getNbSpares(),
entity.stats.getAvgScore(), entity.stats.getAvgPinsPerRound());
}
public static UserTinyDTO toUserTinyDTO(UserEntity entity) {
return new UserTinyDTO(entity.id, entity.name);
}
}

@ -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";
}
}

@ -1,125 +0,0 @@
package org.acme.Api.controllers;
import java.net.URI;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.NotFoundException;
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.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import io.quarkus.hibernate.reactive.panache.PanacheQuery;
import org.acme.Api.BowlDbContext;
import org.acme.Api.DTO.UserDTO;
import org.acme.Api.DTO.UserTinyDTO;
import org.acme.Api.service.UserRepository;
import org.acme.Hibernates.entities.UserEntity;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.jboss.logging.Logger;
import io.quarkus.hibernate.reactive.panache.common.runtime.ReactiveTransactional;
import io.quarkus.panache.common.Sort;
import io.smallrye.mutiny.Uni;
@ApplicationScoped
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/users")
public class UserController {
private static final Logger LOGGER = Logger.getLogger(UserController.class.getName());
@Inject
BowlDbContext service;
@GET
@Operation(summary = "Get all users")
@Produces(MediaType.APPLICATION_JSON)
public Uni<List<UserDTO>> getUsers() {
LOGGER.info("Get all users");
return service.userRepository.findAll().project(UserDTO.class).list();
}
@GET
@Operation(summary = "Get a user by ID")
@APIResponse(responseCode = "200", description = "OK")
@APIResponse(responseCode = "404", description = "User not found")
@Path("/{id}")
public Uni<Response> getUserById(@PathParam("id") Long id) {
LOGGER.info("Get user with id : " + id);
return service.userRepository.findByBowlinId(id)
.onItem()
.transform(
entity -> entity == null ? Response.status(Status.NOT_FOUND) : Response.ok(entity).status(200))
.onItem().transform(Response.ResponseBuilder::build);
}
@POST
@Operation(summary = "Create a new User")
@APIResponse(responseCode = "201", description = "User successfully created")
@APIResponse(responseCode = "422", description = "User invalidly set on request")
@ReactiveTransactional
public Uni<Response> createUser(UserEntity user) {
if (user == null) {
throw new WebApplicationException("user was invalidly set on request.", 422);
}
LOGGER.info("creating user: " + user.getName());
return service.userRepository.persist(user)
.map(persistedUser -> Response
.created(URI.create("/users/" + user.id))
.entity(persistedUser)
.build())
.onFailure().recoverWithItem(Response.status(Status.BAD_REQUEST).build());
}
@PUT
@Operation(summary = "Update a User")
@APIResponse(responseCode = "200", description = "OK")
@APIResponse(responseCode = "404", description = "User not found")
@Path("/{id}")
@ReactiveTransactional
public Uni<Response> updateUser(@PathParam("id") Long id, UserEntity newUser) {
LOGGER.info("Update user with id : " + id);
return service.userRepository.findById(id)
.onItem().ifNull().failWith(() -> new WebApplicationException("User not found", Status.NOT_FOUND))
.onItem().ifNotNull().invoke(oldUser -> {
oldUser.setName(newUser.getName());
})
.onItem().ifNotNull().transform(entity -> Response.ok(entity).build());
}
@DELETE
@Operation(summary = "Delete a User")
@APIResponse(responseCode = "200", description = "User successfully deleted")
@APIResponse(responseCode = "404", description = "User not found")
@Path("/{id}")
@ReactiveTransactional
public Uni<Response> delete(@PathParam("id") Long id) {
LOGGER.info("Delete user with id : " + id);
return service.userRepository.deleteById(id)
.onItem().transform(entity -> !entity ? Response.status(Status.NOT_FOUND).build()
: Response.ok().status(200).build());
}
@GET
@Operation(summary = "Get the number of users")
@Path("/count")
public Uni<Long> count() {
LOGGER.info("Get user count");
return service.userRepository.count();
}
}

@ -1,31 +0,0 @@
package org.acme.Api.service;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import org.acme.Api.DTO.UserDTO;
import org.acme.Api.DTO.UserTinyDTO;
import org.acme.Hibernates.entities.UserEntity;
import io.quarkus.hibernate.reactive.panache.PanacheRepository;
import io.smallrye.mutiny.Uni;
@ApplicationScoped
public class UserRepository implements PanacheRepository<UserEntity> {
// public Uni<UserEntity> getUserByName(String name) {
// return UserEntity.find("name", name).firstResult();
// }
public Uni<List<UserEntity>> findwithName(String name) {
return list("name", name);
}
public Uni<List<UserDTO>> findByBowlinId(Long id) {
return find("id", id).project(UserDTO.class).list();
}
// public Uni<Long> deleteUser() {
// return delete("name", "Stef");
// }
}

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

@ -1,114 +0,0 @@
package org.acme.Hibernates.entities;
import java.io.Serializable;
import javax.persistence.*;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
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
@Table(name = "participe")
public class ParticipeEntity {
@EmbeddedId
public ParticipeId id;
@ManyToOne
@JoinColumn(name = "iduser", referencedColumnName = "id")
public UserEntity user;
/// luii
@ManyToOne
@JoinColumn(name = "idGame", referencedColumnName = "id", insertable = false, updatable = false)
public GameEntity game;
@Column(name = "guestname")
public String guestName;
@ColumnDefault("0")
@Column(name = "totalpoints")
public Integer totalPoints = 0;
public ParticipeEntity() {
}
public ParticipeEntity(ParticipeId id, UserEntity user, GameEntity game, String guestName, Integer totalPoints) {
this.id = id;
this.user = user;
this.game = game;
this.guestName = guestName;
this.totalPoints = totalPoints;
}
}

@ -1,45 +0,0 @@
package org.acme.Hibernates.entities;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.*;
@Entity
@Table(name = "users")
public class UserEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
@Column(length = 100)
public String name;
@Column(length = 100)
private String password;
@OneToOne(cascade = CascadeType.ALL, mappedBy = "user", orphanRemoval = true)
public UserStatsEntity stats;
public UserEntity() {
this.stats = new UserStatsEntity(this);
}
// return name as uppercase in the model
public String getName() {
return name.toUpperCase();
}
// store all names in lowercase in the DB
public void setName(String name) {
this.name = name.toLowerCase();
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password.toLowerCase();
}
}

@ -1,10 +1,9 @@
package org.acme.Api;
package org.acme.api;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.acme.Api.service.*;
import org.acme.api.repository.*;
@Singleton
public class BowlDbContext {
@ -18,5 +17,4 @@ public class BowlDbContext {
public ParticipeRepository participeRepository;
@Inject
public ThrowRepository throwRepository;
}

@ -1,17 +1,13 @@
package org.acme.Api.controllers;
package org.acme.api.controllers;
import java.net.URI;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.NotFoundException;
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;
@ -20,17 +16,11 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.acme.Api.DTO.GameDto;
import org.acme.Api.DTO.UserTinyDTO;
import org.acme.Api.Manager.DbManager;
import org.acme.Api.Manager.GameManager;
import org.acme.Api.service.GameRepository;
import org.acme.Hibernates.entities.GameEntity;
import org.acme.Hibernates.entities.UserEntity;
import org.acme.api.dto.GameDTO;
import org.acme.api.manager.DbManager;
import org.jboss.logging.Logger;
import io.quarkus.hibernate.reactive.panache.common.runtime.ReactiveTransactional;
import io.quarkus.panache.common.Sort;
import io.smallrye.mutiny.Uni;
@ApplicationScoped
@ -43,9 +33,9 @@ public class GameController {
DbManager dbManager;
@GET
public Uni<List<GameDto>> getUsers() {
public Uni<List<GameDTO>> getUsers() {
LOGGER.info("Getting all game");
Uni<List<GameDto>> allGames = dbManager.gameManager.getAllGames();
Uni<List<GameDTO>> allGames = dbManager.gameManager.getAllGames();
return allGames;
}
@ -64,7 +54,7 @@ public class GameController {
@POST
@ReactiveTransactional
public Uni<Response> createGame(GameDto game) {
public Uni<Response> createGame(GameDTO game) {
if (game == null) {
throw new WebApplicationException("user was invalidly set on request.", 422);
}

@ -0,0 +1,181 @@
package org.acme.api.controllers;
import java.util.List;
import java.util.stream.Collectors;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.acme.api.BowlDbContext;
import org.acme.api.dto.UserDTO;
import org.acme.api.dto.UserTinyDTO;
import org.acme.api.mapper.UserMapper;
import org.eclipse.microprofile.openapi.annotations.Operation;
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
import org.jboss.logging.Logger;
import io.quarkus.hibernate.reactive.panache.common.runtime.ReactiveTransactional;
import io.smallrye.mutiny.Uni;
@ApplicationScoped
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/users")
public class UserController {
private static final Logger LOGGER = Logger.getLogger(UserController.class.getName());
@Inject
BowlDbContext service;
@GET
@Operation(summary = "Get all users")
@Produces(MediaType.APPLICATION_JSON)
public Uni<List<UserDTO>> getUsers() {
LOGGER.info("Get all users");
return service.userRepository.findAll().list()
.map(entities -> entities.stream().map(UserMapper::toDto).collect(Collectors.toList()));
}
@GET
@Operation(summary = "Get a user by ID")
@APIResponse(responseCode = "200", description = "OK")
@APIResponse(responseCode = "404", description = "User not found")
@Path("/{id}")
public Uni<Response> getUserById(@PathParam("id") Long id) {
LOGGER.info("Get user with id : " + id);
return service.userRepository.getUserById(id)
.map(user -> user == null ? Response.status(Status.NOT_FOUND) : Response.ok(user).status(200))
.map(Response.ResponseBuilder::build);
}
@GET
@Operation(summary = "Get a user by name")
@APIResponse(responseCode = "200", description = "OK")
@APIResponse(responseCode = "404", description = "User not found")
@Path("/name/{name}")
public Uni<Response> getUserByName(@PathParam("name") String name) {
LOGGER.info("Get user with name : " + name);
return service.userRepository.verifiedName(name)
.flatMap(exist -> {
if (exist) {
return service.userRepository.findWithName(name)
.map(user -> Response.ok(user).build());
} else {
throw new NotFoundException("User not found");
}
});
}
@GET
@Operation(summary = "Get a user by mail")
@APIResponse(responseCode = "200", description = "OK")
@APIResponse(responseCode = "404", description = "User not found")
@Path("/mail/{mail}")
public Uni<Response> getUserByMail(@PathParam("mail") String mail) {
LOGGER.info("Get user with mail : " + mail);
return service.userRepository.verifiedMail(mail)
.flatMap(exist -> {
if (exist) {
return service.userRepository.findWithMail(mail)
.map(user -> Response.ok(user).build());
} else {
throw new NotFoundException("User not found");
}
});
}
@POST
@Operation(summary = "Create a new user")
@APIResponse(responseCode = "201", description = "User successfully created")
@APIResponse(responseCode = "422", description = "User invalidly set on request")
@ReactiveTransactional
public Uni<Response> createUser(UserTinyDTO user) {
if (user == null) {
throw new WebApplicationException("user was invalidly set on request.", 422);
}
LOGGER.info("creating user: " + user);
return Uni.combine().all().unis(
service.userRepository.verifiedName(user.name),
service.userRepository.verifiedMail(user.mail))
.asTuple()
.flatMap(tuple -> {
boolean nameExists = tuple.getItem1();
boolean mailExists = tuple.getItem2();
if (nameExists) {
throw new WebApplicationException("Name already exists", Status.BAD_REQUEST);
}
if (mailExists) {
throw new WebApplicationException("Mail already exists", Status.BAD_REQUEST);
}
return service.userRepository.addUser(user)
.map(createdUser -> Response.status(Response.Status.CREATED).entity(createdUser).build());
})
.onFailure().recoverWithItem(Response.status(Status.BAD_REQUEST).build());
}
@PUT
@Operation(summary = "Update a user")
@APIResponse(responseCode = "200", description = "OK")
@APIResponse(responseCode = "400", description = "Bad Request")
@APIResponse(responseCode = "404", description = "User not found")
@Path("/{id}")
@ReactiveTransactional
public Uni<Response> updateUser(@PathParam("id") Long id, UserTinyDTO newUser) {
LOGGER.info("Update user with id : " + id);
return service.userRepository.findById(id)
.onItem().ifNull().failWith(() -> new WebApplicationException("User not found", Status.NOT_FOUND))
.onItem().ifNotNull().transformToUni(oldUser ->
Uni.combine().all().unis(
service.userRepository.verifiedName(newUser.name),
service.userRepository.verifiedMail(newUser.mail))
.asTuple()
.flatMap(tuple -> {
boolean nameExists = tuple.getItem1();
boolean mailExists = tuple.getItem2();
if (nameExists && !oldUser.getName().equalsIgnoreCase(newUser.name)) {
throw new WebApplicationException("Name already exists", Status.BAD_REQUEST);
}
if (mailExists && !oldUser.getMail().equalsIgnoreCase(newUser.mail)) {
throw new WebApplicationException("Mail already exists", Status.BAD_REQUEST);
}
oldUser.setName(newUser.name);
oldUser.setMail(newUser.mail);
oldUser.setImage(newUser.image);
return service.userRepository.persistAndFlush(oldUser)
.map(entity -> Response.ok(UserMapper.toDto(entity)).build());
})
);
}
@DELETE
@Operation(summary = "Delete a user")
@APIResponse(responseCode = "204")
@APIResponse(responseCode = "404", description = "User not found")
@Path("/{id}")
@ReactiveTransactional
public Uni<Response> delete(@PathParam("id") Long id) {
LOGGER.info("Delete user with id : " + id);
return service.userRepository.deleteById(id)
.onItem().transform(entity -> !entity ? Response.status(Status.NOT_FOUND).build()
: Response.noContent().build());
}
@GET
@Operation(summary = "Get the number of users")
@Path("/count")
public Uni<Long> count() {
LOGGER.info("Get user count");
return service.userRepository.count();
}
}

@ -1,25 +1,17 @@
package org.acme.Api.DTO;
package org.acme.api.dto;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.acme.Hibernates.entities.GameEntity;
import org.acme.Hibernates.entities.ParticipeEntity;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.quarkus.hibernate.reactive.panache.common.ProjectedFieldName;
import io.quarkus.runtime.annotations.RegisterForReflection;
import io.smallrye.mutiny.Uni;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.time.LocalDate;
import java.util.List;
// @RegisterForReflection
// @Schema(description = "A DTO for transferring game details")
@ -49,13 +41,13 @@ import java.util.List;
@RegisterForReflection // Annotation pour permettre l'utilisation avec Quarkus
@Schema(description = "A DTO for transferring game details")
public class GameDto {
public class GameDTO {
@JsonProperty("id")
public Long id;
@JsonProperty("players")
public Uni<List<ParticipeDto>> players;
public Uni<List<ParticipeDTO>> players;
@JsonProperty("date")
@JsonFormat(pattern = "yyyy-MM-dd")
@ -69,19 +61,19 @@ public class GameDto {
@JsonIgnore
@JsonProperty("rounds")
public Uni<List<RoundDto>> rounds;
public Uni<List<RoundDTO>> rounds;
public GameDto() {
public GameDTO() {
// Constructeur vide pour la désérialisation
}
// Constructeur avec tous les champs sauf l'ID (généré automatiquement)
public GameDto(Long id,
Uni<List<ParticipeDto>> players,
LocalDate time,
Long ownerGame,
UserTinyDTO winner,
Uni<List<RoundDto>> rounds) {
public GameDTO(Long id,
Uni<List<ParticipeDTO>> players,
LocalDate time,
Long ownerGame,
UserTinyDTO winner,
Uni<List<RoundDTO>> rounds) {
this.players = players;
this.date = time;
this.hostID = ownerGame;

@ -1,15 +1,11 @@
package org.acme.Api.DTO;
package org.acme.api.dto;
import java.util.UUID;
import org.acme.Hibernates.entities.ParticipeEntity;
import org.acme.Hibernates.entities.ParticipeId;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
public class ParticipeDto {
public class ParticipeDTO {
public Long idUser;
@Schema(description = "Name of the guest")
@ -21,7 +17,7 @@ public class ParticipeDto {
@Schema(description = "The User entity that this Participe belongs to")
public UserDTO user;
public ParticipeDto(Long idUser, UserDTO user, Integer totalPoints, String guestName) {
public ParticipeDTO(Long idUser, UserDTO user, Integer totalPoints, String guestName) {
this.idUser = idUser;
this.guestName = guestName;

@ -1,19 +1,19 @@
package org.acme.Api.DTO;
package org.acme.api.dto;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
public class RoundDto {
public class RoundDTO {
private int playerPosition;
private int turn;
private int pinsFirstThrow;
private int pinsSecondThrow;
private int points;
public RoundDto() {
public RoundDTO() {
}
public RoundDto(int playerPosition, int turn, int pinsFirstThrow, int pinsSecondThrow, int points) {
public RoundDTO(int playerPosition, int turn, int pinsFirstThrow, int pinsSecondThrow, int points) {
this.playerPosition = playerPosition;
this.turn = turn;
this.pinsFirstThrow = pinsFirstThrow;

@ -1,18 +1,27 @@
package org.acme.Api.DTO;
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;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
@RegisterForReflection
@Schema(description = "A DTO for transferring user details")
public class UserDTO {
public Long id;
public String name;
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, UserStatsDTO stats) {
this.id = id;
this.name = name;
this.image = image;
this.mail = mail;
this.stats = stats;
}
/*public UserDTO(Long id, String name,
@ProjectedFieldName("stats.nbVictories") Long nbVictories,
@ProjectedFieldName("stats.nbGames") Long nbGames,
@ProjectedFieldName("stats.highscore") Long highscore,
@ -23,5 +32,5 @@ public class UserDTO {
this.id = id;
this.name = name;
this.stats = new UserStatsDTO(nbVictories, nbGames, highscore, nbStrikes, nbSpares, avgScore, avgPinsPerRound);
}
}*/
}

@ -1,9 +1,7 @@
package org.acme.Api.DTO;
package org.acme.api.dto;
import io.quarkus.runtime.annotations.RegisterForReflection;
import org.acme.Hibernates.entities.UserStatsEntity;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.hibernate.annotations.ColumnDefault;
@RegisterForReflection
@Schema(description = "A DTO describing the stats of a User")
@ -17,7 +15,7 @@ public class UserStatsDTO {
public Double avgPinsPerRound;
public UserStatsDTO(Long nbVictories, Long nbGames, Long highscore, Long nbStrikes, Long nbSpares, Double avgScore,
Double avgPinsPerRound) {
Double avgPinsPerRound) {
this.nbVictories = nbVictories;
this.nbGames = nbGames;
this.highscore = highscore;

@ -1,16 +1,20 @@
package org.acme.Api.DTO;
package org.acme.api.dto;
import io.quarkus.hibernate.reactive.panache.common.ProjectedFieldName;
import io.quarkus.runtime.annotations.RegisterForReflection;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
@RegisterForReflection
@Schema(description = "A minimal DTO for transferring user information")
public class UserTinyDTO {
public Long id;
public String name;
public UserTinyDTO(Long id, String name) {
this.id = id;
public String image;
public String mail;
public String password;
public UserTinyDTO(String name, String image, String mail, String password) {
this.name = name;
this.image = image;
this.mail = mail;
this.password = password;
}
}

@ -1,10 +1,9 @@
package org.acme.Api.Manager;
package org.acme.api.manager;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.acme.Api.BowlDbContext;
import org.acme.api.BowlDbContext;
@Singleton
public class DbManager {

@ -1,13 +1,12 @@
package org.acme.Api.Manager;
package org.acme.api.manager;
import java.util.List;
import java.util.stream.Collectors;
import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.NotFoundException;
import org.acme.Api.DTO.GameDto;
import org.acme.Api.Mappeur.GameMappeur;
import org.acme.api.dto.GameDTO;
import org.acme.api.mapper.GameMapper;
import io.smallrye.mutiny.Uni;
@ -19,21 +18,21 @@ public class GameManager {
this.dbManager = dbManager;
}
public Uni<GameDto> saveGame(GameDto game) {
return dbManager.dbContext.gameRepository.persist(GameMappeur.toEntity(game, dbManager.dbContext))
.onItem().transform(gameEntity -> GameMappeur.toDto(gameEntity, dbManager.dbContext));
public Uni<GameDTO> saveGame(GameDTO game) {
return dbManager.dbContext.gameRepository.persist(GameMapper.toEntity(game, dbManager.dbContext))
.onItem().transform(gameEntity -> GameMapper.toDto(gameEntity, dbManager.dbContext));
}
public Uni<GameDto> getDetailsGameById(Long gameId) {
public Uni<GameDTO> getDetailsGameById(Long gameId) {
return dbManager.dbContext.gameRepository.findById(gameId)
.onItem().ifNull().failWith(new NotFoundException("Game not found"))
.onItem().transform(gameEntity -> GameMappeur.toDto(gameEntity, dbManager.dbContext));
.onItem().transform(gameEntity -> GameMapper.toDto(gameEntity, dbManager.dbContext));
}
public Uni<List<GameDto>> getAllGames() {
public Uni<List<GameDTO>> getAllGames() {
return dbManager.dbContext.gameRepository.findAll().list()
.onItem().transform(games -> games.stream()
.map(gameEntity -> GameMappeur.toDto(gameEntity, dbManager.dbContext))
.map(gameEntity -> GameMapper.toDto(gameEntity, dbManager.dbContext))
.collect(Collectors.toList()))
.onFailure().invoke(throwable -> {
// Log the error or perform any other error handling here

@ -1,4 +1,4 @@
package org.acme.Api.Mappeur;
package org.acme.api.mapper;
import java.time.LocalDate;
import java.time.ZoneId;
@ -7,26 +7,26 @@ import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import org.acme.Api.DTO.ParticipeDto;
import org.acme.Api.DTO.RoundDto;
import org.acme.Hibernates.entities.ParticipeEntity;
import org.acme.Hibernates.entities.RoundEntity;
import org.acme.api.dto.ParticipeDTO;
import org.acme.api.dto.RoundDTO;
import org.acme.hibernates.entities.ParticipeEntity;
import org.acme.hibernates.entities.RoundEntity;
import io.smallrye.mutiny.Uni;
public class Extensions {
public static Uni<List<RoundDto>> toRoundDtoList(Uni<List<RoundEntity>> uni) {
public static Uni<List<RoundDTO>> toRoundDtoList(Uni<List<RoundEntity>> uni) {
return uni.map(roundEntities -> roundEntities.stream()
.map(RoundMappeur::toDto)
.map(RoundMapper::toDto)
.collect(Collectors.toList()));
}
public static Uni<List<ParticipeDto>> toParticipeDtoList(Uni<List<ParticipeEntity>> uni) {
public static Uni<List<ParticipeDTO>> toParticipeDtoList(Uni<List<ParticipeEntity>> uni) {
return uni
.onItem().transformToUni(participes -> {
List<ParticipeDto> dtos = new ArrayList<>();
List<ParticipeDTO> dtos = new ArrayList<>();
for (ParticipeEntity entity : participes) {
dtos.add(ParticipeMappeur.toDto(entity));
dtos.add(ParticipeMapper.toDto(entity));
}
return Uni.createFrom().item(dtos);
})

@ -1,22 +1,13 @@
package org.acme.Api.Mappeur;
package org.acme.api.mapper;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.acme.api.BowlDbContext;
import org.acme.api.dto.GameDTO;
import org.acme.hibernates.entities.GameEntity;
import org.acme.Api.BowlDbContext;
import org.acme.Api.DTO.GameDto;
import org.acme.Api.DTO.UserTinyDTO;
import org.acme.Hibernates.entities.GameEntity;
public class GameMapper {
public class GameMappeur {
public static GameDto toDto(GameEntity entity, BowlDbContext dbContext) {
GameDto dto = new GameDto();
public static GameDTO toDto(GameEntity entity, BowlDbContext dbContext) {
GameDTO dto = new GameDTO();
dto.id = entity.id;
dto.players = dbContext.participeRepository.findByGameIdQ(entity.id);
dto.date = Extensions.toLocalDate(entity.time);
@ -25,7 +16,7 @@ public class GameMappeur {
return dto;
}
public static GameEntity toEntity(GameDto entity, BowlDbContext dbContext) {
public static GameEntity toEntity(GameDTO entity, BowlDbContext dbContext) {
GameEntity game = new GameEntity();
return game;

@ -0,0 +1,12 @@
package org.acme.api.mapper;
import org.acme.api.dto.ParticipeDTO;
import org.acme.hibernates.entities.ParticipeEntity;
public class ParticipeMapper {
public static ParticipeDTO toDto(ParticipeEntity entity) {
return new ParticipeDTO(entity.user.id, UserMapper.toDto(entity.user), entity.totalPoints,
entity.guestName);
}
}

@ -1,14 +1,14 @@
package org.acme.Api.Mappeur;
package org.acme.api.mapper;
import java.util.List;
import org.acme.Api.DTO.RoundDto;
import org.acme.Hibernates.entities.RoundEntity;
import org.acme.Hibernates.entities.ThrowEntity;
import org.acme.api.dto.RoundDTO;
import org.acme.hibernates.entities.RoundEntity;
import org.acme.hibernates.entities.ThrowEntity;
public class RoundMappeur {
public class RoundMapper {
public static RoundDto toDto(RoundEntity entity) {
public static RoundDTO toDto(RoundEntity entity) {
List<ThrowEntity> throwsGame = entity.throwsGame;
int val1 = 0;
int val2 = 0;
@ -20,6 +20,6 @@ public class RoundMappeur {
val1 = throwsGame.get(1).pins;
}
return new RoundDto(entity.participe.id.position, 0, val1, val2, entity.points);
return new RoundDTO(entity.participe.id.position, 0, val1, val2, entity.points);
}
}

@ -0,0 +1,5 @@
package org.acme.api.mapper;
public class TrhowMapper {
}

@ -0,0 +1,38 @@
package org.acme.api.mapper;
import org.acme.api.dto.UserDTO;
import org.acme.api.dto.UserTinyDTO;
import org.acme.hibernates.entities.UserEntity;
import java.security.MessageDigest;
public class UserMapper {
private static final String HASH_ALGORITHM = "SHA-256";
public static UserDTO toDto(UserEntity user) {
return new UserDTO(user.id, user.getName(), user.getImage(), user.getMail(), UserStatsMapper.toDto(user.stats));
}
public static UserEntity toEntity(UserTinyDTO user) {
try {
MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM);
byte[] hashedBytes = digest.digest(user.password.getBytes("UTF-8"));
String hashedPassword = bytesToHex(hashedBytes);
return new UserEntity(user.name.toLowerCase(), user.image, user.mail.toLowerCase(), hashedPassword);
} catch (Exception ex) {
throw new RuntimeException("Error hashing password", ex);
}
}
private static String bytesToHex(byte[] bytes) {
StringBuilder hexString = new StringBuilder();
for (byte b : bytes) {
String hex = Integer.toHexString(0xFF & b);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
}
}

@ -0,0 +1,12 @@
package org.acme.api.mapper;
import org.acme.api.dto.UserStatsDTO;
import org.acme.hibernates.entities.UserStatsEntity;
public class UserStatsMapper {
public static UserStatsDTO toDto(UserStatsEntity stats) {
return new UserStatsDTO(stats.getNbVictories(),stats.getNbGames(), stats.getHighscore(), stats.getNbStrikes(), stats.getNbSpares(), stats.getAvgScore(), stats.getAvgPinsPerRound());
}
}

@ -1,13 +1,11 @@
package org.acme.Api.service;
package org.acme.api.repository;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.NotFoundException;
import org.acme.Api.DTO.GameDto;
import org.acme.Api.Mappeur.GameMappeur;
import org.acme.Hibernates.entities.GameEntity;
import org.acme.api.dto.GameDTO;
import org.acme.hibernates.entities.GameEntity;
import io.quarkus.hibernate.reactive.panache.PanacheRepository;
import io.smallrye.mutiny.Uni;
@ -18,8 +16,8 @@ public class GameRepository implements PanacheRepository<GameEntity> {
return list("id", id);
}
public Uni<List<GameDto>> findByIdGame(Long id) {
return find("id", id).project(GameDto.class).list();
public Uni<List<GameDTO>> findByIdGame(Long id) {
return find("id", id).project(GameDTO.class).list();
}
}
// public Uni<GameDto> getDetailsGameById(Long gameId) {

@ -1,11 +1,11 @@
package org.acme.Api.service;
package org.acme.api.repository;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import org.acme.Api.DTO.ParticipeDto;
import org.acme.Hibernates.entities.ParticipeEntity;
import org.acme.api.dto.ParticipeDTO;
import org.acme.hibernates.entities.ParticipeEntity;
import io.quarkus.hibernate.reactive.panache.PanacheQuery;
import io.quarkus.hibernate.reactive.panache.PanacheRepository;
@ -17,8 +17,8 @@ public class ParticipeRepository implements PanacheRepository<ParticipeEntity> {
return list("game.id", gameId);
}
public Uni<List<ParticipeDto>> findByGameIdQ(Long gameId) {
PanacheQuery<ParticipeDto> query = find("game.id", gameId).project(ParticipeDto.class);
public Uni<List<ParticipeDTO>> findByGameIdQ(Long gameId) {
PanacheQuery<ParticipeDTO> query = find("game.id", gameId).project(ParticipeDTO.class);
return query.list();
}
}

@ -1,11 +1,10 @@
package org.acme.Api.service;
package org.acme.api.repository;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import org.acme.Hibernates.entities.GameEntity;
import org.acme.Hibernates.entities.RoundEntity;
import org.acme.hibernates.entities.RoundEntity;
import io.quarkus.hibernate.reactive.panache.PanacheRepository;
import io.smallrye.mutiny.Uni;

@ -1,8 +1,8 @@
package org.acme.Api.service;
package org.acme.api.repository;
import javax.enterprise.context.ApplicationScoped;
import org.acme.Hibernates.entities.ThrowEntity;
import org.acme.hibernates.entities.ThrowEntity;
import io.quarkus.hibernate.reactive.panache.PanacheRepository;

@ -0,0 +1,54 @@
package org.acme.api.repository;
import javax.enterprise.context.ApplicationScoped;
import org.acme.api.dto.UserDTO;
import org.acme.api.dto.UserTinyDTO;
import org.acme.api.mapper.UserMapper;
import org.acme.hibernates.entities.UserEntity;
import io.quarkus.hibernate.reactive.panache.PanacheRepository;
import io.smallrye.mutiny.Uni;
import java.util.Objects;
@ApplicationScoped
public class UserRepository implements PanacheRepository<UserEntity> {
public Uni<UserDTO> addUser(UserTinyDTO user) {
UserEntity userEntity = UserMapper.toEntity(user);
return persistAndFlush(userEntity)
.map(ignore -> UserMapper.toDto(userEntity));
}
public Uni<UserDTO> findWithName(String name) {
return find("name", name.toLowerCase())
.firstResult()
.map(UserMapper::toDto);
}
public Uni<Boolean> verifiedName(String name) {
return find("name", name.toLowerCase())
.firstResult()
.map(Objects::nonNull);
}
public Uni<Boolean> verifiedMail(String mail) {
return find("mail", mail.toLowerCase())
.firstResult()
.map(Objects::nonNull);
}
public Uni<UserDTO> findWithMail(String mail) {
return find("mail", mail.toLowerCase())
.firstResult()
.map(UserMapper::toDto);
}
public Uni<UserDTO> getUserById(Long id) {
return find("id", id)
.firstResult()
.map(UserMapper::toDto);
}
}

@ -1,4 +1,4 @@
package org.acme.Hibernates.entities;
package org.acme.hibernates.entities;
import java.util.ArrayList;
import java.util.Date;
@ -11,25 +11,19 @@ import org.hibernate.annotations.ColumnDefault;
@Entity
@Table(name = "games")
public class GameEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable = false)
@ColumnDefault("CURRENT_TIMESTAMP")
public Date time = new Date();
@ColumnDefault("0")
public Long winner = 0L;
@ColumnDefault("0")
public int nbPoints = 0;
@ColumnDefault("false")
public Boolean isFinished = false;
@ManyToOne
@JoinColumn(name = "host_id", referencedColumnName = "id")
public UserEntity ownerGame;
@ -38,7 +32,7 @@ public class GameEntity {
}
public GameEntity(UserEntity user, List<ParticipeEntity> players, List<RoundEntity> rounds, Date time, Long winner,
int nbPoints, Boolean isFinished) {
int nbPoints, Boolean isFinished) {
this.ownerGame = user;
this.time = time;
this.winner = winner;

@ -0,0 +1,38 @@
package org.acme.hibernates.entities;
import java.io.Serializable;
import javax.persistence.*;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.hibernate.annotations.ColumnDefault;
@Entity
@Table(name = "participes")
public class ParticipeEntity {
@EmbeddedId
public ParticipeId id;
@ManyToOne
@JoinColumn(name = "idUser", referencedColumnName = "id")
public UserEntity user;
@ManyToOne
@JoinColumn(name = "idGame", referencedColumnName = "id", insertable = false, updatable = false)
public GameEntity game;
@Column(name = "guestName")
public String guestName;
@ColumnDefault("0")
@Column(name = "totalPoints")
public Integer totalPoints = 0;
public ParticipeEntity() {
}
public ParticipeEntity(ParticipeId id, UserEntity user, GameEntity game, String guestName, Integer totalPoints) {
this.id = id;
this.user = user;
this.game = game;
this.guestName = guestName;
this.totalPoints = totalPoints;
}
}

@ -1,4 +1,4 @@
package org.acme.Hibernates.entities;
package org.acme.hibernates.entities;
import java.io.Serializable;

@ -1,4 +1,4 @@
package org.acme.Hibernates.entities;
package org.acme.hibernates.entities;
import java.io.Serializable;
import java.util.ArrayList;
@ -138,26 +138,21 @@ import javax.persistence.*;
// // constructors, getters and setters
// }
@Entity
@Table(name = "round")
@Table(name = "rounds")
public class RoundEntity {
@EmbeddedId
public RoundId id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "game_id", referencedColumnName = "id", insertable = false, updatable = false)
public GameEntity game;
@ManyToOne
@JoinColumns({
@JoinColumn(name = "idGame", referencedColumnName = "idGame", insertable = false, updatable = false),
@JoinColumn(name = "position", referencedColumnName = "position", insertable = false, updatable = false)
})
public ParticipeEntity participe;
@Column(name = "points")
public Integer points;
@OneToMany(mappedBy = "round", cascade = CascadeType.ALL, orphanRemoval = true)
public List<ThrowEntity> throwsGame = new ArrayList<>();

@ -1,4 +1,4 @@
package org.acme.Hibernates.entities;
package org.acme.hibernates.entities;
import java.io.Serializable;
import java.util.Objects;

@ -1,16 +1,14 @@
package org.acme.Hibernates.entities;
package org.acme.hibernates.entities;
import javax.persistence.*;
import org.hibernate.annotations.ColumnDefault;
@Entity
@Table(name = "throwtable")
@Table(name = "throws")
public class ThrowEntity {
@EmbeddedId
public ThrowId id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "game_id", referencedColumnName = "game_id", insertable = false, updatable = false),
@ -19,7 +17,6 @@ public class ThrowEntity {
@JoinColumn(name = "turnNumber", referencedColumnName = "turnNumber", insertable = false, updatable = false)
})
public RoundEntity round;
@ColumnDefault("0")
@Column(name = "pins")
public int pins = 0;

@ -1,4 +1,4 @@
package org.acme.Hibernates.entities;
package org.acme.hibernates.entities;
import java.io.Serializable;
import java.util.Objects;

@ -0,0 +1,67 @@
package org.acme.hibernates.entities;
import javax.persistence.*;
@Entity
@Table(name = "users", uniqueConstraints = {@UniqueConstraint(columnNames = {"name"}), @UniqueConstraint(columnNames = {"mail"})})
public class UserEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
@Column(length = 64)
private String name;
@Column(length = 255)
private String image;
@Column(length = 255)
private String mail;
@Column(length = 144)
private String password;
@OneToOne(cascade = CascadeType.ALL, mappedBy = "user", orphanRemoval = true)
public UserStatsEntity stats;
public UserEntity() {
this.stats = new UserStatsEntity(this);
}
public UserEntity(String name, String image, String mail, String password) {
this.name = name;
this.image = image;
this.mail = mail;
this.password = password;
this.stats = new UserStatsEntity(this);
}
public String getName() {
return name.substring(0, 1).toUpperCase() + name.substring(1);
}
public void setName(String name) {
this.name = name.toLowerCase();
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail.toLowerCase();
}
}

@ -1,4 +1,4 @@
package org.acme.Hibernates.entities;
package org.acme.hibernates.entities;
import org.hibernate.annotations.ColumnDefault;
@ -7,15 +7,14 @@ import java.io.Serializable;
import java.util.UUID;
@Entity
@Table(name = "user_stats")
@Table(name = "userStats")
public class UserStatsEntity {
@Id
private Long id;
@MapsId
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", referencedColumnName = "id", insertable = false, updatable = false)
@JoinColumn(name = "userId", referencedColumnName = "id")
private UserEntity user;
@ColumnDefault("0")
private Long nbVictories = 0L;
@ColumnDefault("0")
@ -33,11 +32,9 @@ public class UserStatsEntity {
public UserStatsEntity() {
}
public UserStatsEntity(UserEntity user) {
this.user = user;
}
public Long getId() {
return id;
}

@ -1,12 +1,12 @@
# achanger
quarkus.datasource.db-kind = postgresql
quarkus.datasource.username = Garderie
quarkus.datasource.password = mdp
quarkus.datasource.reactive.url = vertx-reactive:postgresql://bowldev-postgresql:5432/BowlInDB
#BowlDev-postgresql
quarkus.hibernate-orm.log.sql=true
quarkus.hibernate-orm.sql-load-script=import.sql
# #HTTPS Configuration
# quarkus.http.ssl.certificate.key-files=https/privkey.pem

@ -1,61 +1,16 @@
-- INSERT INTO users(id, name,password) VALUES (nextval('hibernate_sequence'), 'Emre','Emre');
-- INSERT INTO users(id, name,password) VALUES (nextval('hibernate_sequence'), 'Arthur','Arthur');
-- INSERT INTO users(id, name,password) VALUES (nextval('hibernate_sequence'), 'Lucas','Lucas');
-- INSERT INTO users(id, name,password) VALUES (nextval('hibernate_sequence'), 'Louison','Louison');
-- INSERT INTO users (Id, Name, Password) VALUES (1, 'Alice', 'password1'),
-- (2, 'Bob', 'password2'),
-- (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
Users (name, password, image, mail)
VALUES
('david', '38762cf7f55934b34d179ae6a4c80cadccbb7f0a2c2a5b4c4a1cb595d8dadb31','','david.d_almeida@etu.uca.fr'),
('emre', 'af7c70f8789d9e0fde5b5f18b61c5e5dc5d5c5f5e7e5c4f4be7b2cb5d57ef52c','','emre.kartal@etu.uca.fr'),
('arthur', '0cc175b9c0f1b6a831c399e269772661','','arthur.valin@etu.uca.fr');
-- INSERT INTO ThrowTable (Order, idGame, position, , pins) VALUES
-- (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 userStats (userId, avgPinsPerRound, avgScore, highscore, nbGames, nbSpares, nbStrikes, nbVictories) VALUES (1, -1, -1, 0, 0, 0, 0, 0);
INSERT INTO userStats (userId, avgPinsPerRound, avgScore, highscore, nbGames, nbSpares, nbStrikes, nbVictories) VALUES (2, -1, -1, 0, 0, 0, 0, 0);
INSERT INTO userStats (userId, avgPinsPerRound, avgScore, highscore, nbGames, nbSpares, nbStrikes, nbVictories) VALUES (3, -1, -1, 0, 0, 0, 0, 0);
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 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 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 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