From 5c84ccb317e2f96e8c8e8403978ec9e16f56a53c Mon Sep 17 00:00:00 2001 From: kaka-jaques Date: Fri, 23 Sep 2022 07:15:54 -0300 Subject: [PATCH 1/2] UPDATE! API CONNECT ON ONLINE DB! LOGIN API - WORKING! REGISTERING API - LOADING... --- .../controllers/LoginController.java | 17 ++-- .../controllers/PessoaController.java | 16 ++++ .../controllers/RegisterController.java | 17 ++++ .../teamroxo/TMSProject/template/Login.java | 2 + .../teamroxo/TMSProject/template/Pessoa.java | 3 + .../src/main/resources/application.properties | 4 +- .../main/src/app/login/login.component.ts | 11 ++- frontend/main/src/app/loginservice.service.ts | 41 +++++++-- .../src/app/ship-qt/ship-qt.component.html | 83 +++++++++--------- .../main/src/app/ship-qt/ship-qt.component.ts | 85 ++++++++++++------- 10 files changed, 190 insertions(+), 89 deletions(-) diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/LoginController.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/LoginController.java index 57576d2..d9dd2b6 100644 --- a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/LoginController.java +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/LoginController.java @@ -7,6 +7,7 @@ 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.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -17,6 +18,8 @@ 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.LoginRepository; @@ -38,6 +41,11 @@ public class LoginController { @Autowired private LoginRepository loginRepository; + @GetMapping + public List listAll() { + return loginRepository.findAll(); + } + @PostMapping() @ResponseStatus(code = HttpStatus.OK) public @ResponseBody List login(@RequestBody Login credentials){ @@ -53,12 +61,6 @@ public class LoginController { return response; } - - @PostMapping("/register") - @ResponseStatus(code = HttpStatus.CREATED) - public @ResponseBody Pessoa register(@RequestBody Pessoa credentials){ - return pessoaRepository.save(credentials); - } private void setMaturidadeLvl3(Login pessoa) { @@ -70,7 +72,8 @@ private void setMaturidadeLvl3(Login pessoa) { )); ObjectMapper mapper = new ObjectMapper(); - + mapper.registerModule(new JavaTimeModule()); + mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.setSerializationInclusion(Include.NON_NULL); pessoa.setLinks(null); diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/PessoaController.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/PessoaController.java index fb80d71..a52a2be 100644 --- a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/PessoaController.java +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/PessoaController.java @@ -9,6 +9,8 @@ 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.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseStatus; @@ -47,6 +49,20 @@ public Optional list(@PathVariable int id){ return pessoaRepository.findById(id); } + + @GetMapping("/last") + public List lastUser() { + + return pessoaRepository.findAll(); + } + + @PostMapping() + @ResponseStatus(code = HttpStatus.CREATED) + public Pessoa register(@RequestBody Pessoa dados) { + + return pessoaRepository.save(dados); + + } private List obterListaCompleta() { diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/RegisterController.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/RegisterController.java index da9c759..41f7da4 100644 --- a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/RegisterController.java +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/RegisterController.java @@ -1,5 +1,7 @@ package br.com.entra21.teamroxo.TMSProject.controllers; +import java.util.Optional; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.CrossOrigin; @@ -10,7 +12,9 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import br.com.entra21.teamroxo.TMSProject.interfaces.LoginRepository; import br.com.entra21.teamroxo.TMSProject.interfaces.PessoaRepository; +import br.com.entra21.teamroxo.TMSProject.template.Login; import br.com.entra21.teamroxo.TMSProject.template.Pessoa; @RestController @@ -23,10 +27,23 @@ public class RegisterController { @Autowired private PessoaRepository pessoaRepository; + @Autowired + private LoginRepository loginRepository; + @PostMapping() @ResponseStatus(code = HttpStatus.CREATED) public @ResponseBody Pessoa register(@RequestBody Pessoa credentials){ + return pessoaRepository.save(credentials); + + } + + @PostMapping("/login") + @ResponseStatus(code = HttpStatus.CREATED) + public Login registerLogin(@RequestBody Login credentials) { + + return loginRepository.save(credentials); + } } diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/Login.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/Login.java index ab8c655..0cfa538 100644 --- a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/Login.java +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/Login.java @@ -1,5 +1,6 @@ package br.com.entra21.teamroxo.TMSProject.template; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -13,6 +14,7 @@ public class Login extends MaturidadeNivel3Richardson { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; + @Column(unique = true) private String user; private String senha; private boolean admin; diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/Pessoa.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/Pessoa.java index c282a8f..1fe3626 100644 --- a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/Pessoa.java +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/Pessoa.java @@ -2,6 +2,7 @@ import java.time.LocalDate; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; @@ -19,8 +20,10 @@ public class Pessoa extends MaturidadeNivel3Richardson { @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private String nome; + @Column(unique = true) private String email; private LocalDate birth; + @Column(unique = true) private String document; public Pessoa() { diff --git a/backend/TMSProject/src/main/resources/application.properties b/backend/TMSProject/src/main/resources/application.properties index a55f04f..aafc792 100644 --- a/backend/TMSProject/src/main/resources/application.properties +++ b/backend/TMSProject/src/main/resources/application.properties @@ -1,8 +1,8 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/mydatabase +spring.datasource.url=jdbc:mysql://34.151.219.66/mydatabase spring.datasource.username=root -spring.datasource.password=Mr_kak4k0ur1 +spring.datasource.password=Tms@2022 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver diff --git a/frontend/main/src/app/login/login.component.ts b/frontend/main/src/app/login/login.component.ts index 390646b..d01c799 100644 --- a/frontend/main/src/app/login/login.component.ts +++ b/frontend/main/src/app/login/login.component.ts @@ -50,7 +50,7 @@ export class LoginComponent implements OnInit { } register(){ - if(this.nameReg != null && this.emailReg != null && this.passwordReg != null){ + if(this.nameReg != null && this.emailReg != null && this.passwordReg != null && this.userReg != null){ this.loginService.registering(this.nameReg, this.userReg , this.emailReg, this.passwordReg) .pipe( catchError((error)=>{ @@ -58,7 +58,16 @@ export class LoginComponent implements OnInit { }) ) .subscribe((response:any)=>{ + console.log(response); + console.log('Successful Login!'); + if(response == ""){ + this.loginService.progress = false; + alert("ERRO!") + }else{ + this.loginService.succeed = true + this.gotoHome() + } }); }else{ alert('DIGITE TODOS OS CAMPOS OBRIGATÓRIOS!') diff --git a/frontend/main/src/app/loginservice.service.ts b/frontend/main/src/app/loginservice.service.ts index f1437a2..ed99515 100644 --- a/frontend/main/src/app/loginservice.service.ts +++ b/frontend/main/src/app/loginservice.service.ts @@ -45,28 +45,59 @@ export class LoginserviceService implements CanActivate { return this.http.post(this.TMSLoginAPI +'/login', build) } - registering(name:string ,user: string, password: string, email: string) { + registering(name:string ,user: string, email: string, password: string) { this.progress = true + let userId!:number; + let build:any = { - 'name':name, 'user':user, - 'password':password, + 'senha':password + } + + let buildPessoa:any = { + 'nome':name, 'email':email } - this.http.post(this.TMSLoginAPI+'/register', build) + this.http.post(this.TMSLoginAPI+'/register', buildPessoa) + .pipe( + catchError((error)=>{ + return error + }) + ) + .subscribe((response:any)=>{ + return response + }) + + this.http.get(this.TMSLoginAPI +'/user/last') + .subscribe((response:any)=>{ + console.log(response); + + userId = response.id + }) + + let buildLogin:any = { + 'user':user, + 'senha':password, + 'admin': 0, + 'enterprise': 0, + 'pessoa_id': userId + } + + this.http.post(this.TMSLoginAPI+'/register/login', buildLogin) .pipe( catchError((error)=>{ return error }) ) .subscribe((response)=>{ + this.user = name return response }) - return build + return this.http.post(this.TMSLoginAPI +'/login', build) } diff --git a/frontend/main/src/app/ship-qt/ship-qt.component.html b/frontend/main/src/app/ship-qt/ship-qt.component.html index 8e4fa8a..2172d2d 100644 --- a/frontend/main/src/app/ship-qt/ship-qt.component.html +++ b/frontend/main/src/app/ship-qt/ship-qt.component.html @@ -1,49 +1,48 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + +
CEP de origemCEP de destinoComprimento (cm)Largura (cm)Altura (cm)Peso (kg)
CEP de origemCEP de destinoComprimento (cm)Largura (cm)Altura (cm)Peso (kg)
+

- - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + +
IDPreço do fretePrazoOrigemDestinoComprimento (cm)Largura (cm)Altura (cm)Peso (kg)
{{i}}R${{quote.precoFrete}}{{quote.durationTime}} dias úteis{{quote.startAdress}}{{quote.endAdress}}{{quote.comprimento}}{{quote.largura}}{{quote.altura}}{{quote.peso}}
IDPreço do fretePrazoOrigemDestinoTransportadoraPeso cubado
{{i}}R${{quote.precoFrete}}{{quote.tempo}} dias úteis{{quote.start_adress}}{{quote.end_address}}{{quote.carrier}}{{quote.cubagem}} kg
diff --git a/frontend/main/src/app/ship-qt/ship-qt.component.ts b/frontend/main/src/app/ship-qt/ship-qt.component.ts index 22e3139..ace0af0 100644 --- a/frontend/main/src/app/ship-qt/ship-qt.component.ts +++ b/frontend/main/src/app/ship-qt/ship-qt.component.ts @@ -1,8 +1,6 @@ import { HttpClient } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; -import { ActivatedRoute } from '@angular/router'; import { catchError, of } from 'rxjs'; -import { CarriersComponent } from '../carriers/carriers.component'; import { QuoteService } from '../quote.service'; @Component({ @@ -10,6 +8,7 @@ import { QuoteService } from '../quote.service'; templateUrl: './ship-qt.component.html', styleUrls: ['./ship-qt.component.css'] }) + export class ShipQtComponent implements OnInit { quotes!: Array cepOrigem!: string @@ -20,49 +19,71 @@ export class ShipQtComponent implements OnInit { peso!: number precoFrete!: number tempo!: number - trackid!: string - startAdress!: string - endAdress!: string - durationTime!:number - distanceKm!:string + end_address!:string + start_adress!:string + taxQuote!:number + carrier!:string + vol!:number + cubagem!:number + priceFix!:number + fatorCub!:number + - constructor( - public quoteService: QuoteService, private activatedRoute: ActivatedRoute - ) { } + constructor(public quoteService:QuoteService) {} ngOnInit(): void { - this.quotes = new Array(); - //this.quotes.push({ precoFrete: 45.50, tempo: 3, trackid: "BR23154546TR", cepOrigem: 88058086, cepDestino: 88058086, comprimento: 50, largura: 50, altura: 50, peso: 10 }) - //this.quotes.push({ precoFrete: 94.50, tempo: 6, trackid: "BR22315445TR", cepOrigem: 46513265, cepDestino: 65898454, comprimento: 100, largura: 200, altura: 10, peso: 25 }) + this.quotes = new Array() + //this.quotes.push({ precoFrete: 45.50, tempo: 3, trackid: "BR23154546TR", cepOrigem: 88058086, cepDestino: 88058086, comprimento: 50, largura: 50, altura: 50, peso: 10 }) + //this.quotes.push({ precoFrete: 94.50, tempo: 6, trackid: "BR22315445TR", cepOrigem: 46513265, cepDestino: 65898454, comprimento: 100, largura: 200, altura: 10, peso: 25 }) } quote() { - if (this.cepOrigem != null && this.cepDestino != null) { + + if(this.cepOrigem != null && this.cepDestino != null){ this.quoteService.quote(this.cepOrigem, this.cepDestino) - .pipe() - .subscribe((response: any) => { - console.log(response); - console.log(response.routes[0].legs[0].duration.text); - console.log(response.routes[0].legs[0].distance.text); - console.log(response.routes[0].legs[0].start_address); - console.log(response.routes[0].legs[0].end_address); + .pipe() + .subscribe((response:any) => { + console.log(response); + console.log(response.routes[0].legs[0].distance.value); + console.log(response.routes[0].legs[0].duration.value); + + this.fatorCub = 300; //fator cubado - rodoviário + this.taxQuote = 0.041; + this.carrier= "Total Express"; + this.priceFix = 14.55; + + this.start_adress = response.routes[0].legs[0].start_address; + this.end_address = response.routes[0].legs[0].end_address; + + this.vol = (this.comprimento*this.altura*this.largura)/1000000; + + this.cubagem = this.vol*this.fatorCub; + console.log(this.cubagem); + + + this.tempo = Math.ceil((((response.routes[0].legs[0].distance.value)/1000)/80)/7); //dividido por 1000 para converter, /80 velocidade med, /7 horas diárias + this.precoFrete = this.priceFix + ((response.routes[0].legs[0].distance.value/10000)*this.taxQuote)*(this.cubagem); + + console.log(this.tempo); + console.log(this.precoFrete); + + - this.durationTime = response.routes[0].legs[0].duration.value; - this.distanceKm = response.routes[0].legs[0].distance.value; - this.startAdress = response.routes[0].legs[0].start_address; - this.endAdress = response.routes[0].legs[0].end_address; + // this.quotes.push({precoFrete:this.precoFrete, tempo:this.tempo , start_adress:this.start_adress, end_address:this.end_address}) + this.quotes.push({precoFrete:this.precoFrete, tempo:this.tempo , start_adress:this.start_adress, end_address:this.end_address, carrier:this.carrier, vol:this.vol, cubagem:this.cubagem}); + this.cepDestino="" + this.cepOrigem="" + this.comprimento=0 + this.largura=0 + this.altura=0 + this.peso=0 - this.precoFrete = (parseFloat(this.distanceKm)/1000) * 0.081; - console.log(this.precoFrete); - this.durationTime = Math.ceil((parseFloat(this.distanceKm)/500)/1000); - console.log(this.durationTime); - this.quotes.push({precoFrete:this.precoFrete, durationTime:this.durationTime, startAdress:this.startAdress, endAdress:this.endAdress, comprimento:this.comprimento, largura:this.largura, altura:this.altura, peso:this.peso}) - }) - } else { + }) + }else{ alert('DIGITE TODOS OS DADOS!') } From ca00a2867b9a34d9aec148d632b1a325266eb86f Mon Sep 17 00:00:00 2001 From: kaka-jaques Date: Fri, 23 Sep 2022 19:25:37 -0300 Subject: [PATCH 2/2] UPDATE! REGISTERING WORKING! --- .../controllers/PessoaController.java | 6 --- .../controllers/RegisterController.java | 21 ++++---- .../TMSProject/template/Register.java | 54 +++++++++++++++++++ frontend/main/src/app/loginservice.service.ts | 39 ++------------ 4 files changed, 68 insertions(+), 52 deletions(-) create mode 100644 backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/Register.java diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/PessoaController.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/PessoaController.java index a52a2be..876932c 100644 --- a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/PessoaController.java +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/PessoaController.java @@ -50,12 +50,6 @@ public Optional list(@PathVariable int id){ } - @GetMapping("/last") - public List lastUser() { - - return pessoaRepository.findAll(); - } - @PostMapping() @ResponseStatus(code = HttpStatus.CREATED) public Pessoa register(@RequestBody Pessoa dados) { diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/RegisterController.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/RegisterController.java index 41f7da4..bf4cf1f 100644 --- a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/RegisterController.java +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/RegisterController.java @@ -16,13 +16,12 @@ import br.com.entra21.teamroxo.TMSProject.interfaces.PessoaRepository; import br.com.entra21.teamroxo.TMSProject.template.Login; import br.com.entra21.teamroxo.TMSProject.template.Pessoa; +import br.com.entra21.teamroxo.TMSProject.template.Register; @RestController @CrossOrigin(origins = "*") @RequestMapping("/register") public class RegisterController { - - private final String PATH = "http://localhost:8080/register"; @Autowired private PessoaRepository pessoaRepository; @@ -32,17 +31,17 @@ public class RegisterController { @PostMapping() @ResponseStatus(code = HttpStatus.CREATED) - public @ResponseBody Pessoa register(@RequestBody Pessoa credentials){ - - return pessoaRepository.save(credentials); + public @ResponseBody Login register(@RequestBody Register credentials){ - } - - @PostMapping("/login") - @ResponseStatus(code = HttpStatus.CREATED) - public Login registerLogin(@RequestBody Login credentials) { + Pessoa pessoa = new Pessoa(); + Login login = new Login(); - return loginRepository.save(credentials); + pessoa.setNome(credentials.getNome()); + pessoa.setEmail(credentials.getEmail()); + login.setPessoa_id(pessoaRepository.save(pessoa).getId()); + login.setUser(credentials.getUser()); + login.setSenha(credentials.getSenha()); + return loginRepository.save(login); } diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/Register.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/Register.java new file mode 100644 index 0000000..868c1f4 --- /dev/null +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/Register.java @@ -0,0 +1,54 @@ +package br.com.entra21.teamroxo.TMSProject.template; + +public class Register { + + private String nome; + private String user; + private String email; + private String senha; + + public Register() { + super(); + } + + public Register(String nome, String user, String email, String senha) { + super(); + this.nome = nome; + this.user = user; + this.email = email; + this.senha = senha; + } + + public String getNome() { + return nome; + } + + public void setNome(String nome) { + this.nome = nome; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getSenha() { + return senha; + } + + public void setSenha(String senha) { + this.senha = senha; + } + +} diff --git a/frontend/main/src/app/loginservice.service.ts b/frontend/main/src/app/loginservice.service.ts index ed99515..04062d8 100644 --- a/frontend/main/src/app/loginservice.service.ts +++ b/frontend/main/src/app/loginservice.service.ts @@ -49,19 +49,14 @@ export class LoginserviceService implements CanActivate { this.progress = true - let userId!:number; - let build:any = { + 'nome':name, 'user':user, + 'email':email, 'senha':password } - let buildPessoa:any = { - 'nome':name, - 'email':email - } - - this.http.post(this.TMSLoginAPI+'/register', buildPessoa) + this.http.post(this.TMSLoginAPI+'/register', build) .pipe( catchError((error)=>{ return error @@ -71,33 +66,7 @@ export class LoginserviceService implements CanActivate { return response }) - this.http.get(this.TMSLoginAPI +'/user/last') - .subscribe((response:any)=>{ - console.log(response); - - userId = response.id - }) - - let buildLogin:any = { - 'user':user, - 'senha':password, - 'admin': 0, - 'enterprise': 0, - 'pessoa_id': userId - } - - this.http.post(this.TMSLoginAPI+'/register/login', buildLogin) - .pipe( - catchError((error)=>{ - return error - }) - ) - .subscribe((response)=>{ - this.user = name - return response - }) - - return this.http.post(this.TMSLoginAPI +'/login', build) + return this.http.get(this.TMSLoginAPI +'/login', build) }