From d3e48b7dba7017ca6b140db8f1b38d5ff275a9cb Mon Sep 17 00:00:00 2001 From: Mateus Felipe Date: Wed, 28 Sep 2022 21:30:53 -0300 Subject: [PATCH] Users and Carriers - Get and Post --- .../controllers/CarriersControllers.java | 12 +++ .../interfaces/CarriersRepository.java | 8 ++ frontend/main/src/app/carrier.service.ts | 12 +++ .../src/app/carriers/carriers.component.html | 37 ++++---- .../src/app/carriers/carriers.component.ts | 84 ++++++++++++------- frontend/main/src/app/quote.service.ts | 6 ++ .../main/src/app/rct-qt/rct-qt.component.html | 27 +++++- .../main/src/app/rct-qt/rct-qt.component.ts | 21 ++++- .../main/src/app/ship-qt/ship-qt.component.ts | 3 +- frontend/main/src/app/users.service.spec.ts | 16 ++++ frontend/main/src/app/users.service.ts | 29 +++++++ .../main/src/app/users/users.component.html | 15 ++-- .../main/src/app/users/users.component.ts | 65 +++++++++----- 13 files changed, 262 insertions(+), 73 deletions(-) create mode 100644 frontend/main/src/app/users.service.spec.ts create mode 100644 frontend/main/src/app/users.service.ts diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/CarriersControllers.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/CarriersControllers.java index 5a0e7ea..0def445 100644 --- a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/CarriersControllers.java +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/CarriersControllers.java @@ -3,13 +3,18 @@ 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.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import br.com.entra21.teamroxo.TMSProject.interfaces.CarriersRepository; import br.com.entra21.teamroxo.TMSProject.template.Carriers; +import br.com.entra21.teamroxo.TMSProject.template.Pessoa; @RestController @CrossOrigin(origins = "*") @@ -26,4 +31,11 @@ public List listCarriers(){ } + @PostMapping() + @ResponseStatus(code = HttpStatus.CREATED) + public Carriers register(@RequestBody Carriers dados) { + + return carriersRepository.save(dados); + + } } diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/interfaces/CarriersRepository.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/interfaces/CarriersRepository.java index 62d7a39..9aa8298 100644 --- a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/interfaces/CarriersRepository.java +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/interfaces/CarriersRepository.java @@ -1,9 +1,17 @@ package br.com.entra21.teamroxo.TMSProject.interfaces; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + import br.com.entra21.teamroxo.TMSProject.template.Carriers; public interface CarriersRepository extends JpaRepository { + +// @Query("FROM carriers WHERE idade >= :idadeParam") +// List maiorIdade (@Param("idadeParam")Integer idade); } diff --git a/frontend/main/src/app/carrier.service.ts b/frontend/main/src/app/carrier.service.ts index 0bd06ed..2662659 100644 --- a/frontend/main/src/app/carrier.service.ts +++ b/frontend/main/src/app/carrier.service.ts @@ -16,4 +16,16 @@ export class CarrierService { return this.http.get(this.apiURL) } + + adicionar(object:any){ + this.http.post(this.apiURL,object) + .subscribe((response)=>{ + + + console.log(response); + + }) + + + } } diff --git a/frontend/main/src/app/carriers/carriers.component.html b/frontend/main/src/app/carriers/carriers.component.html index 2949c89..4e87155 100644 --- a/frontend/main/src/app/carriers/carriers.component.html +++ b/frontend/main/src/app/carriers/carriers.component.html @@ -1,43 +1,52 @@ + - - + + - + + + - +
Razão socialTaxa E-mailCNPJTaxa - Tabela de freteCnpj
- + + + + +

+ + + - - - + + + + - + + - - + +
ID Razão socialTaxa E-mailCNPJTaxa - Tabela de freteAçõesCnpj
{{i}}{{carrier.name}}{{carrier.razao}}{{carrier.taxa}} {{carrier.email}} {{carrier.cnpj}}{{carrier.taxValorFrete}} - - -
\ No newline at end of file diff --git a/frontend/main/src/app/carriers/carriers.component.ts b/frontend/main/src/app/carriers/carriers.component.ts index ec78f22..b172b05 100644 --- a/frontend/main/src/app/carriers/carriers.component.ts +++ b/frontend/main/src/app/carriers/carriers.component.ts @@ -1,5 +1,8 @@ +import { HttpClient } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; +import { CarrierService } from '../carrier.service'; +import { QuoteService } from '../quote.service'; @Component({ selector: 'app-carriers', @@ -7,46 +10,65 @@ import { Router } from '@angular/router'; styleUrls: ['./carriers.component.css'] }) export class CarriersComponent implements OnInit { - carriers!:Array - name!:string - email!:string - cnpj!:string - taxValorFrete!:number - constructor( - private router:Router - ) { } + carriers!: Array + cnpj!: string + email!: string + razao!: string + taxa!: number + + constructor(public carrierService: CarrierService, public quoteService: QuoteService, private router: Router, private http: HttpClient) { } ngOnInit(): void { this.carriers = new Array() - this.carriers.push({name:"Total Express", email:"total@express.com", cnpj:"4564564566454655", taxValorFrete:0.081}) - this.carriers.push({name:"Jadlog", email:"jadlog@jadlog.com", cnpj:"4564664656565456", taxValorFrete:0.084}) - this.carriers.push({name:"Braspress", email:"braspress@braspress.com", cnpj:"1231323132312", taxValorFrete:0.089}) - this.carriers.push({name:"Correios", email:"correios@correios.com", cnpj:"7897987899789", taxValorFrete:0.078}) + // this.carriers.push({name:"Total Express", email:"total@express.com", cnpj:"4564564566454655", taxValorFrete:0.081}) + // this.carriers.push({name:"Jadlog", email:"jadlog@jadlog.com", cnpj:"4564664656565456", taxValorFrete:0.084}) + // this.carriers.push({name:"Braspress", email:"braspress@braspress.com", cnpj:"1231323132312", taxValorFrete:0.089}) + // this.carriers.push({name:"Correios", email:"correios@correios.com", cnpj:"7897987899789", taxValorFrete:0.078}) + + + this.carrierService.listCarrier().pipe().subscribe((response: any) => { + + console.log(response); + + + + var count = Object.keys(response).length; + + for (let i = 0; i < count; i++) { + + this.razao = response[i].razao; + this.taxa = response[i].taxa; + this.email = response[i].email; + this.cnpj = response[i].cnpj; + + this.carriers.push({ razao: this.razao, taxa: this.taxa, email: this.email, cnpj: this.cnpj}); + + } + + this.razao = ""; + this.taxa = 0; + this.email = ""; + this.cnpj = ""; + + }) } - adicionar(){ - if(this.name){ - this.carriers.push({name:this.name, email:this.email, cnpj:this.cnpj, taxValorFrete:this.taxValorFrete}) - this.name ="" - this.email="" - this.cnpj="" - this.taxValorFrete= 0 - } - let listaCarrier:any = [ - {name:this.name, email:this.email, cnpj:this.cnpj, taxValorFrete:this.taxValorFrete} - ] - this.router.navigate(['ship-qt', JSON.stringify(listaCarrier)]) + adicionar(razao: string, taxa: number, email: string, cnpj: string) { + + + let build ={ + "razao":razao, + "taxa":taxa, + "email":email, + "cnpj":cnpj + } - - deletar(index:number){ - this.carriers.splice(index,1) - } - - alterar(index:number){ - // this.carriers.splice(index,1) + this.carrierService.adicionar(build) + + this.carriers.push({razao:this.razao, taxa:this.taxa, email:this.email, cnpj:this.cnpj}); } } \ No newline at end of file diff --git a/frontend/main/src/app/quote.service.ts b/frontend/main/src/app/quote.service.ts index 6cfa1b6..0ae04f1 100644 --- a/frontend/main/src/app/quote.service.ts +++ b/frontend/main/src/app/quote.service.ts @@ -21,6 +21,12 @@ export class QuoteService { } + recQuote():any{ + + return this.http.get(this.apiURL) + + } + regRecentQuotes(object:any){ this.http.post(this.apiURL2+'/recent',object) .subscribe((response)=>{ diff --git a/frontend/main/src/app/rct-qt/rct-qt.component.html b/frontend/main/src/app/rct-qt/rct-qt.component.html index 1b35802..c81acf7 100644 --- a/frontend/main/src/app/rct-qt/rct-qt.component.html +++ b/frontend/main/src/app/rct-qt/rct-qt.component.html @@ -1 +1,26 @@ -

rct-qt works!

+ + + + + + + + + + + + + + + +
AçãoIDPreço do fretePrazoOrigemDestinoTransportadoraPeso cubado
\ No newline at end of file diff --git a/frontend/main/src/app/rct-qt/rct-qt.component.ts b/frontend/main/src/app/rct-qt/rct-qt.component.ts index be12925..cc30a23 100644 --- a/frontend/main/src/app/rct-qt/rct-qt.component.ts +++ b/frontend/main/src/app/rct-qt/rct-qt.component.ts @@ -1,4 +1,8 @@ +import { HttpClient } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; +import { CarrierService } from '../carrier.service'; +import { QuoteService } from '../quote.service'; @Component({ selector: 'app-rct-qt', @@ -7,9 +11,24 @@ import { Component, OnInit } from '@angular/core'; }) export class RctQtComponent implements OnInit { - constructor() { } + + constructor(public quoteService: QuoteService, private router: Router, private http: HttpClient) { } ngOnInit(): void { + + this.quoteService.recQuote().pipe().subscribe((response: any) => { + + var count = Object.keys(response).length; + + for (let i = 0; i < count; i++) { + + + + + + } + + }) } } 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 00ee164..16beccd 100644 --- a/frontend/main/src/app/ship-qt/ship-qt.component.ts +++ b/frontend/main/src/app/ship-qt/ship-qt.component.ts @@ -79,7 +79,8 @@ export class ShipQtComponent implements OnInit { console.log(this.priceFix + this.distance * response[i].taxa * this.cubagem); - this.precoFrete = this.priceFix + this.distance * response[i].taxa * this.cubagem; + this.precoFrete = (this.priceFix + this.distance * response[i].taxa * this.cubagem); + this.quotes.push({ precoFrete: this.precoFrete, tempo: this.tempo, start_adress: this.start_adress, end_address: this.end_address, carrier: response[i].razao, vol: this.vol, cubagem: this.cubagem, carrierID: response[i].id, pessoaID: this.loginService.pessoaID }); diff --git a/frontend/main/src/app/users.service.spec.ts b/frontend/main/src/app/users.service.spec.ts new file mode 100644 index 0000000..f81244a --- /dev/null +++ b/frontend/main/src/app/users.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { UsersService } from './users.service'; + +describe('UsersService', () => { + let service: UsersService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(UsersService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/frontend/main/src/app/users.service.ts b/frontend/main/src/app/users.service.ts new file mode 100644 index 0000000..2f2d66f --- /dev/null +++ b/frontend/main/src/app/users.service.ts @@ -0,0 +1,29 @@ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { Router } from '@angular/router'; + +@Injectable({ + providedIn: 'root' +}) +export class UsersService { + + apiURL:string = 'http://localhost:8080/user' + + constructor(private router: Router, private http: HttpClient) { } + + listUsers():any{ + + return this.http.get(this.apiURL) + + } + + adicionar(object:any){ + this.http.post(this.apiURL,object) + .subscribe((response)=>{ + + + console.log(response); + + }) +} +} \ No newline at end of file diff --git a/frontend/main/src/app/users/users.component.html b/frontend/main/src/app/users/users.component.html index 72942f2..9e1debe 100644 --- a/frontend/main/src/app/users/users.component.html +++ b/frontend/main/src/app/users/users.component.html @@ -3,6 +3,7 @@ Nome E-mail CPF + Data nascimento @@ -10,7 +11,8 @@ - + + @@ -19,7 +21,7 @@ - +

@@ -28,17 +30,18 @@ - + - + + diff --git a/frontend/main/src/app/users/users.component.ts b/frontend/main/src/app/users/users.component.ts index a1c6bbc..de25fa8 100644 --- a/frontend/main/src/app/users/users.component.ts +++ b/frontend/main/src/app/users/users.component.ts @@ -1,4 +1,7 @@ +import { HttpClient } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; +import { Router } from '@angular/router'; +import { UsersService } from '../users.service'; @Component({ selector: 'app-users', @@ -9,38 +12,62 @@ export class UsersComponent implements OnInit { users!:Array name!:string email!:string -cpf!:string +document!:string +birth!:string - constructor() { } + constructor(public usersService: UsersService, private router: Router, private http: HttpClient) { } ngOnInit(): void { this.users = new Array() - this.users.push({name:"Mateus Felipe", email:"mateusgoettems@gmail.com", cpf:"03215415454"}) - this.users.push({name:"Bruno Roberto", email:"bruno@gmail.com", cpf:"03215415454"}) - this.users.push({name:"Cristian Schaufer", email:"cristian@gmail.com", cpf:"03215415454"}) - this.users.push({name:"Kalil", email:"kalil@gmail.com", cpf:"03215415454"}) + this.usersService.listUsers().pipe().subscribe((response: any) => { + console.log(response); + + var count = Object.keys(response).length; + + for (let i = 0; i < count; i++) { + + this.name = response[i].nome; + this.email = response[i].email; + this.document = response[i].document; + this.birth = response[i].birth; + + this.users.push({name:this.name, email:this.email, document:this.document, birth:this.birth}); + + } + + this.name = ""; + this.email = ""; + this.document = ""; + this.birth = ""; + + }) + } - adicionar(){ - if(this.name != null && this.email != null && this.cpf != null){ - this.users.push({name:this.name, email:this.email, cpf:this.cpf}) - this.name ="" - this.email="" - this.cpf="" - }else{ - alert('DIGITE TODOS OS DADOS!') - } + adicionar(name: string, email: string, document: string, birth: string) { + + + let build ={ + "nome":name, + "email":email, + "document":document, + // "birth":birth, + } + this.usersService.adicionar(build) - deletar(index:number){ - this.users.splice(index,1) + this.users.push({name:this.name, email:this.email, document:this.document, birth:this.birth}); } - alterar(index:number){ - // this.users.splice(index,1) + deletar(){ + } + alterar(){ + + } + }
Nome E-mail CPFAçõesData nascimento
{{i}} {{user.name}} {{user.email}}{{user.cpf}}{{user.document}}{{user.birth}} - - + +