From 2f79e2fa41b875d84a2d4695ba2e4b34af9275c5 Mon Sep 17 00:00:00 2001 From: matias mella Date: Wed, 14 Jul 2021 01:24:10 -0400 Subject: [PATCH 1/2] 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`); + } +} From 069413b577e7db1b8cc69fc21cb31c701a6e2c56 Mon Sep 17 00:00:00 2001 From: matias mella Date: Thu, 15 Jul 2021 00:40:56 -0400 Subject: [PATCH 2/2] se agrego el modificar --- .../agregar-res/agregar-res.component.html | 31 ++++++++++++++++--- .../agregar-res/agregar-res.component.ts | 21 +++++++++++++ frontend/src/app/restaurantes.service.ts | 20 +++++++++++- 3 files changed, 66 insertions(+), 6 deletions(-) diff --git a/frontend/src/app/components/agregar-res/agregar-res.component.html b/frontend/src/app/components/agregar-res/agregar-res.component.html index 187ef67..ee4c720 100644 --- a/frontend/src/app/components/agregar-res/agregar-res.component.html +++ b/frontend/src/app/components/agregar-res/agregar-res.component.html @@ -1,12 +1,33 @@ - - +
    + + - + + + - -
    idnombrecreacionmodificacion
    {{r.id}} {{r.nombre}} {{r['created_at']}} {{r['updated_at']}}
    + + + + + +
    + +

    + nombre: +

    +

    +

    +

    + +
    + + + + + diff --git a/frontend/src/app/components/agregar-res/agregar-res.component.ts b/frontend/src/app/components/agregar-res/agregar-res.component.ts index 3232bf5..1dc1a6f 100644 --- a/frontend/src/app/components/agregar-res/agregar-res.component.ts +++ b/frontend/src/app/components/agregar-res/agregar-res.component.ts @@ -10,6 +10,11 @@ export class AgregarResComponent implements OnInit { restaurante: any; + agre={ + nombre:null + + } + constructor(private restaurantServ : RestaurantesService) { } ngOnInit(): void { @@ -19,6 +24,22 @@ export class AgregarResComponent implements OnInit { recuperartodos(){ this.restaurantServ.mostrarTodosRes().subscribe(result => this.restaurante = result); } + agregarRes(){ + this.restaurantServ.agregar(this.agre).subscribe(this.recuperartodos) + } + eliminarRes(id:any){ + console.log(id); + this.restaurantServ.eliminar(id).subscribe() + + } + modificarRes(id:any){ + console.log(id,this.agre) + + this.restaurantServ.modificar(id,this.agre).subscribe(); + } + + + hayregistro(){ return true; } diff --git a/frontend/src/app/restaurantes.service.ts b/frontend/src/app/restaurantes.service.ts index e0b53fa..ee5276e 100644 --- a/frontend/src/app/restaurantes.service.ts +++ b/frontend/src/app/restaurantes.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@angular/core'; -import {HttpClient} from "@angular/common/http"; +import {HttpClient, HttpHeaders} from "@angular/common/http"; @Injectable({ providedIn: 'root' @@ -14,4 +14,22 @@ export class RestaurantesService { mostrarTodosRes(){ return this.http.get(`${this.url}/restaurantes`); } + + agregar(AgreRestaurant:any){ + const headers: HttpHeaders = new HttpHeaders({ + 'Content-Type': 'application/json' + }); + return this.http.post(`${this.url}/restaurantes`, JSON.stringify(AgreRestaurant),{ headers: headers }); + } + eliminar(codigo:any){ + return this.http.delete(`${this.url}/restaurantes/${codigo}`); + } + modificar(codigo:any,ModificarRes:any){ + const headers: HttpHeaders = new HttpHeaders({ + 'Content-Type': 'application/json' + }); + return this.http.put(`${this.url}/restaurantes/${codigo}`, JSON.stringify(ModificarRes),{ headers: headers }); + } + + }