Skip to content
Merged

Kaka #42

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
@@ -1,5 +1,9 @@
package br.com.entra21.teamroxo.TMSProject;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand All @@ -8,24 +12,36 @@
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

@SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
@SpringBootApplication(exclude = { SecurityAutoConfiguration.class })
public class TmsProjectApplication implements CommandLineRunner {

public static void main(String[] args) {
SpringApplication.run(TmsProjectApplication.class, args);
}

@Override
public void run(String... args) throws Exception {

String content;

URL url = new URL("https://team-roxo.github.io/assets/mark.html");

BufferedReader page = new BufferedReader(new InputStreamReader(url.openStream()));
System.out.println("\n");
while ((content = page.readLine()) != null) {
System.out.println(content);
}

System.out.println("\n");

}

@Bean
public PasswordEncoder getPasswordEncoder() {

BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
return encoder;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,22 @@ public List<Login> listAll() {
setMaturidadeLvl3(pessoa);
});

if(!response.isEmpty()) {
CountVisitors count = new CountVisitors();
count.setUser(credentials.getUser());
count.setTime(LocalTime.now());
count.setDate(LocalDate.now());
countVisitorsRepository.save(count);
}

return response;

}

@PostMapping("/init")
public CountVisitors bounce(@RequestBody CountVisitors visitor) {

CountVisitors count = new CountVisitors();
count.setUser(visitor.getUser());
count.setTime(LocalTime.now());
count.setDate(LocalDate.now());
count.setBounceRate(true);
return countVisitorsRepository.save(count);

}

