creado feed component. llamada a la API para descargar todos los eventos
This commit is contained in:
		
							parent
							
								
									6c8af25e4b
								
							
						
					
					
						commit
						139e3fcb8b
					
				
							
								
								
									
										3
									
								
								src/app/feed/feed.component.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								src/app/feed/feed.component.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | |||||||
|  | <p> | ||||||
|  |   feed works! | ||||||
|  | </p> | ||||||
							
								
								
									
										0
									
								
								src/app/feed/feed.component.scss
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/app/feed/feed.component.scss
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										24
									
								
								src/app/feed/feed.component.spec.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/app/feed/feed.component.spec.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | |||||||
|  | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||||||
|  | import { IonicModule } from '@ionic/angular'; | ||||||
|  | 
 | ||||||
|  | import { FeedComponent } from './feed.component'; | ||||||
|  | 
 | ||||||
|  | describe('FeedComponent', () => { | ||||||
|  |   let component: FeedComponent; | ||||||
|  |   let fixture: ComponentFixture<FeedComponent>; | ||||||
|  | 
 | ||||||
|  |   beforeEach(async(() => { | ||||||
|  |     TestBed.configureTestingModule({ | ||||||
|  |       declarations: [ FeedComponent ], | ||||||
|  |       imports: [IonicModule.forRoot()] | ||||||
|  |     }).compileComponents(); | ||||||
|  | 
 | ||||||
|  |     fixture = TestBed.createComponent(FeedComponent); | ||||||
|  |     component = fixture.componentInstance; | ||||||
|  |     fixture.detectChanges(); | ||||||
|  |   })); | ||||||
|  | 
 | ||||||
|  |   it('should create', () => { | ||||||
|  |     expect(component).toBeTruthy(); | ||||||
|  |   }); | ||||||
|  | }); | ||||||
							
								
								
									
										14
									
								
								src/app/feed/feed.component.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/app/feed/feed.component.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | |||||||
|  | import { Component, OnInit } from '@angular/core'; | ||||||
|  | 
 | ||||||
