From 227c254ebc67678eecfb0cc517cd0f1d433c0e02 Mon Sep 17 00:00:00 2001 From: onsaliyo <gonzalo.mdvc@gmail.com> Date: Sun, 21 Feb 2021 11:11:11 +0100 Subject: [PATCH 01/10] =?UTF-8?q?creados=20api=20y=20login=20services=20co?= =?UTF-8?q?n=20funciones=20vac=C3=ADas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api.service.spec.ts | 16 ++++++++++++++++ src/app/api.service.ts | 33 +++++++++++++++++++++++++++++++++ src/app/app.module.ts | 3 ++- src/app/discoteca.ts | 9 +++++++++ src/app/login.service.ts | 23 ++++++++++++++++++++++- src/app/user.ts | 6 ++++++ 6 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 src/app/api.service.spec.ts create mode 100644 src/app/api.service.ts create mode 100644 src/app/user.ts diff --git a/src/app/api.service.spec.ts b/src/app/api.service.spec.ts new file mode 100644 index 0000000..c0310ae --- /dev/null +++ b/src/app/api.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { ApiService } from './api.service'; + +describe('ApiService', () => { + let service: ApiService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ApiService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/api.service.ts b/src/app/api.service.ts new file mode 100644 index 0000000..32381eb --- /dev/null +++ b/src/app/api.service.ts @@ -0,0 +1,33 @@ +import { Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { Observable, throwError } from 'rxjs'; +import { catchError, retry } from 'rxjs/operators'; +import { User } from './user'; +import { Discoteca } from './discoteca'; + +@Injectable({ + providedIn: 'root' +}) +export class ApiService { + + constructor(private http: HttpClient) { + + } + + + validateUser(loginUser: string, loginPassword: string): boolean{ + return (loginUser==''); + } + + getUser (loginUser: string): void{ + + } + + postNewUser(user: User): void{ + + } + + postNewDiscoteca(discoteca: Discoteca): void{ + + } +} diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 9ba0407..287c89e 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,5 +1,6 @@ import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; +import { HttpClientModule } from '@angular/common/http'; import { RouteReuseStrategy } from '@angular/router'; import { ReactiveFormsModule } from '@angular/forms'; import { IonicModule, IonicRouteStrategy } from '@ionic/angular'; @@ -15,7 +16,7 @@ import { LoginPage } from './login/login.page'; @NgModule({ declarations: [AppComponent, PerfilDiscotecaPage, PromptEventoPage, LoginPage], entryComponents: [], - imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, ReactiveFormsModule, GaleriamodalPageModule], + imports: [BrowserModule, HttpClientModule, IonicModule.forRoot(), AppRoutingModule, ReactiveFormsModule, GaleriamodalPageModule], providers: [ StatusBar, SplashScreen, diff --git a/src/app/discoteca.ts b/src/app/discoteca.ts index 63143b7..4ba5387 100644 --- a/src/app/discoteca.ts +++ b/src/app/discoteca.ts @@ -8,6 +8,7 @@ export class Discoteca { private telefono: number; private localizacion: string; private eventos: Evento[]; + private descripcion: string; setNombre(nombre: string): void{ @@ -37,4 +38,12 @@ export class Discoteca { getEventos(): Evento[]{ return this.eventos; } + + setDescripcion(desc: string): void{ + this.descripcion = desc; + } + + get Descripcion(): string{ + return this.descripcion; + } } diff --git a/src/app/login.service.ts b/src/app/login.service.ts index 92c777e..2e1fcfe 100644 --- a/src/app/login.service.ts +++ b/src/app/login.service.ts @@ -1,9 +1,30 @@ import { Injectable } from '@angular/core'; +import { ApiService } from './api.service'; +import { User } from './user'; @Injectable({ providedIn: 'root' }) export class LoginService { - constructor() { } + private userId: number; + private sessionType: number; + private loginUser: string; + private loginPassword: string; + + constructor(private apiService: ApiService) { + + } + + validateUser(loginUser: string, loginPassword: string): boolean{ + return (loginUser==''); + } + + getUser (loginUser: string): void{ + + } + + postNewUser(user: User): void{ + + } } diff --git a/src/app/user.ts b/src/app/user.ts new file mode 100644 index 0000000..72434d2 --- /dev/null +++ b/src/app/user.ts @@ -0,0 +1,6 @@ +export interface User { + userId: number; + userType: number; + loginUser: string; + loginPassword: string; +} From b9d95793dc3371f388314d309aee9d456d204121 Mon Sep 17 00:00:00 2001 From: onsaliyo <gonzalo.mdvc@gmail.com> Date: Sun, 21 Feb 2021 12:21:18 +0100 Subject: [PATCH 02/10] =?UTF-8?q?a=C3=B1adida=20interfaz=20discoteca?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/discoteca-i.ts | 2 ++ src/app/discoteca.ts | 2 +- src/app/perfil-discoteca/perfil-discoteca.page.ts | 5 +++++ src/app/tab1/tab1.service.ts | 5 +++++ 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/app/discoteca-i.ts diff --git a/src/app/discoteca-i.ts b/src/app/discoteca-i.ts new file mode 100644 index 0000000..522adda --- /dev/null +++ b/src/app/discoteca-i.ts @@ -0,0 +1,2 @@ +export interface DiscotecaI { +} diff --git a/src/app/discoteca.ts b/src/app/discoteca.ts index 4ba5387..8114e04 100644 --- a/src/app/discoteca.ts +++ b/src/app/discoteca.ts @@ -43,7 +43,7 @@ export class Discoteca { this.descripcion = desc; } - get Descripcion(): string{ + getDescripcion(): string{ return this.descripcion; } } diff --git a/src/app/perfil-discoteca/perfil-discoteca.page.ts b/src/app/perfil-discoteca/perfil-discoteca.page.ts index deeaeb9..f87e339 100644 --- a/src/app/perfil-discoteca/perfil-discoteca.page.ts +++ b/src/app/perfil-discoteca/perfil-discoteca.page.ts @@ -20,6 +20,7 @@ export class PerfilDiscotecaPage implements OnInit { nombre: string; telefono: number; localizacion: string; + descripcion: string; fotoSrc: string; fotoLoaded: string; someURL: string; @@ -73,6 +74,10 @@ export class PerfilDiscotecaPage implements OnInit { this.eventos = this.tab1Service.getEventos(); } + getDescripcion(): void{ + this.descripcion = this.tab1Service.getDescripcion(); + } + cargarImagen(){ this.fotoSrc = this.someURL; } diff --git a/src/app/tab1/tab1.service.ts b/src/app/tab1/tab1.service.ts index c07d3c7..8bb4d48 100644 --- a/src/app/tab1/tab1.service.ts +++ b/src/app/tab1/tab1.service.ts @@ -56,6 +56,11 @@ export class Tab1Service implements OnInit{ return this.eventos; } + getDescripcion(): string{ + this.initValues(); + return this.discoteca.getDescripcion(); + } + initEventos(): void{ this.eventos = []; } From 659783d23fc6f5ea29e8f7527cca595f3ca913e4 Mon Sep 17 00:00:00 2001 From: onsaliyo <gonzalo.mdvc@gmail.com> Date: Mon, 22 Feb 2021 20:09:15 +0100 Subject: [PATCH 03/10] metodos e interfaces de login actualizados --- src/app/api.service.ts | 18 ++++++------------ src/app/login.service.ts | 22 +++++++++------------- src/app/user-login.ts | 4 ++++ 3 files changed, 19 insertions(+), 25 deletions(-) create mode 100644 src/app/user-login.ts diff --git a/src/app/api.service.ts b/src/app/api.service.ts index 32381eb..b513eb1 100644 --- a/src/app/api.service.ts +++ b/src/app/api.service.ts @@ -4,30 +4,24 @@ import { Observable, throwError } from 'rxjs'; import { catchError, retry } from 'rxjs/operators'; import { User } from './user'; import { Discoteca } from './discoteca'; +import { UserLogin } from './user-login'; @Injectable({ providedIn: 'root' }) export class ApiService { + url = ''; + constructor(private http: HttpClient) { } - validateUser(loginUser: string, loginPassword: string): boolean{ - return (loginUser==''); + validateUser(user: UserLogin): Observable<User>{ + + return this.http.post<User>(this.url, user); } - getUser (loginUser: string): void{ - } - - postNewUser(user: User): void{ - - } - - postNewDiscoteca(discoteca: Discoteca): void{ - - } } diff --git a/src/app/login.service.ts b/src/app/login.service.ts index 2e1fcfe..f0fde60 100644 --- a/src/app/login.service.ts +++ b/src/app/login.service.ts @@ -1,30 +1,26 @@ import { Injectable } from '@angular/core'; import { ApiService } from './api.service'; import { User } from './user'; +import { UserLogin } from './user-login' @Injectable({ providedIn: 'root' }) export class LoginService { - private userId: number; - private sessionType: number; - private loginUser: string; - private loginPassword: string; + user: User; constructor(private apiService: ApiService) { } - validateUser(loginUser: string, loginPassword: string): boolean{ - return (loginUser==''); + validateUser(login: string, password: string): void{ + let user : UserLogin = { + loginUser: login, + loginPassword: password, + } + this.apiService.validateUser(user) + .subscribe((data: User) => this.user = {...data}); } - getUser (loginUser: string): void{ - - } - - postNewUser(user: User): void{ - - } } diff --git a/src/app/user-login.ts b/src/app/user-login.ts new file mode 100644 index 0000000..f0cc9b0 --- /dev/null +++ b/src/app/user-login.ts @@ -0,0 +1,4 @@ +export interface UserLogin { + loginUser: string; + loginPassword: string; +} From f1bf8ff75ebde1ecd9fbdea042034fdc270d5c89 Mon Sep 17 00:00:00 2001 From: onsaliyo <gonzalo.mdvc@gmail.com> Date: Mon, 8 Mar 2021 13:33:27 +0100 Subject: [PATCH 04/10] =?UTF-8?q?Montada=20comunicaci=C3=B3n=20con=20API,?= =?UTF-8?q?=20pero=20devuelve=20un=20objeto=20undefined?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api.service.ts | 10 ++++++---- src/app/app-routing.module.ts | 2 +- src/app/login.service.ts | 28 +++++++++++++++++++++------- src/app/login/login.page.html | 7 +++++++ src/app/login/login.page.scss | 3 +++ src/app/login/login.page.ts | 18 +++++++++++++++--- src/app/user.ts | 6 +++--- 7 files changed, 56 insertions(+), 18 deletions(-) diff --git a/src/app/api.service.ts b/src/app/api.service.ts index b513eb1..b9bd55d 100644 --- a/src/app/api.service.ts +++ b/src/app/api.service.ts @@ -1,17 +1,18 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; -import { Observable, throwError } from 'rxjs'; -import { catchError, retry } from 'rxjs/operators'; +import { Observable, throwError, BehaviorSubject } from 'rxjs'; +import { catchError, retry, map, tap } from 'rxjs/operators'; import { User } from './user'; import { Discoteca } from './discoteca'; import { UserLogin } from './user-login'; + @Injectable({ providedIn: 'root' }) export class ApiService { - url = ''; + constructor(private http: HttpClient) { @@ -20,8 +21,9 @@ export class ApiService { validateUser(user: UserLogin): Observable<User>{ - return this.http.post<User>(this.url, user); + return this.http.post<User>("http://localhost:3307/api/consultas/users", user); } + } diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 7675048..c4f4dc7 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -23,7 +23,7 @@ const routes: Routes = [ }, { path:'', - redirectTo: 'tabs', + redirectTo: 'login', pathMatch: 'full' }, diff --git a/src/app/login.service.ts b/src/app/login.service.ts index f0fde60..beaf043 100644 --- a/src/app/login.service.ts +++ b/src/app/login.service.ts @@ -1,7 +1,9 @@ import { Injectable } from '@angular/core'; +import { Router } from '@angular/router'; import { ApiService } from './api.service'; import { User } from './user'; -import { UserLogin } from './user-login' +import { UserLogin } from './user-login'; + @Injectable({ providedIn: 'root' @@ -10,17 +12,29 @@ export class LoginService { user: User; - constructor(private apiService: ApiService) { - + constructor(private apiService: ApiService, private router: Router) { + this.user = { + id: 0, + userType: 0, + username: '', + password: '' + }; } - validateUser(login: string, password: string): void{ - let user : UserLogin = { + validateUser(login: string, password: string): User { + + let userlogin: UserLogin = { loginUser: login, loginPassword: password, } - this.apiService.validateUser(user) - .subscribe((data: User) => this.user = {...data}); + + this.apiService.validateUser(userlogin) + .subscribe(user => this.user = user) + + return this.user; + } + + } diff --git a/src/app/login/login.page.html b/src/app/login/login.page.html index 1a77f8b..cacbd4a 100644 --- a/src/app/login/login.page.html +++ b/src/app/login/login.page.html @@ -5,7 +5,14 @@ </ion-header> <ion-content> + <span>Usuario: </span><input type="text" id="username"> + <span>ContraseƱa: </span><input type="text" id="password"> <ion-button (click)="login()"> Login </ion-button> + <div> + <div *ngIf="user"> + {{user.username}} + </div> + </div> </ion-content> diff --git a/src/app/login/login.page.scss b/src/app/login/login.page.scss index e69de29..1bdc99e 100644 --- a/src/app/login/login.page.scss +++ b/src/app/login/login.page.scss @@ -0,0 +1,3 @@ +input{ + color: black; +} \ No newline at end of file diff --git a/src/app/login/login.page.ts b/src/app/login/login.page.ts index 75a025e..f8de934 100644 --- a/src/app/login/login.page.ts +++ b/src/app/login/login.page.ts @@ -1,5 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; +import { LoginService } from '../login.service'; +import { User } from '../user'; @Component({ selector: 'app-login', @@ -8,13 +10,23 @@ import { Router } from '@angular/router'; }) export class LoginPage implements OnInit { - constructor(private router: Router) { } + username: string; + password: string; + user: User; + + constructor(private router: Router, private loginService: LoginService) { } ngOnInit() { + this.user = this.loginService.user; } - login(){ - this.router.navigate(['/tabs']); + async login() { + + this.username = (<HTMLInputElement>document.getElementById("username")).value; + this.password = (<HTMLInputElement>document.getElementById("password")).value; + this.user = await this.loginService.validateUser(this.username, this.password); + console.log(this.user.username); + } } diff --git a/src/app/user.ts b/src/app/user.ts index 72434d2..5f9dd3f 100644 --- a/src/app/user.ts +++ b/src/app/user.ts @@ -1,6 +1,6 @@ export interface User { - userId: number; + id: number; userType: number; - loginUser: string; - loginPassword: string; + username: string; + password: string; } From 36426bc6434fc3fb7f8d66812cc7e5008d365f2e Mon Sep 17 00:00:00 2001 From: onsaliyo <gonzalo.mdvc@gmail.com> Date: Tue, 16 Mar 2021 10:23:46 +0100 Subject: [PATCH 05/10] =?UTF-8?q?Comunicaci=C3=B3n=20con=20backend.=20Perm?= =?UTF-8?q?ite=20cargar=20un=20usuario=20de=20la=20BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api.service.ts | 4 +++- src/app/login.service.ts | 11 ++++++----- src/app/login/login.page.ts | 6 +++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/app/api.service.ts b/src/app/api.service.ts index b9bd55d..b3c7cf4 100644 --- a/src/app/api.service.ts +++ b/src/app/api.service.ts @@ -21,9 +21,11 @@ export class ApiService { validateUser(user: UserLogin): Observable<User>{ - return this.http.post<User>("http://localhost:3307/api/consultas/users", user); + return this.http.post<User>("http://localhost:3307/api/consultas/users", user) + } + } diff --git a/src/app/login.service.ts b/src/app/login.service.ts index beaf043..1b7225a 100644 --- a/src/app/login.service.ts +++ b/src/app/login.service.ts @@ -1,5 +1,6 @@ import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; +import { VirtualTimeScheduler } from 'rxjs'; import { ApiService } from './api.service'; import { User } from './user'; import { UserLogin } from './user-login'; @@ -21,7 +22,7 @@ export class LoginService { }; } - validateUser(login: string, password: string): User { + validateUser(login: string, password: string): void{ let userlogin: UserLogin = { loginUser: login, @@ -29,12 +30,12 @@ export class LoginService { } this.apiService.validateUser(userlogin) - .subscribe(user => this.user = user) - - return this.user; + .subscribe(user => { + this.user = user; + console.log(this.user); + }) } - } diff --git a/src/app/login/login.page.ts b/src/app/login/login.page.ts index f8de934..3016ca9 100644 --- a/src/app/login/login.page.ts +++ b/src/app/login/login.page.ts @@ -20,12 +20,12 @@ export class LoginPage implements OnInit { this.user = this.loginService.user; } - async login() { + login() { this.username = (<HTMLInputElement>document.getElementById("username")).value; this.password = (<HTMLInputElement>document.getElementById("password")).value; - this.user = await this.loginService.validateUser(this.username, this.password); - console.log(this.user.username); + this.loginService.validateUser(this.username, this.password) + } From de5a925e388187346bb4dbe7947e9cb83a4567dc Mon Sep 17 00:00:00 2001 From: onsaliyo <gonzalo.mdvc@gmail.com> Date: Wed, 17 Mar 2021 21:19:42 +0100 Subject: [PATCH 06/10] Redefinida interfaz user --- src/app/login.service.ts | 2 +- src/app/user.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/login.service.ts b/src/app/login.service.ts index 1b7225a..6e8f283 100644 --- a/src/app/login.service.ts +++ b/src/app/login.service.ts @@ -16,9 +16,9 @@ export class LoginService { constructor(private apiService: ApiService, private router: Router) { this.user = { id: 0, + discotecaId: 0, userType: 0, username: '', - password: '' }; } diff --git a/src/app/user.ts b/src/app/user.ts index 5f9dd3f..78fb1f5 100644 --- a/src/app/user.ts +++ b/src/app/user.ts @@ -1,6 +1,6 @@ export interface User { id: number; + discotecaId: number; userType: number; username: string; - password: string; } From 660f19932cc92e53d0fcec5e633935710b93ab02 Mon Sep 17 00:00:00 2001 From: onsaliyo <gonzalo.mdvc@gmail.com> Date: Thu, 18 Mar 2021 18:04:58 +0100 Subject: [PATCH 07/10] Si el usuario es tipo 0 (gestor de discoteca) muestra la discoteca asociada al gestor en la BD --- src/app/api.service.ts | 11 +++++++++-- src/app/discoteca-i.ts | 4 ++++ src/app/login.service.ts | 10 +++++++--- src/app/tab1/tab1.service.ts | 24 ++++++++++++++++++++---- src/app/user.ts | 2 +- 5 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/app/api.service.ts b/src/app/api.service.ts index b3c7cf4..58e806e 100644 --- a/src/app/api.service.ts +++ b/src/app/api.service.ts @@ -5,6 +5,7 @@ import { catchError, retry, map, tap } from 'rxjs/operators'; import { User } from './user'; import { Discoteca } from './discoteca'; import { UserLogin } from './user-login'; +import { DiscotecaI } from './discoteca-i'; @Injectable({ @@ -12,7 +13,7 @@ import { UserLogin } from './user-login'; }) export class ApiService { - + baseUrl = "http://localhost:3307/api/consultas"; constructor(private http: HttpClient) { @@ -21,10 +22,16 @@ export class ApiService { validateUser(user: UserLogin): Observable<User>{ - return this.http.post<User>("http://localhost:3307/api/consultas/users", user) + return this.http.post<User>(this.baseUrl+"/users", user) } + getUserDiscoteca(discotecaId: number): Observable<DiscotecaI>{ + + return this.http.post<DiscotecaI>(this.baseUrl+"/discoteca", { "id": discotecaId}); + + } + diff --git a/src/app/discoteca-i.ts b/src/app/discoteca-i.ts index 522adda..a3274f1 100644 --- a/src/app/discoteca-i.ts +++ b/src/app/discoteca-i.ts @@ -1,2 +1,6 @@ export interface DiscotecaI { + discotecaId: number, + nombre: string, + telefono: number, + localizacion: string } diff --git a/src/app/login.service.ts b/src/app/login.service.ts index 6e8f283..8652c71 100644 --- a/src/app/login.service.ts +++ b/src/app/login.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { VirtualTimeScheduler } from 'rxjs'; import { ApiService } from './api.service'; +import { Tab1Service } from './tab1/tab1.service'; import { User } from './user'; import { UserLogin } from './user-login'; @@ -13,10 +14,10 @@ export class LoginService { user: User; - constructor(private apiService: ApiService, private router: Router) { + constructor(private apiService: ApiService, private router: Router, private tab1service: Tab1Service) { this.user = { id: 0, - discotecaId: 0, + discotecaID: 0, userType: 0, username: '', }; @@ -31,8 +32,11 @@ export class LoginService { this.apiService.validateUser(userlogin) .subscribe(user => { - this.user = user; + this.user = user[0]; console.log(this.user); + console.log(this.user.discotecaID); + this.tab1service.getDiscoteca(this.user.discotecaID); + }) } diff --git a/src/app/tab1/tab1.service.ts b/src/app/tab1/tab1.service.ts index 8bb4d48..1b98cd3 100644 --- a/src/app/tab1/tab1.service.ts +++ b/src/app/tab1/tab1.service.ts @@ -5,6 +5,9 @@ import { Discoteca } from '../discoteca' import { Evento } from '../evento'; import { FormControl, FormGroup } from '@angular/forms'; import { NumericValueAccessor } from '@ionic/angular'; +import { DiscotecaI } from '../discoteca-i'; +import { ApiService } from '../api.service'; +import { Router } from '@angular/router'; @Injectable({ @@ -13,13 +16,14 @@ import { NumericValueAccessor } from '@ionic/angular'; export class Tab1Service implements OnInit{ discoteca: Discoteca; + discotecaI: DiscotecaI; galeria: string[]; eventos: Evento[]; eventoForms: FormGroup[]; eventoIndex: number; editarEvento: boolean; - constructor() { + constructor(private apiService: ApiService, private router: Router) { } @@ -29,9 +33,9 @@ export class Tab1Service implements OnInit{ initValues(): void{ this.discoteca = new Discoteca(); - this.discoteca.setNombre('Barraca'); - this.discoteca.setTelefono(666666666); - this.discoteca.setLocalizacion('Calle del Barquillo'); + this.discoteca.setNombre(this.discotecaI.nombre); + this.discoteca.setTelefono(this.discotecaI.telefono); + this.discoteca.setLocalizacion(this.discotecaI.localizacion); this.galeria = []; this.initEventos(); this.editarEvento = false; @@ -73,4 +77,16 @@ export class Tab1Service implements OnInit{ return this.eventos[eventoIndex]; } + getDiscoteca(discotecaId: number){ + if (discotecaId != 0){ + this.apiService.getUserDiscoteca(discotecaId) + .subscribe(discoteca => { + this.discotecaI = discoteca[0]; + console.log(this.discotecaI); + this.initValues(); + this.router.navigate(['/tabs/tab1/perfil-discoteca']); + }) + } + } + } diff --git a/src/app/user.ts b/src/app/user.ts index 78fb1f5..f40b02f 100644 --- a/src/app/user.ts +++ b/src/app/user.ts @@ -1,6 +1,6 @@ export interface User { id: number; - discotecaId: number; + discotecaID: number; userType: number; username: string; } From f6756c25a89ee08ab54ea6b49295ac3c3eb61b95 Mon Sep 17 00:00:00 2001 From: onsaliyo <gonzalo.mdvc@gmail.com> Date: Thu, 18 Mar 2021 18:56:19 +0100 Subject: [PATCH 08/10] =?UTF-8?q?reorganizaci=C3=B3n=20con=20carpetas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/{ => interfaces}/discoteca-i.ts | 0 src/app/interfaces/eventoi.ts | 2 ++ src/app/{ => interfaces}/user-login.ts | 0 src/app/{ => interfaces}/user.ts | 0 src/app/login/login.page.ts | 4 ++-- src/app/{ => services}/api.service.spec.ts | 0 src/app/{ => services}/api.service.ts | 8 ++++---- src/app/{ => services}/login.service.spec.ts | 0 src/app/{ => services}/login.service.ts | 6 +++--- src/app/tab1/tab1.service.ts | 4 ++-- 10 files changed, 13 insertions(+), 11 deletions(-) rename src/app/{ => interfaces}/discoteca-i.ts (100%) create mode 100644 src/app/interfaces/eventoi.ts rename src/app/{ => interfaces}/user-login.ts (100%) rename src/app/{ => interfaces}/user.ts (100%) rename src/app/{ => services}/api.service.spec.ts (100%) rename src/app/{ => services}/api.service.ts (77%) rename src/app/{ => services}/login.service.spec.ts (100%) rename src/app/{ => services}/login.service.ts (85%) diff --git a/src/app/discoteca-i.ts b/src/app/interfaces/discoteca-i.ts similarity index 100% rename from src/app/discoteca-i.ts rename to src/app/interfaces/discoteca-i.ts diff --git a/src/app/interfaces/eventoi.ts b/src/app/interfaces/eventoi.ts new file mode 100644 index 0000000..961d4e7 --- /dev/null +++ b/src/app/interfaces/eventoi.ts @@ -0,0 +1,2 @@ +export interface Eventoi { +} diff --git a/src/app/user-login.ts b/src/app/interfaces/user-login.ts similarity index 100% rename from src/app/user-login.ts rename to src/app/interfaces/user-login.ts diff --git a/src/app/user.ts b/src/app/interfaces/user.ts similarity index 100% rename from src/app/user.ts rename to src/app/interfaces/user.ts diff --git a/src/app/login/login.page.ts b/src/app/login/login.page.ts index 3016ca9..c33e6a8 100644 --- a/src/app/login/login.page.ts +++ b/src/app/login/login.page.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; -import { LoginService } from '../login.service'; -import { User } from '../user'; +import { LoginService } from '../services/login.service'; +import { User } from '../interfaces/user'; @Component({ selector: 'app-login', diff --git a/src/app/api.service.spec.ts b/src/app/services/api.service.spec.ts similarity index 100% rename from src/app/api.service.spec.ts rename to src/app/services/api.service.spec.ts diff --git a/src/app/api.service.ts b/src/app/services/api.service.ts similarity index 77% rename from src/app/api.service.ts rename to src/app/services/api.service.ts index 58e806e..cf30afc 100644 --- a/src/app/api.service.ts +++ b/src/app/services/api.service.ts @@ -2,10 +2,10 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable, throwError, BehaviorSubject } from 'rxjs'; import { catchError, retry, map, tap } from 'rxjs/operators'; -import { User } from './user'; -import { Discoteca } from './discoteca'; -import { UserLogin } from './user-login'; -import { DiscotecaI } from './discoteca-i'; +import { User } from '../interfaces/user'; +import { Discoteca } from '../discoteca'; +import { UserLogin } from '../interfaces/user-login'; +import { DiscotecaI } from '../interfaces/discoteca-i'; @Injectable({ diff --git a/src/app/login.service.spec.ts b/src/app/services/login.service.spec.ts similarity index 100% rename from src/app/login.service.spec.ts rename to src/app/services/login.service.spec.ts diff --git a/src/app/login.service.ts b/src/app/services/login.service.ts similarity index 85% rename from src/app/login.service.ts rename to src/app/services/login.service.ts index 8652c71..977a8b3 100644 --- a/src/app/login.service.ts +++ b/src/app/services/login.service.ts @@ -2,9 +2,9 @@ import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; import { VirtualTimeScheduler } from 'rxjs'; import { ApiService } from './api.service'; -import { Tab1Service } from './tab1/tab1.service'; -import { User } from './user'; -import { UserLogin } from './user-login'; +import { Tab1Service } from '../tab1/tab1.service'; +import { User } from '../interfaces/user'; +import { UserLogin } from '../interfaces/user-login'; @Injectable({ diff --git a/src/app/tab1/tab1.service.ts b/src/app/tab1/tab1.service.ts index 1b98cd3..7df4ad2 100644 --- a/src/app/tab1/tab1.service.ts +++ b/src/app/tab1/tab1.service.ts @@ -5,8 +5,8 @@ import { Discoteca } from '../discoteca' import { Evento } from '../evento'; import { FormControl, FormGroup } from '@angular/forms'; import { NumericValueAccessor } from '@ionic/angular'; -import { DiscotecaI } from '../discoteca-i'; -import { ApiService } from '../api.service'; +import { DiscotecaI } from '../interfaces/discoteca-i'; +import { ApiService } from '../services/api.service'; import { Router } from '@angular/router'; From 4b2d8cf7b692b7406bdbc8e40f8c316d2b3ecd3d Mon Sep 17 00:00:00 2001 From: onsaliyo <gonzalo.mdvc@gmail.com> Date: Sat, 20 Mar 2021 13:21:50 +0100 Subject: [PATCH 09/10] Se suben eventos a la BD, asociados a la discoteca del usuario --- src/app/discoteca.ts | 7 +++ src/app/evento.ts | 10 ++-- src/app/interfaces/discoteca-i.ts | 2 +- src/app/interfaces/eventoi.ts | 12 ++++ src/app/prompt-evento/prompt-evento.page.html | 13 ++++- src/app/prompt-evento/prompt-evento.page.ts | 56 ++++++++++++++----- src/app/services/api.service.ts | 7 +++ src/app/tab1/tab1.service.ts | 14 +++++ 8 files changed, 102 insertions(+), 19 deletions(-) diff --git a/src/app/discoteca.ts b/src/app/discoteca.ts index 8114e04..8438b79 100644 --- a/src/app/discoteca.ts +++ b/src/app/discoteca.ts @@ -10,6 +10,13 @@ export class Discoteca { private eventos: Evento[]; private descripcion: string; + setId(id: number): void{ + this.id = id; + } + + getId(): number{ + return this.id; + } setNombre(nombre: string): void{ this.nombre = nombre; diff --git a/src/app/evento.ts b/src/app/evento.ts index 0471ab1..4ce12b3 100644 --- a/src/app/evento.ts +++ b/src/app/evento.ts @@ -1,10 +1,12 @@ +import { Time } from "@angular/common"; + export class Evento { private id: number; nombre: string; localizacion: string; fecha: Date; dia: string; - hora: string; + hora: Time; descripcion: string; precio1: number; precio2: number; @@ -49,11 +51,11 @@ export class Evento { return this.dia; } - setHora(fecha: Date): void{ - this.hora = fecha.getHours()+":"+fecha.getMinutes(); + setHora(time: Time): void{ + this.hora = time; } - getHora(): string{ + getHora(): Time{ return this.hora; } diff --git a/src/app/interfaces/discoteca-i.ts b/src/app/interfaces/discoteca-i.ts index a3274f1..c5e5c93 100644 --- a/src/app/interfaces/discoteca-i.ts +++ b/src/app/interfaces/discoteca-i.ts @@ -1,5 +1,5 @@ export interface DiscotecaI { - discotecaId: number, + discotecaID: number, nombre: string, telefono: number, localizacion: string diff --git a/src/app/interfaces/eventoi.ts b/src/app/interfaces/eventoi.ts index 961d4e7..8926fb3 100644 --- a/src/app/interfaces/eventoi.ts +++ b/src/app/interfaces/eventoi.ts @@ -1,2 +1,14 @@ +import { Time } from "@angular/common"; + export interface Eventoi { + + discotecaID: number, + nombre: string, + localizacion: string, + fecha: Date, + hora: Time, + descripcion: string, + precio1: number, + precio2: number, + } diff --git a/src/app/prompt-evento/prompt-evento.page.html b/src/app/prompt-evento/prompt-evento.page.html index 94845bd..8e2cd63 100644 --- a/src/app/prompt-evento/prompt-evento.page.html +++ b/src/app/prompt-evento/prompt-evento.page.html @@ -21,7 +21,7 @@ <ion-item> <label> Fecha: - <ion-datetime displayFormat="DD/MM, HH:mm"placeholder="Elegir Fecha" formControlName="fecha"></ion-datetime> + <ion-datetime displayFormat="YYYY/DD/MM"placeholder="Elegir Fecha" formControlName="fecha"></ion-datetime> </label> <span *ngIf="fecha.errors.required && submitted"> @@ -29,6 +29,17 @@ </span> </ion-item> + <ion-item> + <label> + Hora + <ion-datetime displayFormat="HH:MM"placeholder="Elegir Hora" formControlName="hora"></ion-datetime> + </label> + <span + *ngIf="hora.errors.required && submitted"> + Tu evento necesita una hora + </span> + </ion-item> + <ion-item> <label> diff --git a/src/app/prompt-evento/prompt-evento.page.ts b/src/app/prompt-evento/prompt-evento.page.ts index 7711c91..0e44ac1 100644 --- a/src/app/prompt-evento/prompt-evento.page.ts +++ b/src/app/prompt-evento/prompt-evento.page.ts @@ -3,6 +3,9 @@ import { FormControl, FormGroup, Validators } from '@angular/forms'; import { Tab1Service } from '../tab1/tab1.service'; import { Evento } from '../evento'; import { Router } from '@angular/router'; +import { Eventoi } from '../interfaces/eventoi'; +import { DatePipe } from '@angular/common' +import { ViewEventoPageRoutingModule } from '../view-evento/view-evento-routing.module'; @Component({ selector: 'app-prompt-evento', @@ -10,17 +13,17 @@ import { Router } from '@angular/router'; styleUrls: ['./prompt-evento.page.scss'], }) export class PromptEventoPage implements OnInit{ - submitted = false; eventoForm = new FormGroup({ - nombre: new FormControl('', Validators.required), - fecha: new FormControl('', Validators.required), - precio1: new FormControl('', Validators.required), - precio2: new FormControl('', Validators.required), - descripcion: new FormControl('', Validators.required), + nombre: new FormControl(null, Validators.required), + fecha: new FormControl(null, Validators.required), + hora: new FormControl(null, Validators.required), + precio1: new FormControl(null, Validators.required), + precio2: new FormControl(null, Validators.required), + descripcion: new FormControl(null, Validators.required), }); - eventos: Evento[]; + eventos: Eventoi[]; constructor(private tab1Service: Tab1Service, private router: Router) { @@ -36,28 +39,38 @@ export class PromptEventoPage implements OnInit{ if (this.eventoForm.valid){ let evento = new Evento(); this.asignarEvento(evento); - this.router.navigate(['/tabs']); + } } asignarEvento(evento: Evento){ evento.setNombre(this.eventoForm.get('nombre').value); evento.setDesc(this.eventoForm.get('descripcion').value); - evento.setFecha(this.eventoForm.get('fecha').value); + var fecha = this.eventoForm.get('fecha').value; + fecha = fecha.split("T")[0]; + evento.setFecha(fecha); + var hora = this.eventoForm.get('hora').value; + hora = hora.split("T")[1]; + hora = hora.split(":")[0]+(":")+hora.split(":")[1]; + evento.setHora(hora); evento.setPrecio1(this.eventoForm.get('precio1').value); evento.setPrecio2(this.eventoForm.get('precio2').value); //evento.setDia(evento.getFecha()); el datetime de Ion devuelve un String, no se puede - //evento.setHora(evento.getFecha()); transformar en dia y hora if (!this.tab1Service.eventos){ this.tab1Service.initEventos();} if(!this.tab1Service.eventoForms){ this.tab1Service.initEventoForms();} + let eventoInterface = this.interfaceEvento(evento); if(this.tab1Service.editarEvento==true){ - this.tab1Service.eventos[this.tab1Service.eventoIndex] = evento; - this.tab1Service.eventoForms[this.tab1Service.eventoIndex] = this.eventoForm; + this.tab1Service.updateEvento(eventoInterface); + //this.tab1Service.eventos[this.tab1Service.eventoIndex] = evento; + //this.tab1Service.eventoForms[this.tab1Service.eventoIndex] = this.eventoForm; } else{ this.tab1Service.eventos.push(evento); - this.tab1Service.eventoForms.push(this.eventoForm);} + this.tab1Service.postEvento(eventoInterface); + //this.tab1Service.eventos.push(evento); + //this.tab1Service.eventoForms.push(this.eventoForm); + } } @@ -84,6 +97,23 @@ export class PromptEventoPage implements OnInit{ get descripcion(){ return this.eventoForm.get('descripcion'); } + + interfaceEvento(evento: Evento): Eventoi{ + let eventoInterface: Eventoi; + eventoInterface = { + discotecaID: this.tab1Service.discotecaI.discotecaID, + nombre: evento.nombre, + localizacion: this.tab1Service.discotecaI.localizacion, + fecha: evento.fecha, + hora: evento.hora, + descripcion: evento.descripcion, + precio1: evento.precio1, + precio2: evento.precio2, + } + + return eventoInterface; + } + } diff --git a/src/app/services/api.service.ts b/src/app/services/api.service.ts index cf30afc..9c3bd9a 100644 --- a/src/app/services/api.service.ts +++ b/src/app/services/api.service.ts @@ -6,6 +6,7 @@ import { User } from '../interfaces/user'; import { Discoteca } from '../discoteca'; import { UserLogin } from '../interfaces/user-login'; import { DiscotecaI } from '../interfaces/discoteca-i'; +import { Eventoi } from '../interfaces/eventoi'; @Injectable({ @@ -32,6 +33,12 @@ export class ApiService { } + postEvento(eventoInterface: Eventoi): Observable<Eventoi>{ + + return this.http.post<Eventoi>(this.baseUrl+"/evento", eventoInterface); + + } + diff --git a/src/app/tab1/tab1.service.ts b/src/app/tab1/tab1.service.ts index 7df4ad2..aa1db15 100644 --- a/src/app/tab1/tab1.service.ts +++ b/src/app/tab1/tab1.service.ts @@ -8,6 +8,7 @@ import { NumericValueAccessor } from '@ionic/angular'; import { DiscotecaI } from '../interfaces/discoteca-i'; import { ApiService } from '../services/api.service'; import { Router } from '@angular/router'; +import { Eventoi } from '../interfaces/eventoi'; @Injectable({ @@ -33,6 +34,7 @@ export class Tab1Service implements OnInit{ initValues(): void{ this.discoteca = new Discoteca(); + this.discoteca.setId(this.discotecaI.discotecaID); this.discoteca.setNombre(this.discotecaI.nombre); this.discoteca.setTelefono(this.discotecaI.telefono); this.discoteca.setLocalizacion(this.discotecaI.localizacion); @@ -89,4 +91,16 @@ export class Tab1Service implements OnInit{ } } + postEvento(evento: Eventoi){ + this.apiService.postEvento(evento) + .subscribe(evento => { + this.router.navigate(['/tabs']); + }) + + } + + updateEvento(evento: Eventoi){ + + } + } From bc2d935506226fee20dfed47c74f56b92925a2c9 Mon Sep 17 00:00:00 2001 From: onsaliyo <gonzalo.mdvc@gmail.com> Date: Thu, 25 Mar 2021 12:29:41 +0100 Subject: [PATCH 10/10] =?UTF-8?q?Se=20muestran=20los=20eventos=20asociados?= =?UTF-8?q?=20a=20la=20disco=20en=20la=20BD.=20No=20se=20muestran,=20y=20d?= =?UTF-8?q?eber=C3=ADan,=20los=20reci=C3=A9n=20a=C3=B1adidos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/evento.spec.ts | 7 -- src/app/evento.ts | 77 ------------------- src/app/interfaces/eventoi.ts | 2 +- .../perfil-discoteca/perfil-discoteca.page.ts | 15 ++-- src/app/prompt-evento/prompt-evento.page.ts | 54 ++++++------- src/app/services/api.service.ts | 6 ++ src/app/tab1/tab1.service.ts | 26 ++++--- 7 files changed, 52 insertions(+), 135 deletions(-) delete mode 100644 src/app/evento.spec.ts delete mode 100644 src/app/evento.ts diff --git a/src/app/evento.spec.ts b/src/app/evento.spec.ts deleted file mode 100644 index e2e7d95..0000000 --- a/src/app/evento.spec.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Evento } from './evento'; - -describe('Evento', () => { - it('should create an instance', () => { - expect(new Evento()).toBeTruthy(); - }); -}); diff --git a/src/app/evento.ts b/src/app/evento.ts deleted file mode 100644 index 4ce12b3..0000000 --- a/src/app/evento.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { Time } from "@angular/common"; - -export class Evento { - private id: number; - nombre: string; - localizacion: string; - fecha: Date; - dia: string; - hora: Time; - descripcion: string; - precio1: number; - precio2: number; - - setNombre(nombre: string): void{ - this.nombre = nombre; - } - - getNombre(): string{ - return this.nombre; - } - - setLocalizacion(localizacion: string): void{ - this.localizacion = localizacion; - } - - getLocalizacion(): string{ - return this.localizacion - } - - setFecha(fecha: Date): void{ - this.fecha = fecha; - } - - getFecha(): Date{ - return this.fecha; - } - - setDesc(desc: string): void{ - this.descripcion = desc; - } - - getDesc(): string{ - return this.descripcion; - } - - setDia(fecha: Date): void{ - this.dia = fecha.getDate()+"/"+fecha.getMonth(); - } - - getDia(): string{ - return this.dia; - } - - setHora(time: Time): void{ - this.hora = time; - } - - getHora(): Time{ - return this.hora; - } - - setPrecio1(precio: number): void{ - this.precio1 = precio; - } - - getPrecio1(): number{ - return this.precio1; - } - - setPrecio2(precio: number): void{ - this.precio2 = precio; - } - - getPrecio2(): number{ - return this.precio2; - } -} diff --git a/src/app/interfaces/eventoi.ts b/src/app/interfaces/eventoi.ts index 8926fb3..b613b3c 100644 --- a/src/app/interfaces/eventoi.ts +++ b/src/app/interfaces/eventoi.ts @@ -1,7 +1,7 @@ import { Time } from "@angular/common"; export interface Eventoi { - + id: number, discotecaID: number, nombre: string, localizacion: string, diff --git a/src/app/perfil-discoteca/perfil-discoteca.page.ts b/src/app/perfil-discoteca/perfil-discoteca.page.ts index f87e339..2438f98 100644 --- a/src/app/perfil-discoteca/perfil-discoteca.page.ts +++ b/src/app/perfil-discoteca/perfil-discoteca.page.ts @@ -3,7 +3,7 @@ import { Tab1Service } from '../tab1/tab1.service'; import { IonSlides, ModalController} from '@ionic/angular'; import { AlertController } from '@ionic/angular'; import { ViewChild } from '@angular/core'; -import { Evento } from '../evento'; +import { Eventoi } from '../interfaces/eventoi'; import { Router } from '@angular/router'; import { THIS_EXPR } from '@angular/compiler/src/output/output_ast'; import { GaleriamodalPage } from '../galeriamodal/galeriamodal.page'; @@ -28,7 +28,7 @@ export class PerfilDiscotecaPage implements OnInit { editEnabled: string; galeriaFotos: string[]; currentIndex: number; - eventos: Evento[]; + eventos: Eventoi[]; alertCtrl: AlertController; sliderOpts = { slidesPerView: 1.5, @@ -70,14 +70,15 @@ export class PerfilDiscotecaPage implements OnInit { this.localizacion = this.tab1Service.getLocalizacion(); } - getEventos(): void{ - this.eventos = this.tab1Service.getEventos(); - } getDescripcion(): void{ this.descripcion = this.tab1Service.getDescripcion(); } + getEventos(): void{ + this.eventos = this.tab1Service.eventos; + } + cargarImagen(){ this.fotoSrc = this.someURL; } @@ -174,12 +175,12 @@ export class PerfilDiscotecaPage implements OnInit { this.router.navigate(['/tabs/tab1/prompt-evento']); } - mostrarEvento(evento: Evento){ + mostrarEvento(evento: Eventoi){ this.tab1Service.eventoIndex = this.eventos.indexOf(evento); this.router.navigate(['/tabs/tab1/view-evento']); } - editarEvento(evento: Evento){ + editarEvento(evento: Eventoi){ this.tab1Service.eventoIndex = this.eventos.indexOf(evento); this.tab1Service.editarEvento = true; this.router.navigate(['/tabs/tab1/prompt-evento']); diff --git a/src/app/prompt-evento/prompt-evento.page.ts b/src/app/prompt-evento/prompt-evento.page.ts index 0e44ac1..31b21a3 100644 --- a/src/app/prompt-evento/prompt-evento.page.ts +++ b/src/app/prompt-evento/prompt-evento.page.ts @@ -1,7 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { FormControl, FormGroup, Validators } from '@angular/forms'; import { Tab1Service } from '../tab1/tab1.service'; -import { Evento } from '../evento'; import { Router } from '@angular/router'; import { Eventoi } from '../interfaces/eventoi'; import { DatePipe } from '@angular/common' @@ -37,37 +36,47 @@ export class PromptEventoPage implements OnInit{ onSubmit(){ this.submitted = true; if (this.eventoForm.valid){ - let evento = new Evento(); + let evento: Eventoi = { + id: null, + discotecaID: this.tab1Service.discotecaI.discotecaID, + nombre: '', + localizacion: this.tab1Service.discotecaI.localizacion, + fecha: null, + hora: null, + descripcion: '', + precio1: null, + precio2: null + + + }; this.asignarEvento(evento); } } - asignarEvento(evento: Evento){ - evento.setNombre(this.eventoForm.get('nombre').value); - evento.setDesc(this.eventoForm.get('descripcion').value); + asignarEvento(evento: Eventoi){ + evento.nombre = this.eventoForm.get('nombre').value; + evento.descripcion = this.eventoForm.get('descripcion').value; var fecha = this.eventoForm.get('fecha').value; fecha = fecha.split("T")[0]; - evento.setFecha(fecha); - var hora = this.eventoForm.get('hora').value; + evento.fecha = fecha; + let hora = this.eventoForm.get('hora').value; hora = hora.split("T")[1]; hora = hora.split(":")[0]+(":")+hora.split(":")[1]; - evento.setHora(hora); - evento.setPrecio1(this.eventoForm.get('precio1').value); - evento.setPrecio2(this.eventoForm.get('precio2').value); + evento.hora = hora; + evento.precio1 = this.eventoForm.get('precio1').value; + evento.precio2 = this.eventoForm.get('precio2').value; //evento.setDia(evento.getFecha()); el datetime de Ion devuelve un String, no se puede if (!this.tab1Service.eventos){ this.tab1Service.initEventos();} if(!this.tab1Service.eventoForms){ this.tab1Service.initEventoForms();} - let eventoInterface = this.interfaceEvento(evento); if(this.tab1Service.editarEvento==true){ - this.tab1Service.updateEvento(eventoInterface); + this.tab1Service.updateEvento(evento); //this.tab1Service.eventos[this.tab1Service.eventoIndex] = evento; //this.tab1Service.eventoForms[this.tab1Service.eventoIndex] = this.eventoForm; } else{ - this.tab1Service.eventos.push(evento); - this.tab1Service.postEvento(eventoInterface); + this.tab1Service.postEvento(evento); //this.tab1Service.eventos.push(evento); //this.tab1Service.eventoForms.push(this.eventoForm); } @@ -98,22 +107,5 @@ export class PromptEventoPage implements OnInit{ return this.eventoForm.get('descripcion'); } - interfaceEvento(evento: Evento): Eventoi{ - let eventoInterface: Eventoi; - eventoInterface = { - discotecaID: this.tab1Service.discotecaI.discotecaID, - nombre: evento.nombre, - localizacion: this.tab1Service.discotecaI.localizacion, - fecha: evento.fecha, - hora: evento.hora, - descripcion: evento.descripcion, - precio1: evento.precio1, - precio2: evento.precio2, - } - - return eventoInterface; - } - - } diff --git a/src/app/services/api.service.ts b/src/app/services/api.service.ts index 9c3bd9a..b922549 100644 --- a/src/app/services/api.service.ts +++ b/src/app/services/api.service.ts @@ -39,6 +39,12 @@ export class ApiService { } + getEventos(discotecaID: number): Observable<Eventoi[]>{ + return this.http.post<Eventoi[]>(this.baseUrl+"/eventosDiscoteca", {"id": discotecaID}); + + + } + diff --git a/src/app/tab1/tab1.service.ts b/src/app/tab1/tab1.service.ts index aa1db15..5b65175 100644 --- a/src/app/tab1/tab1.service.ts +++ b/src/app/tab1/tab1.service.ts @@ -2,7 +2,7 @@ import { Injectable, OnInit } from '@angular/core'; import { stringify } from 'querystring'; import { Tab1Page } from './tab1.page' import { Discoteca } from '../discoteca' -import { Evento } from '../evento'; +import { Observable, of } from 'rxjs'; import { FormControl, FormGroup } from '@angular/forms'; import { NumericValueAccessor } from '@ionic/angular'; import { DiscotecaI } from '../interfaces/discoteca-i'; @@ -19,7 +19,7 @@ export class Tab1Service implements OnInit{ discoteca: Discoteca; discotecaI: DiscotecaI; galeria: string[]; - eventos: Evento[]; + eventos: Eventoi[]; eventoForms: FormGroup[]; eventoIndex: number; editarEvento: boolean; @@ -29,7 +29,7 @@ export class Tab1Service implements OnInit{ } ngOnInit(){ - this.initValues(); + } initValues(): void{ @@ -38,37 +38,40 @@ export class Tab1Service implements OnInit{ this.discoteca.setNombre(this.discotecaI.nombre); this.discoteca.setTelefono(this.discotecaI.telefono); this.discoteca.setLocalizacion(this.discotecaI.localizacion); - this.galeria = []; this.initEventos(); + this.galeria = []; this.editarEvento = false; } getNombre(): string{ - this.initValues(); return this.discoteca.getNombre(); } getTelefono(): number{ - this.initValues(); return this.discoteca.getTelefono(); } getLocalizacion(): string{ - this.initValues(); return this.discoteca.getLocalizacion(); } - getEventos(): Evento[]{ + getEventos(): Eventoi[]{ return this.eventos; } getDescripcion(): string{ - this.initValues(); return this.discoteca.getDescripcion(); } initEventos(): void{ this.eventos = []; + this.apiService.getEventos(this.discoteca.getId()) + .subscribe(eventos => { + this.eventos = eventos; + this.router.navigate(['/tabs/tab1/perfil-discoteca']); + }) + + } initEventoForms(): void{ @@ -79,14 +82,13 @@ export class Tab1Service implements OnInit{ return this.eventos[eventoIndex]; } - getDiscoteca(discotecaId: number){ +getDiscoteca(discotecaId: number){ if (discotecaId != 0){ this.apiService.getUserDiscoteca(discotecaId) .subscribe(discoteca => { this.discotecaI = discoteca[0]; console.log(this.discotecaI); this.initValues(); - this.router.navigate(['/tabs/tab1/perfil-discoteca']); }) } } @@ -94,7 +96,7 @@ export class Tab1Service implements OnInit{ postEvento(evento: Eventoi){ this.apiService.postEvento(evento) .subscribe(evento => { - this.router.navigate(['/tabs']); + this.initEventos(); }) }