Skip to content
Merged

Kaka #86

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

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.logging.SimpleFormatter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
Expand All @@ -28,13 +32,11 @@
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.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 @@ -77,8 +79,7 @@ public List<Pessoa> birthNow(){

@GetMapping("/birthmonth")
public List<Pessoa> birthMonth(){
return pessoaRepository.findBirthMonth(LocalDate.now().withMonth(LocalDate.now().getMonthValue()).with(TemporalAdjusters.firstDayOfMonth()),
LocalDate.now().withMonth(LocalDate.now().getMonthValue()).with(TemporalAdjusters.lastDayOfMonth()));
return pessoaRepository.findBirthMonth(LocalDate.now());
}

@GetMapping("/bounce")
Expand Down Expand Up @@ -107,6 +108,8 @@ public Pessoa register(@RequestBody Pessoa dados) {
public void deletePessoa(@PathVariable("id") int id){
pessoaRepository.deleteById(id);
}



private List<Pessoa> obterListaCompleta() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
@EnableJpaRepositories
public interface PessoaRepository extends JpaRepository<Pessoa, Integer> {

@Query("FROM Pessoa WHERE birth = :now")
@Query("FROM Pessoa WHERE MONTH(birth) = EXTRACT(MONTH FROM :now) AND DAY(birth) = EXTRACT(DAY FROM :now)")
List<Pessoa> findBirth (@Param("now") LocalDate now);

@Query("FROM Pessoa WHERE birth BETWEEN :firstDay and :lastDay")
List<Pessoa> findBirthMonth (@Param("firstDay") LocalDate first, @Param("lastDay") LocalDate last);
@Query("FROM Pessoa WHERE MONTH(birth) = EXTRACT(MONTH FROM :now)")
List<Pessoa> findBirthMonth (@Param("now") LocalDate now);

}
6 changes: 3 additions & 3 deletions frontend/main/src/app/body/body.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ <h3 class="dropdown-item-title">
<span class="badge badge-warning navbar-badge" *ngIf="this.notificationCount != 0">{{this.notificationCount}}</span>
</a>
<div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
<div *ngFor="let notify of notificacoes;let i = index">
<div *ngFor="let notify of this.notificacoes;let i = index">
<div class="dropdown-divider"></div>
<a href="#" routerLink={{notify.route}} class="dropdown-item">
<div class="media">
<div class="media-body">
<h3 class="dropdown-item-title">
{{notify.title}}
<span class="float-right text-sm text-danger"><i class="fas fa-star"></i></span>
<span class="float-right text-sm text-warning"><i class="fas fa-bell"></i></span>
</h3>
<p class="text-sm">{{notify.text}}</p>
</div>
Expand Down Expand Up @@ -208,4 +208,4 @@ <h3 class="dropdown-item-title">
<span>{{loginService.nome}}<br><a routerLink="" (click)="sair()" class="small"
style="color: red;">Sair</a>&nbsp;&nbsp;&nbsp;&nbsp;<a routerLink="edit" class="small">Edit</a> </span>
</div>
</aside>
</aside>
111 changes: 79 additions & 32 deletions frontend/main/src/app/body/body.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { LoginComponent } from '../login/login.component';
import { LoginserviceService } from '../loginservice.service';
import { HttpClient } from '@angular/common/http';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { catchError, Observable } from 'rxjs';
import { NotificationService } from '../notification.service';

@Component({
Expand All @@ -17,65 +17,112 @@ export class BodyComponent implements OnInit {

readonly APIBirthMonth: string = "http://localhost:8080/user/birthmonth"

birthnow! : string
birthmonth! : string
aniversariantes!: Array<any>
aniversariantesMes!: Array<any>
notificacoes!:Array<any>
notificationCount!:number
birthnow!: string
birthmonth!: string
aniversariantes: Array<any> = new Array()
aniversariantesMes: Array<any> = new Array()
notificacoes: Array<any> = new Array()
notificationCount!: number
id!: number
nome!: string
email!: string
birth!: Date
birth!: string
document!: string

constructor(public loginService:LoginserviceService, private router:Router, private http:HttpClient, private notify:NotificationService) { }
constructor(public loginService: LoginserviceService, private router: Router, private http: HttpClient, private notify: NotificationService) { }

ngOnInit(): void {

this.aniversariantes = new Array()
this.aniversariantesMes = new Array()
this.notificacoes = new Array()

if(this.loginService.document == null || this.loginService.birth == null){
this.notificacoes.push({title:"Complete seu Cadastro!", text:"Clique aqui para concluir!", route:"edit"})
}

this.http.get(this.APIBirthNow)
.subscribe((resultado:any) => {
.subscribe((resultado: any) => {

var count = Object.keys(resultado).length
console.log(resultado);

for(let i=0;i<count;i++){
var count = Object.keys(resultado).length

if(resultado[i].id == this.loginService.pessoaID){
this.notificacoes.push({title:"Hoje é seu Aniversário!", text:"Parabéns! Para comemorar temos algumas ofertas para você. Confira!", route:"ship-quote"})
}
for (let i = 0; i < count; i++) {

this.aniversariantes.push({id: resultado[i].id ,nome: resultado[i].nome, email: resultado[i].email, birth: resultado[i].birth, document: resultado[i].document})
this.aniversariantes.push({ id: resultado[i].id, nome: resultado[i].nome, email: resultado[i].email, birth: resultado[i].birth, document: resultado[i].document })

}
}

});
});

this.http.get(this.APIBirthMonth)
.subscribe((resultado:any) => {
.subscribe((resultado: any) => {

var count = Object.keys(resultado).length

for (let i = 0; i < count; i++) {

this.aniversariantesMes.push({ id: resultado[i].id, nome: resultado[i].nome, email: resultado[i].email, birth: resultado[i].birth, document: resultado[i].document })

}

});

setTimeout(() => {
this.notification()
}, 450);

}

notification() {

var count = Object.keys(resultado).length
if (this.loginService.succeed == true) {
console.log(this.loginService.document, this.loginService.birth);

for(let i=0;i<count;i++){
setTimeout(() => {

this.aniversariantesMes.push({id: resultado[i].id ,nome: resultado[i].nome, email: resultado[i].email, birth: resultado[i].birth, document: resultado[i].document})
if (this.loginService.birth) {
console.log('DOCUMENTOS CORRETOS!');
} else {
this.notificacoes.push({ title: "Complete seu Cadastro!", text: "Clique aqui para concluir!", route: "edit" })
}

if (this.loginService.document) {
console.log('DOCUMENTOS CORRETOS!');
} else {
this.notificacoes.push({ title: "Complete seu Cadastro!", text: "Clique aqui para concluir!", route: "edit" })
}

}, 500);

this.http.get(this.APIBirthNow)
.subscribe((resultado: any) => {

var count = Object.keys(resultado).length

for (let i = 0; i < count; i++) {

}
if (resultado[i].id === this.loginService.pessoaID) { //verificar qual ID a API tá retornando
this.notificacoes.push({ title: "Hoje é seu Aniversário!", text: "Parabéns, "+this.loginService.nome.split(' ').at(0)+"! Para comemorar temos algumas ofertas para você. Confira!", route: "ship-quote" })
}
}
})

});
setTimeout(() => {

this.notificationCount = this.notificacoes.length
this.notificationCount = this.notificacoes.length

if (this.notificationCount === 0) {
this.notificacoes.push({ title: 'Tudo certo por aqui, '+this.loginService.nome.split(' ').at(0)+'!', text: 'Te avisaremos qualquer coisa! 😉', route:'#' })
}

}, 600);

}

if(this.loginService.succeed == false){
this.ngOnInit();
}

}

sair(){
sair() {
this.loginService.succeed = false;
this.ngOnInit();
}
}
4 changes: 2 additions & 2 deletions frontend/main/src/app/edit/edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { LoginserviceService } from '../loginservice.service';
export class EditComponent implements OnInit {
name!:string
user!:string
birth!:Date
birth!:string
document!:string
email!:string
password!:string
Expand All @@ -21,7 +21,7 @@ password!:string
constructor(
private router:Router,
private login: LoginserviceService

) { }

ngOnInit(): void {
Expand Down
35 changes: 22 additions & 13 deletions frontend/main/src/app/loginservice.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { Injectable } from '@angular/core';
import { InjectSetupWrapper } from '@angular/core/testing';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
import { catchError, Observable } from 'rxjs';
import { BodyComponent } from './body/body.component';
import { LoginComponent } from './login/login.component';
import { NotificationService } from './notification.service';

@Injectable({
providedIn: 'root'
Expand All @@ -19,7 +21,7 @@ export class LoginserviceService implements CanActivate {
user!: string
email!: string
password!: string
birth!: Date
birth!: string
document!: string

//DADOS DE CONTROLE
Expand All @@ -40,6 +42,8 @@ export class LoginserviceService implements CanActivate {

logging(user: string, password: string) {

console.log('login service iniciado');

this.progress = true

let build: any = {
Expand All @@ -51,14 +55,30 @@ export class LoginserviceService implements CanActivate {
.pipe(
catchError((error)=>{
this.progress = false
console.log(error);
return error

})
)
.subscribe((response:any)=>{

console.log('API works');
console.log(response);

this.admin = response[0].admin
this.enterprise = response[0].enterprise
this.user = response[0].user
this.pessoaID = response[0].pessoa_id
this.password = response[0].senha

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

if(this.admin == true){
this.adminEnter = true;
Expand All @@ -75,30 +95,19 @@ export class LoginserviceService implements CanActivate {
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.nome = resp.nome
this.pessoaID = response[0].pessoa_id
this.birth = resp.birth
this.document = resp.document
this.email = resp.email
this.password = response[0].senha
})

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
4 changes: 1 addition & 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 { BodyComponent } from './body/body.component';
import { LoginserviceService } from './loginservice.service';
import { RctQtComponent } from './rct-qt/rct-qt.component';
import { ShipQtComponent } from './ship-qt/ship-qt.component';
Expand All @@ -24,7 +25,6 @@ export class QuoteService {
quote(cepOrigem:string, cepDestino:string):any{

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

this.newBounce = {
"id":this.login.idBounce,
Expand All @@ -46,7 +46,6 @@ export class QuoteService {
recQuote():any{

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

this.newBounce = {
"id":this.login.idBounce,
Expand All @@ -68,7 +67,6 @@ export class QuoteService {
regRecentQuotes(object:any){

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

this.newBounce = {
"id":this.login.idBounce,
Expand Down
Loading