Skip to content
Merged

Kaka #15

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions backend/TMSProject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.jdbc.core.JdbcTemplate;

import br.com.entra21.teamroxo.TMSProject.interfaces.PessoaRepository;
import br.com.entra21.teamroxo.TMSProject.template.Login;
import br.com.entra21.teamroxo.TMSProject.template.Pessoa;

@SpringBootApplication
public class TmsProjectApplication implements CommandLineRunner {

public static ArrayList<Pessoa> pessoas=new ArrayList();

private static PessoaRepository pessoaRepository;

public static ArrayList<Login> login = new ArrayList();

@Autowired
private JdbcTemplate jdbc;

public static void main(String[] args) {
SpringApplication.run(TmsProjectApplication.class, args);
Expand All @@ -20,12 +29,6 @@ public static void main(String[] args) {
@Override
public void run(String... args) throws Exception {

pessoas.add(new Pessoa("Kalil", "kjfakhouri@gmail.com", (byte) 21));
pessoas.add(new Pessoa("Kalil", "kjfakhouri@gmail.com", (byte) 21));
pessoas.add(new Pessoa("Kalil", "kjfakhouri@gmail.com", (byte) 21));
pessoas.add(new Pessoa("Kalil", "kjfakhouri@gmail.com", (byte) 21));
pessoas.add(new Pessoa("Kalil", "kjfakhouri@gmail.com", (byte) 21));

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package br.com.entra21.teamroxo.TMSProject;

import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

public class WebConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {

registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST", "DELETE", "PUT");

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package br.com.entra21.teamroxo.TMSProject.controllers;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import br.com.entra21.teamroxo.TMSProject.TmsProjectApplication;
import br.com.entra21.teamroxo.TMSProject.interfaces.PessoaRepository;
import br.com.entra21.teamroxo.TMSProject.template.ItemNivel3;
import br.com.entra21.teamroxo.TMSProject.template.Login;
import br.com.entra21.teamroxo.TMSProject.template.Pessoa;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/login")
public class LoginController {

private final String PATH = "http://localhost:8080/login";

@Autowired
private PessoaRepository pessoaRepository;

@PostMapping()
@ResponseStatus(code = HttpStatus.OK)
public @ResponseBody List<Login> login(@RequestBody Login credentials){

List<Login> response = new ArrayList<Login>(pessoaRepository.findAll()).stream()
.filter(login -> (login.getUser().equals(credentials.getUser())) &&
login.getSenha().equals(credentials.getSenha()))
.toList();
response.forEach(pessoa -> {
setMaturidadeLvl3(pessoa);
});

return response;

}

@PostMapping("/register")
@ResponseStatus(code = HttpStatus.CREATED)
public @ResponseBody Pessoa register(@RequestBody Pessoa credentials){
return pessoaRepository.save(credentials);
}

private void setMaturidadeLvl3(Login pessoa) {

ArrayList<String> headers = new ArrayList<>(Arrays.asList(

"Accept:application/json",
"Content-Type:application/json"

));

ObjectMapper mapper = new ObjectMapper();

mapper.setSerializationInclusion(Include.NON_NULL);

pessoa.setLinks(null);

try {

String json = mapper.writeValueAsString(pessoa);
pessoa.setLinks(new ArrayList<>());
pessoa.getLinks().add(new ItemNivel3("POST", PATH+"/login", headers, json));

} catch (JsonProcessingException e) {
e.printStackTrace();
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -15,25 +18,34 @@
import com.fasterxml.jackson.databind.ObjectMapper;

import br.com.entra21.teamroxo.TMSProject.TmsProjectApplication;
import br.com.entra21.teamroxo.TMSProject.interfaces.PessoaRepository;
import br.com.entra21.teamroxo.TMSProject.template.ItemNivel3;
import br.com.entra21.teamroxo.TMSProject.template.Pessoa;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/login")
@RequestMapping("/user")
public class PessoaController {

private final String PATH = "http://localhost:8080/pessoas";
private final String PATH = "http://localhost:8080/users";

@Autowired
private PessoaRepository pessoaRepository;

@GetMapping()
@ResponseStatus(code = HttpStatus.OK)
public List<Pessoa>listAll(){
return obterListaCompleta();
}

@GetMapping("/{user}")
public List<Pessoa>list(@PathVariable String user){
return null;
}

private List<Pessoa> obterListaCompleta() {

List<Pessoa> response = TmsProjectApplication.pessoas.stream().toList();
List<Pessoa> response = pessoaRepository.findAll();
response.forEach(pessoa -> {
setMaturidadeNivel3(pessoa);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package br.com.entra21.teamroxo.TMSProject.interfaces;

import org.springframework.data.jpa.repository.JpaRepository;

import br.com.entra21.teamroxo.TMSProject.template.Pessoa;

public interface PessoaRepository extends JpaRepository<Pessoa, Integer> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package br.com.entra21.teamroxo.TMSProject.template;

public class Login extends MaturidadeNivel3Richardson {

private String user;
private String senha;
private boolean admin;
private boolean enterprise;

public Login() {
super();
}

public Login(String user, String senha, boolean admin, boolean enterprise) {
super();
this.user = user;
this.senha = senha;
this.admin = admin;
this.enterprise = enterprise;
}

public String getUser() {
return user;
}

public void setUser(String user) {
this.user = user;
}

public String getSenha() {
return senha;
}

public void setSenha(String senha) {
this.senha = senha;
}

public boolean isAdmin() {
return admin;
}

public void setAdmin(boolean admin) {
this.admin = admin;
}

public boolean isEnterprise() {
return enterprise;
}

public void setEnterprise(boolean enterprise) {
this.enterprise = enterprise;
}

}
Original file line number Diff line number Diff line change
@@ -1,42 +1,52 @@
package br.com.entra21.teamroxo.TMSProject.template;

public class Pessoa extends MaturidadeNivel3Richardson{
import java.time.LocalDate;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "pessoa")
public class Pessoa extends Login {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String nome;
private String email;
private byte idade;



//CONSTRUCTORS
private LocalDate birth;
private long document;

public Pessoa() {
super();
}
public Pessoa(String nome, String email, byte idade) {

public Pessoa(Integer id, String nome, String email, LocalDate birth, long document) {
super();
this.id = id;
this.nome = nome;
this.idade = idade;
this.email = email;
this.birth = birth;
this.document = document;
}

// GETTERS...

public String getNome() {
return nome;
public Integer getId() {
return id;
}

public void setNome(String nome) {
this.nome = nome;
public void setId(Integer id) {
this.id = id;
}

public int getIdade() {
return idade;
public String getNome() {
return nome;
}

public void setIdade(byte idade) {
this.idade = idade;
public void setNome(String nome) {
this.nome = nome;
}

public String getEmail() {
Expand All @@ -46,5 +56,21 @@ public String getEmail() {
public void setEmail(String email) {
this.email = email;
}

public LocalDate getBirth() {
return birth;
}

public void setBirth(LocalDate birth) {
this.birth = birth;
}

public long getDocument() {
return document;
}

public void setDocument(long document) {
this.document = document;
}

}
15 changes: 15 additions & 0 deletions backend/TMSProject/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase

spring.datasource.username=root

spring.datasource.password=Mr_kak4k0ur1


spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.jpa.hibernate.ddl-auto=update

spring.jpa.show-sql=true

spring.jpa.properties.hibernate.format_sql=true

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL57InnoDBDialect
Loading