Atualiza configuração e modelo de usuários
- Substitui application.properties por application.yaml (configuração Spring Boot em YAML) - Adiciona entidade/modelo Users com builder - Ajusta BackendApplication.java para refletir novas configurações/uso do modelo - Atualiza .gitignore para ignorar diretórios e artefatos de build e dados locais Ref.: padronização de config, preparação para persistência e melhorias de estrutura.master
parent
728d753c72
commit
06ba25eabd
|
|
@ -35,3 +35,7 @@ out/
|
|||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Database ###
|
||||
data/
|
||||
|
||||
|
|
|
|||
|
|
@ -2,12 +2,19 @@ package com.hitcommunications.servermanager;
|
|||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@SpringBootApplication
|
||||
@RestController
|
||||
public class BackendApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(BackendApplication.class, args);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String home() {
|
||||
return "Hello, World!";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
package com.hitcommunications.servermanager.model;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.hibernate.annotations.UpdateTimestamp;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
@Table(name = "tab_users")
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class Users {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.UUID)
|
||||
@Column(updatable = false, nullable = false)
|
||||
private UUID id;
|
||||
|
||||
@Column(nullable = false, unique = true)
|
||||
private String username;
|
||||
|
||||
@Column(nullable = false, unique = true, length = 100)
|
||||
private String email;
|
||||
|
||||
@Column(nullable = false, length = 20)
|
||||
private String password;
|
||||
|
||||
@Column(nullable = false, length = 30)
|
||||
private String firstName;
|
||||
|
||||
@Column(nullable = false, length = 30)
|
||||
private String lastName;
|
||||
|
||||
@CreationTimestamp
|
||||
@Column(nullable = false)
|
||||
private Timestamp createdAt;
|
||||
|
||||
@UpdateTimestamp
|
||||
@Column(nullable = false)
|
||||
private Timestamp updatedAt;
|
||||
|
||||
private Timestamp lastLogin;
|
||||
|
||||
@PrePersist
|
||||
private void prePersist() {
|
||||
if (this.username == null) {
|
||||
this.username = generateUsername();
|
||||
}
|
||||
}
|
||||
|
||||
public String generateUsername() {
|
||||
String firstPart = this.firstName != null && this.firstName.length() >= 3 ? this.firstName.substring(0, 3) : (this.firstName != null ? this.firstName : "");
|
||||
String secondPart = this.lastName != null && this.lastName.length() >= 3 ? this.lastName.substring(0, 3) : (this.lastName != null ? this.lastName : "");
|
||||
this.username = firstPart + secondPart;
|
||||
return this.username;
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +0,0 @@
|
|||
spring.application.name=backend
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
spring:
|
||||
application:
|
||||
name: backend
|
||||
datasource:
|
||||
url: jdbc:h2:file:./data/db
|
||||
driver-class-name: org.h2.Driver
|
||||
username: sa
|
||||
password:
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: update
|
||||
database-platform: org.hibernate.dialect.H2Dialect
|
||||
h2:
|
||||
console:
|
||||
enabled: true
|
||||
path: /h2-console
|
||||
|
||||
Loading…
Reference in New Issue