fix admin boolean
This commit is contained in:
@@ -53,6 +53,7 @@ public class UserController {
|
|||||||
if(createdUser == null) {
|
if(createdUser == null) {
|
||||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
createdUser.setAdmin(0);
|
||||||
return new ResponseEntity<>(createdUser, HttpStatus.CREATED);
|
return new ResponseEntity<>(createdUser, HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
package ch.progetto152.entity;
|
package ch.progetto152.entity;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.*;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@ToString
|
|
||||||
@Table(name = "User", schema = "Progetto152", catalog = "")
|
@Table(name = "User", schema = "Progetto152", catalog = "")
|
||||||
public class UserEntity {
|
public class UserEntity {
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@@ -25,12 +19,7 @@ public class UserEntity {
|
|||||||
private String password;
|
private String password;
|
||||||
@Basic
|
@Basic
|
||||||
@Column(name = "admin")
|
@Column(name = "admin")
|
||||||
private Byte admin;
|
private int admin;
|
||||||
|
|
||||||
public UserEntity(String name, String username, String password) {
|
|
||||||
this.username = username;
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
@@ -56,6 +45,14 @@ public class UserEntity {
|
|||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getAdmin() {
|
||||||
|
return admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAdmin(int admin) {
|
||||||
|
this.admin = admin;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) {
|
if (this == o) {
|
||||||
@@ -65,19 +62,11 @@ public class UserEntity {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
UserEntity that = (UserEntity) o;
|
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
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(id, username, password);
|
return Objects.hash(id, username, password, admin);
|
||||||
}
|
|
||||||
|
|
||||||
public Byte getAdmin() {
|
|
||||||
return admin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAdmin(Byte admin) {
|
|
||||||
this.admin = admin;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ create table if not exists User
|
|||||||
id int not null auto_increment,
|
id int not null auto_increment,
|
||||||
username varchar(100) not null unique,
|
username varchar(100) not null unique,
|
||||||
password varchar(100) not null,
|
password varchar(100) not null,
|
||||||
admin boolean default false,
|
admin int(1) not null default 0,
|
||||||
primary key (id)
|
primary key (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -101,7 +101,10 @@ insert into User (username, password)
|
|||||||
values ('luca.bianchi', 'password');
|
values ('luca.bianchi', 'password');
|
||||||
insert into User (username, password)
|
insert into User (username, password)
|
||||||
values ('giovanni.verdi', '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)
|
||||||
insert into Waypoints_visited (user_id, waypoint_id) values (2,2);
|
values (1, 1);
|
||||||
|
insert into Waypoints_visited (user_id, waypoint_id)
|
||||||
|
values (2, 2);
|
||||||
Reference in New Issue
Block a user