Skip to content

Commit

Permalink
Use only id autogenerated
Browse files Browse the repository at this point in the history
  • Loading branch information
isabellerobin committed Feb 3, 2020
1 parent 72efa04 commit a11fb25
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 52 deletions.
34 changes: 16 additions & 18 deletions back/src/main/java/com/crecerjuntos/model/Achievement.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,46 +27,44 @@ public int hashCode() {
/** Unique, private & generated id */
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private final Long id;
private Long id;

@ManyToOne
@JoinColumn(name = "student_id", nullable = false)
private final Student student;
private Student student;

/** Session id */
private final String sessionId;
private String sessionId;

/** Timestamp of the achievement */
private final Date timestamp;
private Date timestamp;

/** Name of the current exercise */
@Column(nullable = false)
private final String exercise;
private String exercise;

/** Level of the current exercise, default : 1 */
@Column(columnDefinition = "integer default 1")
private final int level;
private int level;

/** Progression should be between 0 and 100 */
private final double progress;
private double progress;

/** Score, should be between 0 and 100 */
private final int score;
private int score;

public Achievement() {
this(0L, new Student(), "0", Date.valueOf(LocalDate.now()), "No exercise", 0, 0, 0);
this(new Student(), "0", Date.valueOf(LocalDate.now()), "No exercise", 0, 0, 0);
}

public Achievement(
final Long id,
final Student student,
final String sessionId,
final Date timestamp,
final String exercise,
final int level,
final double progress,
final int score) {
this.id = id;
Student student,
String sessionId,
Date timestamp,
String exercise,
int level,
double progress,
int score) {
this.student = student;
this.sessionId = sessionId;
this.timestamp = timestamp;
Expand Down
38 changes: 13 additions & 25 deletions back/src/main/java/com/crecerjuntos/model/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,70 +11,58 @@ public class Student implements BaseEntity {
public static final String DEFAULT_NAME = "Anonymous";
public static final String DEFAULT_MAIL = "anonymous@gmail.com";
public static final Student DEFAULT =
new Student(1L, DEFAULT_NAME, DEFAULT_MAIL, "", Section.DEFAULT);
new Student(DEFAULT_NAME, DEFAULT_MAIL, "", Section.DEFAULT);

/** Private generated id */
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private final Long id;
private Long id;

/** Public first name */
@Column(nullable = false)
private final String name;
private String name;

/** Email address */
@Column(unique = true, nullable = false)
private final String mail;
private String mail;

/** Password */
@Column(nullable = false)
private final String password;
private String password;

/** Id of the associated section */
@Enumerated(EnumType.STRING)
private final Section section;
private Section section;

public Student() {
this(0L, DEFAULT_NAME, Section.DEFAULT);
this(DEFAULT_NAME, DEFAULT_MAIL, "", Section.DEFAULT);
}

public Student(
final Long id,
final String name,
final String mail,
final String password,
final Section section) {
this.id = id;
String name,
String mail,
String password,
Section section) {
this.name = name;
this.mail = mail;
this.password = password;
this.section = section;
}

public Student(final Long id, final String name, final Section section) {
this.id = id;
public Student(final String name, final Section section) {
this.name = name;
this.mail = DEFAULT_MAIL;
this.password = null;
this.section = section;
}

public Student(final Long id, final String name) {
this.id = id;
public Student(final String name) {
this.name = name;
this.mail = DEFAULT_MAIL;
this.password = null;
this.section = Section.DEFAULT;
}

public Student(final Long id) {
this.id = id;
this.name = DEFAULT_NAME;
this.mail = DEFAULT_MAIL;
this.password = null;
this.section = Section.DEFAULT;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public void create() throws Exception{
double progress = TestServices.random.nextInt(100);
Achievement achievement =
new Achievement(
TestServices.random.nextLong(),
student,
"session",
date,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void setUp() {
studentService = new StudentService(studentRepository);

// Add a test student in repository
Student testStudent = new Student(1234L, "Pedro test", Section.DEFAULT);
Student testStudent = new Student("Pedro test", Section.DEFAULT);
List<Student> studentList = new ArrayList<>();
studentList.add(testStudent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class TestServices {
public static final Student generateTestStudent() throws Exception{
String mail = "student.test" + UUID.randomUUID() + "@gmail.com";
Student student =
new Student(random.nextLong(), "Test Student", mail, "password", Section.DEFAULT);
new Student("Test Student", mail, "password", Section.DEFAULT);
authoringServices.add(student);
return studentAccess.byMail(mail);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public static Student create(
String mail, final String username, final String password, final String section)
throws DataBaseException {
// Create student
long id = random.nextLong();
Student student = new Student(id, username, mail, password, Section.fromString(section));
Student student = new Student(username, mail, password, Section.fromString(section));

// Register new student in database
logger.info("Create Student User {}", student);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ public class ProgressServices {
private static final IAchievementAccess achievementAccess = new AchievementService();

public static void start(final Exercise exercise, final int level) throws DataBaseException {
long id = random.nextLong();
VaadinSession session = UI.getCurrent().getSession();
Student student = LoginServices.getStudent();
Achievement achievement =
new Achievement(
id,
student,
session.getSession().getId(),
new java.sql.Date(Calendar.getInstance().getTime().getTime()),
Expand All @@ -44,12 +42,10 @@ public static void start(final Exercise exercise, final int level) throws DataBa
}

public static void end(final Exercise exercise, final int level, final int score) throws DataBaseException{
long id = random.nextLong();
VaadinSession session = UI.getCurrent().getSession();
Student student = LoginServices.getStudent();
Achievement achievement =
new Achievement(
id,
student,
session.getSession().getId(),
new java.sql.Date(Calendar.getInstance().getTime().getTime()),
Expand Down

0 comments on commit a11fb25

Please sign in to comment.