BackEnd #3

Merged
onsaliyo merged 11 commits from BackEnd into master 2021-03-31 13:01:27 +02:00
5 changed files with 41 additions and 10 deletions
Showing only changes of commit 660f19932c - Show all commits

View File

@ -5,6 +5,7 @@ import { catchError, retry, map, tap } from 'rxjs/operators';
import { User } from './user'; import { User } from './user';
import { Discoteca } from './discoteca'; import { Discoteca } from './discoteca';
import { UserLogin } from './user-login'; import { UserLogin } from './user-login';
import { DiscotecaI } from './discoteca-i';
@Injectable({ @Injectable({
@ -12,7 +13,7 @@ import { UserLogin } from './user-login';
}) })
export class ApiService { export class ApiService {
baseUrl = "http://localhost:3307/api/consultas";
constructor(private http: HttpClient) { constructor(private http: HttpClient) {
@ -21,7 +22,13 @@ export class ApiService {
validateUser(user: UserLogin): Observable<User>{ 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});
} }

View File

@ -1,2 +1,6 @@
export interface DiscotecaI { export interface DiscotecaI {
discotecaId: number,
nombre: string,
telefono: number,
localizacion: string
} }

View File

@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { VirtualTimeScheduler } from 'rxjs'; import { VirtualTimeScheduler } from 'rxjs';
import { ApiService } from './api.service'; import { ApiService } from './api.service';
import { Tab1Service } from './tab1/tab1.service';
import { User } from './user'; import { User } from './user';
import { UserLogin } from './user-login'; import { UserLogin } from './user-login';
@ -13,10 +14,10 @@ export class LoginService {
user: User; user: User;
constructor(private apiService: ApiService, private router: Router) { constructor(private apiService: ApiService, private router: Router, private tab1service: Tab1Service) {
this.user = { this.user = {
id: 0, id: 0,
discotecaId: 0, discotecaID: 0,
userType: 0, userType: 0,
username: '', username: '',
}; };
@ -31,8 +32,11 @@ export class LoginService {
this.apiService.validateUser(userlogin) this.apiService.validateUser(userlogin)
.subscribe(user => { .subscribe(user => {
this.user = user; this.user = user[0];
console.log(this.user); console.log(this.user);
console.log(this.user.discotecaID);
this.tab1service.getDiscoteca(this.user.discotecaID);
}) })
} }

View File

@ -5,6 +5,9 @@ import { Discoteca } from '../discoteca'
import { Evento } from '../evento'; import { Evento } from '../evento';
import { FormControl, FormGroup } from '@angular/forms'; import { FormControl, FormGroup } from '@angular/forms';
import { NumericValueAccessor } from '@ionic/angular'; import { NumericValueAccessor } from '@ionic/angular';
import { DiscotecaI } from '../discoteca-i';
import { ApiService } from '../api.service';
import { Router } from '@angular/router';
@Injectable({ @Injectable({
@ -13,13 +16,14 @@ import { NumericValueAccessor } from '@ionic/angular';
export class Tab1Service implements OnInit{ export class Tab1Service implements OnInit{
discoteca: Discoteca; discoteca: Discoteca;
discotecaI: DiscotecaI;
galeria: string[]; galeria: string[];
eventos: Evento[]; eventos: Evento[];
eventoForms: FormGroup[]; eventoForms: FormGroup[];
eventoIndex: number; eventoIndex: number;
editarEvento: boolean; editarEvento: boolean;
constructor() { constructor(private apiService: ApiService, private router: Router) {
} }
@ -29,9 +33,9 @@ export class Tab1Service implements OnInit{
initValues(): void{ initValues(): void{
this.discoteca = new Discoteca(); this.discoteca = new Discoteca();
this.discoteca.setNombre('Barraca'); this.discoteca.setNombre(this.discotecaI.nombre);
this.discoteca.setTelefono(666666666); this.discoteca.setTelefono(this.discotecaI.telefono);
this.discoteca.setLocalizacion('Calle del Barquillo'); this.discoteca.setLocalizacion(this.discotecaI.localizacion);
this.galeria = []; this.galeria = [];
this.initEventos(); this.initEventos();
this.editarEvento = false; this.editarEvento = false;
@ -73,4 +77,16 @@ export class Tab1Service implements OnInit{
return this.eventos[eventoIndex]; 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']);
})
}
}
} }

View File

@ -1,6 +1,6 @@
export interface User { export interface User {
id: number; id: number;
discotecaId: number; discotecaID: number;
userType: number; userType: number;
username: string; username: string;
} }