Skip to content

Commit

Permalink
Merge pull request #24 from pi-ati-ort/8-mejoras
Browse files Browse the repository at this point in the history
PR: roles
  • Loading branch information
n1colasf authored Feb 20, 2024
2 parents 52f4d15 + 2ff4fa6 commit 3634a55
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/main/java/com/pi/ati/ort/back/classes/RegisterRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ public class RegisterRequest {
private String name;
private String username;
private String password;
private String role;

public RegisterRequest() {
}

public RegisterRequest(String name, String username, String password) {
public RegisterRequest(String name, String username, String password, String role) {
this.name = name;
this.username = username;
this.password = password;
this.role = role;
}

public String getName() {
Expand All @@ -37,4 +39,12 @@ public String getPassword() {
public void setPassword(String password) {
this.password = password;
}

public String getRole() {
return role;
}

public void setRole(String role) {
this.role = role;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public ResponseEntity<User> register(@Valid @RequestBody RegisterRequest registe
user.setName(registerRequest.getName());
user.setUsername(registerRequest.getUsername());
user.setPassword(registerRequest.getPassword());
user.setRole(User.Role.valueOf(registerRequest.getRole()));

bimClient.registerUser(user.getUsername(), user.getPassword(), user.getName());
User createdUser = userService.createUser(user);
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/pi/ati/ort/back/entities/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;

import java.util.Date;

@Entity
@Table(name = "models")
public class Model {
Expand All @@ -19,6 +21,8 @@ public class Model {
private Byte file;
@NotNull
private Long size;
@NotNull
private Date created_at = new Date();

public Model() {
}
Expand Down Expand Up @@ -97,4 +101,12 @@ public Long getBimId() {
public void setBimId(Long bimId) {
this.bimId = bimId;
}

public Date getCreated_at() {
return created_at;
}

public void setCreated_at(Date created_at) {
this.created_at = created_at;
}
}
33 changes: 32 additions & 1 deletion src/main/java/com/pi/ati/ort/back/entities/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;

import java.util.Date;

@Entity
@Table(name = "users")
public class User {
Expand All @@ -16,14 +18,25 @@ public class User {
private String username;
@NotNull
private String password;
@Enumerated(EnumType.STRING)
private Role role;
@NotNull
private Date created_at = new Date();

public User() {
}

public User(Long id, String username, String password) {
public enum Role {
USER,
ADMIN
}

public User(Long id, String name, String username, String password, Role role) {
this.id = id;
this.name = name;
this.username = username;
this.password = password;
this.role = role;
}

public Long getId() {
Expand Down Expand Up @@ -58,13 +71,31 @@ public void setPassword(String password) {
this.password = password;
}

public Role getRole() {
return role;
}

public void setRole(Role role) {
this.role = role;
}

public Date getCreated_at() {
return created_at;
}

public void setCreated_at(Date created_at) {
this.created_at = created_at;
}

@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", username='" + username + '\'' +
", password='" + password + '\'' +
", role=" + role +
", created_at=" + created_at +
'}';
}
}

0 comments on commit 3634a55

Please sign in to comment.