-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementing user and product services
- Loading branch information
1 parent
c151b46
commit cc6b406
Showing
54 changed files
with
998 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<app-menu></app-menu> | ||
<app-menu *ngIf="currentRoute === '/inicio' || currentRoute === '/login'" ></app-menu> | ||
<router-outlet></router-outlet> | ||
<app-rodape></app-rodape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,22 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Router, NavigationEnd } from '@angular/router'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.css'] | ||
}) | ||
export class AppComponent { | ||
export class AppComponent implements OnInit { | ||
title = 'Hypnix - Home'; | ||
} | ||
currentRoute!: string; | ||
|
||
constructor(private router: Router) { } | ||
|
||
ngOnInit() { | ||
this.router.events.subscribe(event => { | ||
if (event instanceof NavigationEnd) { | ||
this.currentRoute = event.urlAfterRedirects; | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { GuardGuard } from './guard.guard'; | ||
|
||
describe('GuardGuard', () => { | ||
let guard: GuardGuard; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
guard = TestBed.inject(GuardGuard); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(guard).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router'; | ||
import { Observable } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class GuardGuard implements CanActivate { | ||
|
||
constructor(private _router: Router){} | ||
|
||
canActivate( | ||
route: ActivatedRouteSnapshot, | ||
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { | ||
|
||
if(localStorage.getItem('token') !== null){ | ||
return true; | ||
} | ||
|
||
this._router.navigate(['login']); | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,42 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Produto } from '../models/Produto.model'; | ||
import { ProdutoService } from '../services/produto.service'; | ||
|
||
@Component({ | ||
selector: 'app-inicio', | ||
templateUrl: './inicio.component.html', | ||
styleUrls: ['./inicio.component.css'] | ||
}) | ||
export class InicioComponent { | ||
export class InicioComponent implements OnInit{ | ||
|
||
public produtos: Produto[] = []; | ||
|
||
constructor(private _produtoService:ProdutoService){} | ||
|
||
ngOnInit(): void { | ||
this.listarProdutos(); | ||
} | ||
showAll: boolean = false; | ||
|
||
verTudo() { | ||
this.showAll = true; | ||
} | ||
|
||
listarProdutos():void{ | ||
this._produtoService.getProdutos().subscribe( | ||
retornaProduto =>{ | ||
this.produtos = retornaProduto.map( | ||
item => { | ||
return new Produto( | ||
item.id, | ||
item.produto, | ||
item.foto, | ||
item.preco | ||
); | ||
} | ||
) | ||
} | ||
) | ||
} | ||
|
||
} |
Oops, something went wrong.