agrege listado de restaurante
This commit is contained in:
1
frontend/.dockerignore
Normal file
1
frontend/.dockerignore
Normal file
@@ -0,0 +1 @@
|
|||||||
|
node_modules/
|
||||||
@@ -2,13 +2,15 @@ import { NgModule } from '@angular/core';
|
|||||||
import { RouterModule, Routes } from '@angular/router';
|
import { RouterModule, Routes } from '@angular/router';
|
||||||
import {PublicComponent} from "./components/public/public.component";
|
import {PublicComponent} from "./components/public/public.component";
|
||||||
import {PrivateComponent} from "./components/private/private.component";
|
import {PrivateComponent} from "./components/private/private.component";
|
||||||
import {AuthGuard} from "./guards/auth.guard";
|
//import {AuthGuard} from "./guards/auth.guard";
|
||||||
//import { AuthGuard } from '@auth0/auth0-angular';
|
import { AuthGuard } from '@auth0/auth0-angular';
|
||||||
|
import {AgregarResComponent} from "./components/agregar-res/agregar-res.component";
|
||||||
|
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: 'public', component:PublicComponent},
|
{ path: 'public', component:PublicComponent},
|
||||||
{ path: 'private', component:PrivateComponent, canActivate: [AuthGuard]},
|
{ path: 'private', component:PrivateComponent, canActivate: [AuthGuard]},
|
||||||
|
{path: 'agregar.res', component:AgregarResComponent, canActivate:[AuthGuard]},
|
||||||
{path: '**', pathMatch: 'full', redirectTo: 'public'}
|
{path: '**', pathMatch: 'full', redirectTo: 'public'}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,9 @@
|
|||||||
<li class="nav-item" routerLinkActive="active">
|
<li class="nav-item" routerLinkActive="active">
|
||||||
<a class="nav-link" routerLink="public" uter>public</a>
|
<a class="nav-link" routerLink="public" uter>public</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item" routerLinkActive="active">
|
||||||
|
<a class="nav-link" routerLink="agregar.res">agregar.res</a>
|
||||||
|
</li>
|
||||||
<li class="nav-item" routerLinkActive="active" >
|
<li class="nav-item" routerLinkActive="active" >
|
||||||
<a class="nav-link" routerLink="private" *ngIf="(auth.isAuthenticated$ |async )">private</a>
|
<a class="nav-link" routerLink="private" *ngIf="(auth.isAuthenticated$ |async )">private</a>
|
||||||
</li>
|
</li>
|
||||||
@@ -17,10 +20,12 @@
|
|||||||
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
|
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
|
||||||
<button class="btn btn-outline-success" type="submit">Search</button>
|
<button class="btn btn-outline-success" type="submit">Search</button>
|
||||||
</form>
|
</form>
|
||||||
|
<li> </li>
|
||||||
|
<button class="btn btn-primary" (click)="loginWithRedirect()" *ngIf="!(auth.isAuthenticated$ | async)">Ingresar</button>
|
||||||
|
<button class="btn btn-danger" (click)="logout()" *ngIf="(auth.isAuthenticated$ | async)">salir</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button class="btn btn-primary" (click)="loginWithRedirect()" *ngIf="!(auth.isAuthenticated$ | async)">Ingresar</button>
|
|
||||||
<button class="btn btn-danger" (click)="logout()" *ngIf="(auth.isAuthenticated$ | async)">salir</button>
|
|
||||||
</nav>
|
</nav>
|
||||||
<div class="container mt-5">
|
<div class="container mt-5">
|
||||||
<router-outlet></router-outlet>
|
<router-outlet></router-outlet>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import {AuthService} from "@auth0/auth0-angular";
|
import {AuthService} from "@auth0/auth0-angular";
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
templateUrl: './app.component.html',
|
templateUrl: './app.component.html',
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
import { AppRoutingModule } from './app-routing.module';
|
import { AppRoutingModule } from './app-routing.module';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
|
||||||
import { AuthModule } from '@auth0/auth0-angular';
|
import { AuthModule, AuthHttpInterceptor } from '@auth0/auth0-angular';
|
||||||
import { PublicComponent } from './components/public/public.component';
|
import { PublicComponent } from './components/public/public.component';
|
||||||
import { PrivateComponent } from './components/private/private.component';
|
import { PrivateComponent } from './components/private/private.component';
|
||||||
|
import { AgregarResComponent } from './components/agregar-res/agregar-res.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
AppComponent,
|
AppComponent,
|
||||||
PublicComponent,
|
PublicComponent,
|
||||||
PrivateComponent
|
PrivateComponent,
|
||||||
|
AgregarResComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
@@ -21,10 +23,33 @@ import { PrivateComponent } from './components/private/private.component';
|
|||||||
domain: 'dev-ygnrzo5i.us.auth0.com',
|
domain: 'dev-ygnrzo5i.us.auth0.com',
|
||||||
clientId: '2MCYrmwNWAkeJyYYYRCS1gscDbiwAIfq',
|
clientId: '2MCYrmwNWAkeJyYYYRCS1gscDbiwAIfq',
|
||||||
cacheLocation: 'localstorage',
|
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]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
export class AppModule { }
|
export class AppModule { }
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<table *ngIf="restaurante">
|
||||||
|
<tr>
|
||||||
|
<td>id</td><td>nombre</td><td>creacion</td><td>modificacion</td>
|
||||||
|
</tr>
|
||||||
|
<tr *ngFor="let r of restaurante.data">
|
||||||
|
<td>{{r.id}}</td>
|
||||||
|
<td>{{r.nombre}}</td>
|
||||||
|
<td>{{r['created_at']}}</td>
|
||||||
|
<td>{{r['updated_at']}}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<pre *ngIf="auth.user$ | async as user">
|
<pre *ngIf="auth.user$ | async">
|
||||||
<code>
|
<code>
|
||||||
{{user | json}}
|
{{dato | json}}
|
||||||
</code>
|
</code>
|
||||||
</pre>
|
</pre>
|
||||||
|
|||||||
@@ -1,16 +1,31 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import {AuthService} from "@auth0/auth0-angular";
|
import {AuthService} from "@auth0/auth0-angular";
|
||||||
|
|
||||||
|
import { concatMap, tap, pluck } from 'rxjs/operators';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-private',
|
selector: 'app-private',
|
||||||
templateUrl: './private.component.html',
|
templateUrl: './private.component.html',
|
||||||
styleUrls: ['./private.component.scss']
|
styleUrls: ['./private.component.scss']
|
||||||
})
|
})
|
||||||
export class PrivateComponent implements OnInit {
|
export class PrivateComponent implements OnInit {
|
||||||
|
dato = {};
|
||||||
|
|
||||||
constructor(public auth: AuthService) { }
|
constructor(public auth: AuthService, private http: HttpClient) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
16
frontend/src/app/restaurantes.service.spec.ts
Normal file
16
frontend/src/app/restaurantes.service.spec.ts
Normal file
@@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
17
frontend/src/app/restaurantes.service.ts
Normal file
17
frontend/src/app/restaurantes.service.ts
Normal file
@@ -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`);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user