Skip to content

Commit

Permalink
Merge pull request #98 from Arquisoft/entities-develop
Browse files Browse the repository at this point in the history
Add GameSession entity
  • Loading branch information
Pelayori authored Mar 2, 2024
2 parents 7a342da + 48a43e6 commit bf49983
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/main/java/com/uniovi/entities/GameSession.java
Original file line number Diff line number Diff line change
@@ -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++;
}

}
3 changes: 3 additions & 0 deletions src/main/java/com/uniovi/entities/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class Player {
inverseJoinColumns={@JoinColumn(name="ROLE_ID", referencedColumnName="NAME")})
private Set<Role> roles = new HashSet<>();

@OneToMany(mappedBy = "player")
private Set<GameSession> gameSessions = new HashSet<>();

// Transient: no se almacena en la base de datos
@Transient
private String passwordConfirm;
Expand Down

0 comments on commit bf49983

Please sign in to comment.