From 2f79e2fa41b875d84a2d4695ba2e4b34af9275c5 Mon Sep 17 00:00:00 2001 From: matias mella Date: Wed, 14 Jul 2021 01:24:10 -0400 Subject: [PATCH] agrege listado de restaurante --- frontend/.dockerignore | 1 + frontend/src/app/app-routing.module.ts | 6 ++- frontend/src/app/app.component.html | 9 ++++- frontend/src/app/app.component.ts | 1 + frontend/src/app/app.module.ts | 37 ++++++++++++++++--- .../agregar-res/agregar-res.component.html | 12 ++++++ .../agregar-res/agregar-res.component.scss | 0 .../agregar-res/agregar-res.component.ts | 26 +++++++++++++ .../components/private/private.component.html | 4 +- .../components/private/private.component.ts | 17 ++++++++- frontend/src/app/restaurantes.service.spec.ts | 16 ++++++++ frontend/src/app/restaurantes.service.ts | 17 +++++++++ 12 files changed, 133 insertions(+), 13 deletions(-) create mode 100644 frontend/.dockerignore create mode 100644 frontend/src/app/components/agregar-res/agregar-res.component.html create mode 100644 frontend/src/app/components/agregar-res/agregar-res.component.scss create mode 100644 frontend/src/app/components/agregar-res/agregar-res.component.ts create mode 100644 frontend/src/app/restaurantes.service.spec.ts create mode 100644 frontend/src/app/restaurantes.service.ts diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1 @@ +node_modules/ diff --git a/frontend/src/app/app-routing.module.ts b/frontend/src/app/app-routing.module.ts index b7a38d3..62f93b6 100644 --- a/frontend/src/app/app-routing.module.ts +++ b/frontend/src/app/app-routing.module.ts @@ -2,13 +2,15 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import {PublicComponent} from "./components/public/public.component"; import {PrivateComponent} from "./components/private/private.component"; -import {AuthGuard} from "./guards/auth.guard"; -//import { AuthGuard } from '@auth0/auth0-angular'; +//import {AuthGuard} from "./guards/auth.guard"; +import { AuthGuard } from '@auth0/auth0-angular'; +import {AgregarResComponent} from "./components/agregar-res/agregar-res.component"; const routes: Routes = [ { path: 'public', component:PublicComponent}, { path: 'private', component:PrivateComponent, canActivate: [AuthGuard]}, + {path: 'agregar.res', component:AgregarResComponent, canActivate:[AuthGuard]}, {path: '**', pathMatch: 'full', redirectTo: 'public'} ]; diff --git a/frontend/src/app/app.component.html b/frontend/src/app/app.component.html index 5f1cebb..18618ef 100644 --- a/frontend/src/app/app.component.html +++ b/frontend/src/app/app.component.html @@ -9,6 +9,9 @@ + @@ -17,10 +20,12 @@ +
  • + + - - +
    diff --git a/frontend/src/app/app.component.ts b/frontend/src/app/app.component.ts index 48a962b..ea391c9 100644 --- a/frontend/src/app/app.component.ts +++ b/frontend/src/app/app.component.ts @@ -1,6 +1,7 @@ import { Component } from '@angular/core'; import {AuthService} from "@auth0/auth0-angular"; + @Component({ selector: 'app-root', templateUrl: './app.component.html', diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 4e595cd..0af38e9 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -1,18 +1,20 @@ import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; - +import { FormsModule } from '@angular/forms'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; - -import { AuthModule } from '@auth0/auth0-angular'; +import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http'; +import { AuthModule, AuthHttpInterceptor } from '@auth0/auth0-angular'; import { PublicComponent } from './components/public/public.component'; import { PrivateComponent } from './components/private/private.component'; +import { AgregarResComponent } from './components/agregar-res/agregar-res.component'; @NgModule({ declarations: [ AppComponent, PublicComponent, - PrivateComponent + PrivateComponent, + AgregarResComponent ], imports: [ BrowserModule, @@ -21,10 +23,33 @@ import { PrivateComponent } from './components/private/private.component'; domain: 'dev-ygnrzo5i.us.auth0.com', clientId: '2MCYrmwNWAkeJyYYYRCS1gscDbiwAIfq', cacheLocation: 'localstorage', - useRefreshTokens:true + useRefreshTokens:true, + audience: 'https://api.unified.restaurant', + scope: 'read:current_user', + httpInterceptor:{ + allowedList: [ + { + // Match any request that starts 'https://dev-6scsp8es.us.auth0.com/api/v2/' (note the asterisk) + uri: 'https://api.unified.restaurant/api/v1/*', + tokenOptions: { + // The attached token should target this audience + audience: 'https://api.unified.restaurant', + + // The attached token should have these scopes + scope: 'read:current_user' + } + } + ] + } }), + + + HttpClientModule, + FormsModule + ], + providers: [ + { provide: HTTP_INTERCEPTORS, useClass: AuthHttpInterceptor, multi: true } ], - providers: [], bootstrap: [AppComponent] }) export class AppModule { } diff --git a/frontend/src/app/components/agregar-res/agregar-res.component.html b/frontend/src/app/components/agregar-res/agregar-res.component.html new file mode 100644 index 0000000..187ef67 --- /dev/null +++ b/frontend/src/app/components/agregar-res/agregar-res.component.html @@ -0,0 +1,12 @@ + + + + + + + + + + +
    idnombrecreacionmodificacion
    {{r.id}}{{r.nombre}}{{r['created_at']}}{{r['updated_at']}}
    + diff --git a/frontend/src/app/components/agregar-res/agregar-res.component.scss b/frontend/src/app/components/agregar-res/agregar-res.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/components/agregar-res/agregar-res.component.ts b/frontend/src/app/components/agregar-res/agregar-res.component.ts new file mode 100644 index 0000000..3232bf5 --- /dev/null +++ b/frontend/src/app/components/agregar-res/agregar-res.component.ts @@ -0,0 +1,26 @@ +import { Component, OnInit } from '@angular/core'; +import {RestaurantesService} from "../../restaurantes.service"; + +@Component({ + selector: 'app-agregar-res', + templateUrl: './agregar-res.component.html', + styleUrls: ['./agregar-res.component.scss'] +}) +export class AgregarResComponent implements OnInit { + + restaurante: any; + + constructor(private restaurantServ : RestaurantesService) { } + + ngOnInit(): void { + this.recuperartodos(); + + } + recuperartodos(){ + this.restaurantServ.mostrarTodosRes().subscribe(result => this.restaurante = result); + } + hayregistro(){ + return true; + } + +} diff --git a/frontend/src/app/components/private/private.component.html b/frontend/src/app/components/private/private.component.html index c0b80bb..a7b776c 100644 --- a/frontend/src/app/components/private/private.component.html +++ b/frontend/src/app/components/private/private.component.html @@ -1,5 +1,5 @@ -
    +
       
    -    {{user | json}}
    +    {{dato | json}}
       
     
    diff --git a/frontend/src/app/components/private/private.component.ts b/frontend/src/app/components/private/private.component.ts index 553fa8e..e6c07e7 100644 --- a/frontend/src/app/components/private/private.component.ts +++ b/frontend/src/app/components/private/private.component.ts @@ -1,16 +1,31 @@ import { Component, OnInit } from '@angular/core'; import {AuthService} from "@auth0/auth0-angular"; +import { concatMap, tap, pluck } from 'rxjs/operators'; +import { HttpClient } from '@angular/common/http'; + @Component({ selector: 'app-private', templateUrl: './private.component.html', styleUrls: ['./private.component.scss'] }) export class PrivateComponent implements OnInit { + dato = {}; - constructor(public auth: AuthService) { } + constructor(public auth: AuthService, private http: HttpClient) { } ngOnInit(): void { + + this.auth.user$ + .pipe( + tap((user)=>console.log(user)), + concatMap((user)=> + this.http.get(`https://api.unified.restaurant/api/v1/users/${user?.sub}`) + ), + tap((userdato) =>(this.dato = userdato)) + ).subscribe(); + console.log(); + } } diff --git a/frontend/src/app/restaurantes.service.spec.ts b/frontend/src/app/restaurantes.service.spec.ts new file mode 100644 index 0000000..b5c5d98 --- /dev/null +++ b/frontend/src/app/restaurantes.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { RestaurantesService } from './restaurantes.service'; + +describe('RestaurantesService', () => { + let service: RestaurantesService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(RestaurantesService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/restaurantes.service.ts b/frontend/src/app/restaurantes.service.ts new file mode 100644 index 0000000..e0b53fa --- /dev/null +++ b/frontend/src/app/restaurantes.service.ts @@ -0,0 +1,17 @@ +import { Injectable } from '@angular/core'; + +import {HttpClient} from "@angular/common/http"; + +@Injectable({ + providedIn: 'root' +}) +export class RestaurantesService { + + url='https://api.unified.restaurant/api/v1'; + + constructor(private http: HttpClient) { } + + mostrarTodosRes(){ + return this.http.get(`${this.url}/restaurantes`); + } +}