|  | @Component({ | ||||||
|  |   selector: 'app-feed', | ||||||
|  |   templateUrl: './feed.component.html', | ||||||
|  |   styleUrls: ['./feed.component.scss'], | ||||||
|  | }) | ||||||
|  | export class FeedComponent implements OnInit { | ||||||
|  | 
 | ||||||
|  |   constructor() { } | ||||||
|  | 
 | ||||||
|  |   ngOnInit() {} | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -79,9 +79,6 @@ export class PerfilDiscotecaPage implements OnInit { | |||||||
|     this.eventos = this.tab1Service.eventos; |     this.eventos = this.tab1Service.eventos; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getDescripcion(): void{ |  | ||||||
|     this.descripcion = this.tab1Service.getDescripcion(); |  | ||||||
|   } |  | ||||||
| 
 | 
 | ||||||
|   cargarImagen(){ |   cargarImagen(){ | ||||||
|       this.fotoSrc = this.someURL; |       this.fotoSrc = this.someURL; | ||||||
| @ -192,6 +189,7 @@ export class PerfilDiscotecaPage implements OnInit { | |||||||
|   editarEvento(evento: Eventoi){ |   editarEvento(evento: Eventoi){ | ||||||
|     this.tab1Service.eventoIndex = this.eventos.indexOf(evento); |     this.tab1Service.eventoIndex = this.eventos.indexOf(evento); | ||||||
|     this.tab1Service.editarEvento = true; |     this.tab1Service.editarEvento = true; | ||||||
|  |     this.tab1Service.initEventoForms(); | ||||||
|     this.router.navigate(['/tabs/tab1/prompt-evento']); |     this.router.navigate(['/tabs/tab1/prompt-evento']); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -39,7 +39,13 @@ export class ApiService { | |||||||
|      |      | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getEventos(discotecaID: number): Observable<Eventoi[]>{ |   getEventos(): Observable<Eventoi[]>{ | ||||||
|  | 
 | ||||||
|  |     return this.http.get<Eventoi[]>(this.baseUrl+"/evento"); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   getEventosDiscoteca(discotecaID: number): Observable<Eventoi[]>{ | ||||||
|  | 
 | ||||||
|       return this.http.post<Eventoi[]>(this.baseUrl+"/eventosDiscoteca", {"id": discotecaID}); |       return this.http.post<Eventoi[]>(this.baseUrl+"/eventosDiscoteca", {"id": discotecaID}); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										16
									
								
								src/app/services/feed.service.spec.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/app/services/feed.service.spec.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | |||||||
|  | import { TestBed } from '@angular/core/testing'; | ||||||
|  | 
 | ||||||
|  | import { FeedService } from './feed.service'; | ||||||
|  | 
 | ||||||
|  | describe('FeedService', () => { | ||||||
|  |   let service: FeedService; | ||||||
|  | 
 | ||||||
|  |   beforeEach(() => { | ||||||
|  |     TestBed.configureTestingModule({}); | ||||||
|  |     service = TestBed.inject(FeedService); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   it('should be created', () => { | ||||||
|  |     expect(service).toBeTruthy(); | ||||||
|  |   }); | ||||||
|  | }); | ||||||
							
								
								
									
										22
									
								
								src/app/services/feed.service.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								src/app/services/feed.service.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | |||||||
|  | import { Injectable } from '@angular/core'; | ||||||
|  | import { Router } from '@angular/router'; | ||||||
|  | import { Eventoi } from '../interfaces/eventoi'; | ||||||
|  | import { ApiService } from './api.service'; | ||||||
|  | 
 | ||||||
|  | @Injectable({ | ||||||
|  |   providedIn: 'root' | ||||||
|  | }) | ||||||
|  | export class FeedService { | ||||||
|  | 
 | ||||||
|  |   eventos: Eventoi[]; | ||||||
|  | 
 | ||||||
|  |   constructor(private apiService: ApiService, private router: Router) { } | ||||||
|  | 
 | ||||||
|  |   initFeed(): void{ | ||||||
|  |     this.apiService.getEventos() | ||||||
|  |     .subscribe(eventos => { | ||||||
|  |       this.eventos = eventos; | ||||||
|  |        | ||||||
|  |     }) | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -5,6 +5,7 @@ import { ApiService } from './api.service'; | |||||||
| import { Tab1Service } from '../tab1/tab1.service'; | import { Tab1Service } from '../tab1/tab1.service'; | ||||||
| import { User } from '../interfaces/user'; | import { User } from '../interfaces/user'; | ||||||
| import { UserLogin } from '../interfaces/user-login'; | import { UserLogin } from '../interfaces/user-login'; | ||||||
|  | import { FeedService } from './feed.service'; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @Injectable({ | @Injectable({ | ||||||
| @ -14,7 +15,7 @@ export class LoginService { | |||||||
| 
 | 
 | ||||||
|   user: User; |   user: User; | ||||||
| 
 | 
 | ||||||
|   constructor(private apiService: ApiService, private router: Router, private tab1service: Tab1Service) { |   constructor(private apiService: ApiService, private router: Router, private tab1service: Tab1Service, private feedService: FeedService) { | ||||||
|     this.user = { |     this.user = { | ||||||
|       id: 0, |       id: 0, | ||||||
|       discotecaID: 0, |       discotecaID: 0, | ||||||
| @ -32,10 +33,11 @@ export class LoginService { | |||||||
| 
 | 
 | ||||||
|     this.apiService.validateUser(userlogin) |     this.apiService.validateUser(userlogin) | ||||||
|       .subscribe(user => { |       .subscribe(user => { | ||||||
|         this.user = user[0]; |         this.user = user[0];   | ||||||
|         console.log(this.user); |         if (this.user.userType==0) | ||||||
|         console.log(this.user.discotecaID); |           this.tab1service.getDiscoteca(this.user.discotecaID); | ||||||
|         this.tab1service.getDiscoteca(this.user.discotecaID); |         else if (this.user.userType==1)  | ||||||
|  |           this.feedService.initFeed(); | ||||||
| 
 | 
 | ||||||
|       }) |       }) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ import { stringify } from 'querystring'; | |||||||
| import { Tab1Page } from './tab1.page' | import { Tab1Page } from './tab1.page' | ||||||
| import { Discoteca } from '../discoteca' | import { Discoteca } from '../discoteca' | ||||||
| import { Observable, of } from 'rxjs'; | import { Observable, of } from 'rxjs'; | ||||||
| import { FormControl, FormGroup } from '@angular/forms'; | import { FormControl, FormGroup, Validators } from '@angular/forms'; | ||||||
| import { NumericValueAccessor } from '@ionic/angular'; | import { NumericValueAccessor } from '@ionic/angular'; | ||||||
| import { DiscotecaI } from '../interfaces/discoteca-i'; | import { DiscotecaI } from '../interfaces/discoteca-i'; | ||||||
| import { ApiService } from '../services/api.service'; | import { ApiService } from '../services/api.service'; | ||||||
| @ -65,7 +65,7 @@ export class Tab1Service implements OnInit{ | |||||||
| 
 | 
 | ||||||
|   initEventos(): void{ |   initEventos(): void{ | ||||||
|     this.eventos = []; |     this.eventos = []; | ||||||
|     this.apiService.getEventos(this.discoteca.getId()) |     this.apiService.getEventosDiscoteca(this.discoteca.getId()) | ||||||
|     .subscribe(eventos => { |     .subscribe(eventos => { | ||||||
|       this.eventos = eventos; |       this.eventos = eventos; | ||||||
|       this.router.navigate(['/tabs/tab1/perfil-discoteca']); |       this.router.navigate(['/tabs/tab1/perfil-discoteca']); | ||||||
| @ -76,6 +76,25 @@ export class Tab1Service implements OnInit{ | |||||||
| 
 | 
 | ||||||
|   initEventoForms(): void{ |   initEventoForms(): void{ | ||||||
|     this.eventoForms = []; |     this.eventoForms = []; | ||||||
|  |     if (this.eventos){ | ||||||
|  |       this.eventos.forEach(evento => { | ||||||
|  |         let thisForm = new FormGroup({ | ||||||
|  |           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), | ||||||
|  |       }); | ||||||
|  |       thisForm.controls['nombre'].setValue(evento.nombre); | ||||||
|  |       thisForm.controls['fecha'].setValue(evento.fecha); | ||||||
|  |       thisForm.controls['hora'].setValue(evento.hora); | ||||||
|  |       thisForm.controls['precio1'].setValue(evento.precio1); | ||||||
|  |       thisForm.controls['precio2'].setValue(evento.precio2); | ||||||
|  |       thisForm.controls['descripcion'].setValue(evento.descripcion); | ||||||
|  |       this.eventoForms.push(thisForm); | ||||||
|  |       }) | ||||||
|  |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   getEventobyIndex(eventoIndex: number){ |   getEventobyIndex(eventoIndex: number){ | ||||||
| @ -91,6 +110,7 @@ getDiscoteca(discotecaId: number){ | |||||||
|       this.initValues(); |       this.initValues(); | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
|  |   | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   postEvento(evento: Eventoi){ |   postEvento(evento: Eventoi){ | ||||||
| @ -105,4 +125,6 @@ getDiscoteca(discotecaId: number){ | |||||||
| 
 | 
 | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user