fix admin boolean

This commit is contained in:
2023-05-05 11:29:09 +02:00
parent d9e90f0874
commit 77be681498
3 changed files with 19 additions and 26 deletions

View File

@@ -53,6 +53,7 @@ public class UserController {
if(createdUser == null) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
createdUser.setAdmin(0);
return new ResponseEntity<>(createdUser, HttpStatus.CREATED);
}

View File

@@ -1,16 +1,10 @@
package ch.progetto152.entity;
import jakarta.persistence.*;
import lombok.*;
import java.util.Objects;
@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@ToString
@Table(name = "User", schema = "Progetto152", catalog = "")
public class UserEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@@ -25,12 +19,7 @@ public class UserEntity {
private String password;
@Basic
@Column(name = "admin")
private Byte admin;
public UserEntity(String name, String username, String password) {
this.username = username;
this.password = password;
}
private int admin;
public int getId() {
return id;
@@ -56,6 +45,14 @@ public class UserEntity {
this.password = password;
}
public int getAdmin() {
return admin;
}
public void setAdmin(int admin) {
this.admin = admin;
}
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -65,19 +62,11 @@ public class UserEntity {
return false;
}
UserEntity that = (UserEntity) o;
return id == that.id && Objects.equals(username, that.username) && Objects.equals(password, that.password);
return id == that.id && admin == that.admin && Objects.equals(username, that.username) && Objects.equals(password, that.password);
}
@Override
public int hashCode() {
return Objects.hash(id, username, password);
}
public Byte getAdmin() {
return admin;
}
public void setAdmin(Byte admin) {
this.admin = admin;
return Objects.hash(id, username, password, admin);
}
}

View File

@@ -31,7 +31,7 @@ create table if not exists User
id int not null auto_increment,
username varchar(100) not null unique,
password varchar(100) not null,
admin boolean default false,
admin int(1) not null default 0,
primary key (id)
);
@@ -101,7 +101,10 @@ insert into User (username, password)
values ('luca.bianchi', 'password');
insert into User (username, password)
values ('giovanni.verdi', 'password');
insert into User (username, password, admin) values ('Joe', 'admin', true);
insert into User (username, password, admin)
values ('Joe', 'admin', true);
insert into Waypoints_visited (user_id, waypoint_id) values (1,1);
insert into Waypoints_visited (user_id, waypoint_id) values (2,2);
insert into Waypoints_visited (user_id, waypoint_id)
values (1, 1);
insert into Waypoints_visited (user_id, waypoint_id)
values (2, 2);