From 4f3c733a2f6736417004a1503b762f7edaa2fc31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20D=C3=ADaz=20N=C3=BA=C3=B1ez?= Date: Fri, 1 Mar 2024 01:04:26 +0100 Subject: [PATCH 1/2] Add GameSession entity --- .../java/com/uniovi/entities/GameSession.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/com/uniovi/entities/GameSession.java diff --git a/src/main/java/com/uniovi/entities/GameSession.java b/src/main/java/com/uniovi/entities/GameSession.java new file mode 100644 index 00000000..aa218e48 --- /dev/null +++ b/src/main/java/com/uniovi/entities/GameSession.java @@ -0,0 +1,36 @@ +package com.uniovi.entities; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotEmpty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.time.LocalDateTime; + +@Getter +@Setter +@Entity +@NoArgsConstructor +public class GameSession { + + @Id + @GeneratedValue + private Long id; + + @ManyToOne + private Player player; + + private Integer correctQuestions; + private Integer totalQuestions; + + private LocalDateTime createdAt; + private LocalDateTime updateAt; + + public void addQuestion(boolean correct) { + if(correct) + correctQuestions++; + totalQuestions++; + } + +} From 48a43e6b7b92db7626c71566e9365dcf29f9ddde Mon Sep 17 00:00:00 2001 From: Pelayori <31128562+Pelayori@users.noreply.github.com> Date: Sat, 2 Mar 2024 17:41:19 +0100 Subject: [PATCH 2/2] Add new member to player to match GameSession new entity --- src/main/java/com/uniovi/entities/Player.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/uniovi/entities/Player.java b/src/main/java/com/uniovi/entities/Player.java index eba49c42..8c953f26 100644 --- a/src/main/java/com/uniovi/entities/Player.java +++ b/src/main/java/com/uniovi/entities/Player.java @@ -35,6 +35,9 @@ public class Player { inverseJoinColumns={@JoinColumn(name="ROLE_ID", referencedColumnName="NAME")}) private Set roles = new HashSet<>(); + @OneToMany(mappedBy = "player") + private Set gameSessions = new HashSet<>(); + // Transient: no se almacena en la base de datos @Transient private String passwordConfirm;