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 new file mode 100644 index 0000000..5a0e7ea --- /dev/null +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/CarriersControllers.java @@ -0,0 +1,29 @@ +package br.com.entra21.teamroxo.TMSProject.controllers; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import br.com.entra21.teamroxo.TMSProject.interfaces.CarriersRepository; +import br.com.entra21.teamroxo.TMSProject.template.Carriers; + +@RestController +@CrossOrigin(origins = "*") +@RequestMapping("/carriers") +public class CarriersControllers { + + @Autowired + private CarriersRepository carriersRepository; + + @GetMapping() + public List listCarriers(){ + + return carriersRepository.findAll(); + + } + +} 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 d9dd2b6..54c26fa 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 @@ -22,8 +22,10 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import br.com.entra21.teamroxo.TMSProject.TmsProjectApplication; +import br.com.entra21.teamroxo.TMSProject.interfaces.CountVisitorsRepository; import br.com.entra21.teamroxo.TMSProject.interfaces.LoginRepository; import br.com.entra21.teamroxo.TMSProject.interfaces.PessoaRepository; +import br.com.entra21.teamroxo.TMSProject.template.CountVisitors; import br.com.entra21.teamroxo.TMSProject.template.ItemNivel3; import br.com.entra21.teamroxo.TMSProject.template.Login; import br.com.entra21.teamroxo.TMSProject.template.Pessoa; @@ -36,10 +38,10 @@ public class LoginController { private final String PATH = "http://localhost:8080/login"; @Autowired - private PessoaRepository pessoaRepository; + private LoginRepository loginRepository; @Autowired - private LoginRepository loginRepository; + private CountVisitorsRepository countVisitorsRepository; @GetMapping public List listAll() { @@ -58,6 +60,12 @@ public List listAll() { setMaturidadeLvl3(pessoa); }); + if(!response.isEmpty()) { + CountVisitors count = new CountVisitors(); + count.setCount(0); + countVisitorsRepository.save(count); + } + return response; } 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 876932c..cb3313c 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 @@ -23,6 +23,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import br.com.entra21.teamroxo.TMSProject.TmsProjectApplication; +import br.com.entra21.teamroxo.TMSProject.interfaces.CountVisitorsRepository; import br.com.entra21.teamroxo.TMSProject.interfaces.PessoaRepository; import br.com.entra21.teamroxo.TMSProject.template.ItemNivel3; import br.com.entra21.teamroxo.TMSProject.template.Pessoa; @@ -37,6 +38,9 @@ public class PessoaController { @Autowired private PessoaRepository pessoaRepository; + @Autowired + private CountVisitorsRepository countVisitorsRepository; + @GetMapping() @ResponseStatus(code = HttpStatus.OK) public ListlistAll(){ @@ -45,9 +49,17 @@ public class PessoaController { @GetMapping("/{id}") public Optional list(@PathVariable int id){ - return pessoaRepository.findById(id); - + } + + @GetMapping("/countClients") + public long numberClients() { + return pessoaRepository.count(); + } + + @GetMapping("/countVisitors") + public long numberVisitors() { + return countVisitorsRepository.count(); } @PostMapping() diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/ShipController.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/ShipController.java new file mode 100644 index 0000000..64dfcd9 --- /dev/null +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/controllers/ShipController.java @@ -0,0 +1,64 @@ +package br.com.entra21.teamroxo.TMSProject.controllers; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import javax.net.ssl.HttpsURLConnection; + +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.RestController; + +@RestController +@CrossOrigin(origins = "*") +@RequestMapping("/ship") +public class ShipController { + + final String GOOGLE = "https://maps.googleapis.com/maps/api/directions/json?origin="; + + @GetMapping("/{cepOrigem}/{cepDestino}") + public ArrayList getGoogleAPI(@PathVariable ("cepOrigem") int param1, @PathVariable ("cepDestino") int param2 ){ + + try { + + String APIUrl = GOOGLE+param1+"&destination="+param2+"&key=AIzaSyCKNjLUI0d01M0SfoDjIov4vZlR3DprotM"; + + URL url = new URL(APIUrl); + HttpsURLConnection get = (HttpsURLConnection) url.openConnection(); + + BufferedReader response = new BufferedReader(new InputStreamReader(get.getInputStream())); + + ArrayList jsonEmString = converteJsonEmString(response); + + return jsonEmString; + + }catch (Exception e) { + + return null; + + } + + } + + public static ArrayList converteJsonEmString(BufferedReader buffereReader) throws IOException { + + String resposta; + ArrayList json = new ArrayList<>(); + + while ((resposta = buffereReader.readLine()) != null) { + + json.add(resposta); + + } + + return json; + } + +} 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 new file mode 100644 index 0000000..62d7a39 --- /dev/null +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/interfaces/CarriersRepository.java @@ -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.Carriers; + +public interface CarriersRepository extends JpaRepository { + +} diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/interfaces/CountVisitorsRepository.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/interfaces/CountVisitorsRepository.java new file mode 100644 index 0000000..b1d1ad9 --- /dev/null +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/interfaces/CountVisitorsRepository.java @@ -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.CountVisitors; + +public interface CountVisitorsRepository extends JpaRepository { + +} diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/Carriers.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/Carriers.java new file mode 100644 index 0000000..676c4c9 --- /dev/null +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/Carriers.java @@ -0,0 +1,74 @@ +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 = "carriers") +public class Carriers { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + private String razao; + private String email; + private String cnpj; + private float taxa; + + public Carriers() { + super(); + } + + public Carriers(Integer id, String razao, String email, String cnpj, float taxa) { + super(); + this.id = id; + this.razao = razao; + this.email = email; + this.cnpj = cnpj; + this.taxa = taxa; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getRazao() { + return razao; + } + + public void setRazao(String razao) { + this.razao = razao; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getCnpj() { + return cnpj; + } + + public void setCnpj(String cnpj) { + this.cnpj = cnpj; + } + + public float getTaxa() { + return taxa; + } + + public void setTaxa(float taxa) { + this.taxa = taxa; + } + +} diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/CountVisitors.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/CountVisitors.java new file mode 100644 index 0000000..6fb7bf5 --- /dev/null +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/CountVisitors.java @@ -0,0 +1,35 @@ +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 = "count_visitors") +public class CountVisitors { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + private long count; + + public CountVisitors() { + super(); + } + + public CountVisitors(long count) { + super(); + this.count = count; + } + + public long getCount() { + return count; + } + + public void setCount(long count) { + this.count = count; + } + +} diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/RecentQuote.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/RecentQuote.java new file mode 100644 index 0000000..71a7e85 --- /dev/null +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/RecentQuote.java @@ -0,0 +1,105 @@ +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 = "recent") +public class RecentQuote { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + private float price; + private byte await; + private String origin; + private String destiny; + private byte carrier_id; + private float cub_height; + private int pessoa_id; + + public RecentQuote() { + super(); + } + + public RecentQuote(Integer id, float price, byte await, String origin, String destiny, byte carrier_id, + float cub_height, int pessoa_id) { + super(); + this.id = id; + this.price = price; + this.await = await; + this.origin = origin; + this.destiny = destiny; + this.carrier_id = carrier_id; + this.cub_height = cub_height; + this.pessoa_id = pessoa_id; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public float getPrice() { + return price; + } + + public void setPrice(float price) { + this.price = price; + } + + public byte getAwait() { + return await; + } + + public void setAwait(byte await) { + this.await = await; + } + + public String getOrigin() { + return origin; + } + + public void setOrigin(String origin) { + this.origin = origin; + } + + public String getDestiny() { + return destiny; + } + + public void setDestiny(String destiny) { + this.destiny = destiny; + } + + public byte getCarrier_id() { + return carrier_id; + } + + public void setCarrier_id(byte carrier_id) { + this.carrier_id = carrier_id; + } + + public float getCub_height() { + return cub_height; + } + + public void setCub_height(float cub_height) { + this.cub_height = cub_height; + } + + public int getPessoa_id() { + return pessoa_id; + } + + public void setPessoa_id(int pessoa_id) { + this.pessoa_id = pessoa_id; + } + +} diff --git a/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/RegisterQuote.java b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/RegisterQuote.java new file mode 100644 index 0000000..c305a35 --- /dev/null +++ b/backend/TMSProject/src/main/java/br/com/entra21/teamroxo/TMSProject/template/RegisterQuote.java @@ -0,0 +1,105 @@ +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 = "register") +public class RegisterQuote { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + private float price; + private byte await; + private String origin; + private String destiny; + private byte carrier_id; + private float cub_height; + private int pessoa_id; + + public RegisterQuote() { + super(); + } + + public RegisterQuote(Integer id, float price, byte await, String origin, String destiny, byte carrier_id, + float cub_height, int pessoa_id) { + super(); + this.id = id; + this.price = price; + this.await = await; + this.origin = origin; + this.destiny = destiny; + this.carrier_id = carrier_id; + this.cub_height = cub_height; + this.pessoa_id = pessoa_id; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public float getPrice() { + return price; + } + + public void setPrice(float price) { + this.price = price; + } + + public byte getAwait() { + return await; + } + + public void setAwait(byte await) { + this.await = await; + } + + public String getOrigin() { + return origin; + } + + public void setOrigin(String origin) { + this.origin = origin; + } + + public String getDestiny() { + return destiny; + } + + public void setDestiny(String destiny) { + this.destiny = destiny; + } + + public byte getCarrier_id() { + return carrier_id; + } + + public void setCarrier_id(byte carrier_id) { + this.carrier_id = carrier_id; + } + + public float getCub_height() { + return cub_height; + } + + public void setCub_height(float cub_height) { + this.cub_height = cub_height; + } + + public int getPessoa_id() { + return pessoa_id; + } + + public void setPessoa_id(int pessoa_id) { + this.pessoa_id = pessoa_id; + } + +} diff --git a/frontend/main/src/app/login/login.component.ts b/frontend/main/src/app/login/login.component.ts index d01c799..5ec4416 100644 --- a/frontend/main/src/app/login/login.component.ts +++ b/frontend/main/src/app/login/login.component.ts @@ -1,5 +1,7 @@ +import { HttpClient } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; +import { waitForDebugger } from 'inspector'; import { catchError, of } from 'rxjs'; import { LoginserviceService } from '../loginservice.service'; @@ -10,6 +12,8 @@ import { LoginserviceService } from '../loginservice.service'; }) export class LoginComponent implements OnInit { + readonly TMSLoginAPI: string = "http://localhost:8080" + emailReg!:string nameReg!:string userReg!:string @@ -18,7 +22,7 @@ export class LoginComponent implements OnInit { user!:string password!:string - constructor(private router:Router, public loginService:LoginserviceService) { } + constructor(private router:Router, public loginService:LoginserviceService, private http:HttpClient) { } ngOnInit(): void { this.loginService.succeed = false @@ -50,28 +54,58 @@ export class LoginComponent implements OnInit { } register(){ - 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)=>{ - return of(['Error!', error]) - }) - ) + + let email:boolean + let user:boolean + + if(this.emailReg.match('@')){ + email = true + }else{ + email = false + console.log('FORMAÇÃO DE EMAIL ERRADO'); + } + + if(this.nameReg != null && email && this.passwordReg != null && this.userReg != null){ + + let response:any = this.loginService.registering(this.nameReg, this.userReg , this.emailReg, this.passwordReg) + + console.log(response); + + let ID!:number; + + setTimeout(() =>{ + this.http.post(this.TMSLoginAPI+'/login', response) .subscribe((response:any)=>{ console.log(response); - console.log('Successful Login!'); if(response == ""){ this.loginService.progress = false; - alert("ERRO!") - }else{ + alert("USUARIO OU SENHA ERRADOS") + }else if(response.status == '500'){ + this.loginService.progress = false; + console.log('Erro no Servidor! Por favor aguarde!'); + } + else{ + ID = response[0].pessoa_id this.loginService.succeed = true this.gotoHome() } - }); + }) + setTimeout(()=>{ + this.http.get(this.TMSLoginAPI+'/user/'+ID) + .subscribe((response:any)=>{ + console.log(response); + this.loginService.user = response.nome + }) + },500) + + },1500) + }else{ + alert('DIGITE TODOS OS CAMPOS OBRIGATÓRIOS!') this.loginService.progress = false + } } diff --git a/frontend/main/src/app/loginservice.service.ts b/frontend/main/src/app/loginservice.service.ts index 04062d8..d7999d2 100644 --- a/frontend/main/src/app/loginservice.service.ts +++ b/frontend/main/src/app/loginservice.service.ts @@ -11,7 +11,7 @@ import { LoginComponent } from './login/login.component'; export class LoginserviceService implements CanActivate { user!: string - TMSLoginAPI: string = "http://localhost:8080" + readonly TMSLoginAPI: string = "http://localhost:8080" succeed!: boolean progress: boolean = false @@ -56,17 +56,23 @@ export class LoginserviceService implements CanActivate { 'senha':password } + let buildLogin:any = { + 'user':user, + 'senha':password + } + this.http.post(this.TMSLoginAPI+'/register', build) .pipe( catchError((error)=>{ return error }) ) - .subscribe((response:any)=>{ - return response + .subscribe((response)=>{ + buildLogin = response + return buildLogin }) - return this.http.get(this.TMSLoginAPI +'/login', build) + return buildLogin }