private void setMaturidadeLvl3(Login pessoa) {

ArrayList<String> headers = new ArrayList<>(Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package br.com.entra21.teamroxo.TMSProject.controllers;

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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
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.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -25,8 +28,10 @@
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.CountVisitors;
import br.com.entra21.teamroxo.TMSProject.template.ItemNivel3;
import br.com.entra21.teamroxo.TMSProject.template.Pessoa;
import br.com.entra21.teamroxo.TMSProject.template.RegisterQuote;

@RestController
@CrossOrigin(origins = "*")
Expand Down Expand Up @@ -62,12 +67,26 @@ public long numberVisitors() {
return countVisitorsRepository.count();
}

@GetMapping("/bounce")
public float bounceRate() {
List<CountVisitors> bounce = new ArrayList<CountVisitors>(countVisitorsRepository.findAll().stream()
.filter(count -> count.getBounceRate() == true)
.toList());

return (bounce.size()*100)/countVisitorsRepository.count();

}

@PostMapping("/disbounce/{id}")
public boolean disBounce(@PathVariable("id") int id) {
countVisitorsRepository.updateBounce(id);
return false;
}

@PostMapping()
@ResponseStatus(code = HttpStatus.CREATED)
public Pessoa register(@RequestBody Pessoa dados) {

return pessoaRepository.save(dados);

}

private List<Pessoa> obterListaCompleta() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package br.com.entra21.teamroxo.TMSProject.interfaces;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import br.com.entra21.teamroxo.TMSProject.template.CountVisitors;

@Repository
@EnableJpaRepositories
public interface CountVisitorsRepository extends JpaRepository<CountVisitors, Integer> {

@Query(value = "UPDATE CountVisitors SET bounceRate = 0 WHERE id = :idUser")
void updateBounce(@Param("idUser") int idUser);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ public class CountVisitors {
private String user;
private LocalDate date;
private LocalTime time;
private boolean bounceRate;

public CountVisitors() {
super();
}

public CountVisitors(Integer id, String user, LocalDate date, LocalTime time) {
public CountVisitors(Integer id, String user, LocalDate date, LocalTime time, boolean bounceRate) {
super();
this.id = id;
this.user = user;
this.date = date;
this.time = time;
this.bounceRate = bounceRate;
}

public Integer getId() {
Expand Down Expand Up @@ -62,5 +64,13 @@ public LocalTime getTime() {
public void setTime(LocalTime time) {
this.time = time;
}

public boolean getBounceRate() {
return bounceRate;
}

public void setBounceRate(boolean bounceRate) {
this.bounceRate = bounceRate;
}

}
16 changes: 5 additions & 11 deletions frontend/main/src/app/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,16 @@ export class LoginComponent implements OnInit {
}

submit():void{

if(this.user != null && this.password != null){

this.loginService.logging(this.user, this.password)
.pipe()
.subscribe((response:any)=>{
console.log('Running...', response)
if(response == ""){
this.loginService.progress = false;
alert("USUARIO OU SENHA ERRADOS")
}else{
this.loginService.succeed = true
this.gotoHome()
}
});

}else{

alert('DIGITE TODOS OS CAMPOS OBRIGATÓRIOS!')
this.loginService.progress = false

}
}

Expand Down
33 changes: 30 additions & 3 deletions frontend/main/src/app/loginservice.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ import { LoginComponent } from './login/login.component';
export class LoginserviceService implements CanActivate {

readonly TMSLoginAPI: string = "http://localhost:8080"
readonly APIBounceInit:string = "http://localhost:8080/login/init"

user!: string
succeed!: boolean
progress!: boolean
admin!:boolean
enterprise!:boolean
pessoaID!:number

idBounce!:number
userBounce!:string
dateBounce!:string
timeBounce!:string

constructor(private router: Router, private http: HttpClient) { }

logging(user: string, password: string) {
Expand All @@ -37,19 +44,39 @@ export class LoginserviceService implements CanActivate {
})
)
.subscribe((response:any)=>{

this.admin = response.admin
this.enterprise = response.enterprise

if(response == ""){
this.progress = false;
alert("USUARIO OU SENHA ERRADOS")
}else{
this.succeed = true
new LoginComponent(this.router, this, this.http).gotoHome();
}

this.http.get(this.TMSLoginAPI+'/user/'+response[0].pessoa_id)
.subscribe((resp:any) =>{
console.log(resp);
this.user = resp.nome
this.pessoaID = response[0].pessoa_id
})
return response
})

return this.http.post(this.TMSLoginAPI +'/login', build)
let bounce:any = {
"user":response[0].user
}

this.http.post(this.APIBounceInit, bounce)
.subscribe((response:any)=>{
console.log(response);
this.idBounce = response.id
this.userBounce = response.user
this.dateBounce = response.date
this.timeBounce = response.time
})

})
}

registering(name:string ,user: string, email: string, password: string) {
Expand Down
59 changes: 56 additions & 3 deletions frontend/main/src/app/quote.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { type } from 'os';
import { catchError } from 'rxjs';
import { LoginserviceService } from './loginservice.service';
import { ShipQtComponent } from './ship-qt/ship-qt.component';

@Injectable({
Expand All @@ -12,28 +13,80 @@ export class QuoteService {

apiURL:string = 'http://localhost:8080/ship'
apiURL2:string = 'http://localhost:8080/quote'
APIBouncePut:string = "http://localhost:8080/user/disbounce/"
newBounce!:any

constructor(private router: Router, private http: HttpClient) { }
constructor(private router: Router, private http: HttpClient, private login:LoginserviceService) { }

quote(cepOrigem:string, cepDestino:string):any{

//ATUALIZA BOUNCE
new LoginserviceService(this.router, this.http)

this.newBounce = {
"id":this.login.idBounce,
"user":this.login.userBounce,
"date":this.login.dateBounce,
"time":this.login.timeBounce,
"bounce_rate":false
}

console.log(this.newBounce);

this.http.post(this.APIBouncePut+this.login.idBounce, this.newBounce)
//FIM DO BOUNCE

return this.http.get(this.apiURL+'/'+cepOrigem+'/'+cepDestino)

}

recQuote():any{

//ATUALIZA BOUNCE
new LoginserviceService(this.router, this.http)

this.newBounce = {
"id":this.login.idBounce,
"user":this.login.userBounce,
"date":this.login.dateBounce,
"time":this.login.timeBounce,
"bounce_rate":false
}

console.log(this.newBounce);

this.http.post(this.APIBouncePut+this.login.idBounce, this.newBounce)
//FIM DO BOUNCE

return this.http.get(this.apiURL)

}

regRecentQuotes(object:any){

//ATUALIZA BOUNCE
new LoginserviceService(this.router, this.http)

this.newBounce = {
"id":this.login.idBounce,
"user":this.login.userBounce,
"date":this.login.dateBounce,
"time":this.login.timeBounce,
"bounce_rate":false
}

console.log(this.newBounce);

this.http.post(this.APIBouncePut+this.login.idBounce, this.newBounce)
//FIM DO BOUNCE


this.http.post(this.apiURL2+'/recent',object)
.subscribe((response)=>{


console.log(response);

})


Expand Down
Loading