Skip to content
Merged
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,90 @@
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.LoginRepository;
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;

@Autowired
private LoginRepository loginRepository;

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

List<Login> response = new ArrayList<Login>(loginRepository.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 @@ -2,38 +2,55 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

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;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

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("/{id}")
public Optional<Pessoa> list(@PathVariable int id){

return pessoaRepository.findById(id);

}

private List<Pessoa> obterListaCompleta() {

List<Pessoa> response = TmsProjectApplication.pessoas.stream().toList();
List<Pessoa> response = pessoaRepository.findAll();
response.forEach(pessoa -> {
setMaturidadeNivel3(pessoa);
});
Expand All @@ -48,6 +65,8 @@ private void setMaturidadeNivel3(Pessoa pessoa) {
headers.add("Accept : application/json");
headers.add("Content-type : application/json");
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.setSerializationInclusion(Include.NON_NULL);

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package br.com.entra21.teamroxo.TMSProject.controllers;

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 br.com.entra21.teamroxo.TMSProject.interfaces.PessoaRepository;
import br.com.entra21.teamroxo.TMSProject.template.Pessoa;

@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/register")
public class RegisterController {

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

@Autowired
private PessoaRepository pessoaRepository;

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

}
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.Login;

public interface LoginRepository extends JpaRepository<Login, Integer> {

}
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,84 @@
package br.com.entra21.teamroxo.TMSProject.template;

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

@Entity
@Table(name = "login")
public class Login extends MaturidadeNivel3Richardson {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String user;
private String senha;
private boolean admin;
private boolean enterprise;
private Integer pessoa_id;

public Login() {
super();
}

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

public Integer getId() {
return id;
}

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

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;
}

public Integer getPessoa_id() {
return pessoa_id;
}

public void setPessoa_id(Integer pessoa_id) {
this.pessoa_id = pessoa_id;
}

}
Loading