Skip to content
Merged

Kaka #25

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
Original file line number Diff line number Diff line change
@@ -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<Carriers> listCarriers(){

return carriersRepository.findAll();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Login> listAll() {
Expand All @@ -58,6 +60,12 @@ public List<Login> listAll() {
setMaturidadeLvl3(pessoa);
});

if(!response.isEmpty()) {
CountVisitors count = new CountVisitors();
count.setCount(0);
countVisitorsRepository.save(count);
}

return response;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,6 +38,9 @@ public class PessoaController {
@Autowired
private PessoaRepository pessoaRepository;

@Autowired
private CountVisitorsRepository countVisitorsRepository;

@GetMapping()
@ResponseStatus(code = HttpStatus.OK)
public List<Pessoa>listAll(){
Expand All @@ -45,9 +49,17 @@ public class PessoaController {

@GetMapping("/{id}")
public Optional<Pessoa> 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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> jsonEmString = converteJsonEmString(response);

return jsonEmString;

}catch (Exception e) {

return null;

}

}

public static ArrayList<String> converteJsonEmString(BufferedReader buffereReader) throws IOException {

String resposta;
ArrayList<String> json = new ArrayList<>();

while ((resposta = buffereReader.readLine()) != null) {

json.add(resposta);

}

return json;
}

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

public interface CarriersRepository extends JpaRepository<Carriers, 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.CountVisitors;

public interface CountVisitorsRepository extends JpaRepository<CountVisitors, Integer> {

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Loading