diff --git a/firestore.rules b/firestore.rules index bbd672e..e51e019 100644 --- a/firestore.rules +++ b/firestore.rules @@ -16,5 +16,10 @@ service cloud.firestore { allow read: if true; allow write: if true; } + match /shows/{show}/songs/{song} { + allow read: if true; + allow write: if true; + } } } + diff --git a/src/app/modules/shows/services/show-song-data.service.spec.ts b/src/app/modules/shows/services/show-song-data.service.spec.ts new file mode 100644 index 0000000..75940ab --- /dev/null +++ b/src/app/modules/shows/services/show-song-data.service.spec.ts @@ -0,0 +1,16 @@ +import {TestBed} from '@angular/core/testing'; + +import {ShowSongDataService} from './show-song-data.service'; + +describe('ShowSongDataService', () => { + let service: ShowSongDataService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ShowSongDataService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/modules/shows/services/show-song-data.service.ts b/src/app/modules/shows/services/show-song-data.service.ts new file mode 100644 index 0000000..cd6c500 --- /dev/null +++ b/src/app/modules/shows/services/show-song-data.service.ts @@ -0,0 +1,20 @@ +import {Injectable} from '@angular/core'; +import {DbService} from '../../../services/db.service'; +import {Observable} from 'rxjs'; +import {ShowSong} from './showSong'; + +@Injectable({ + providedIn: 'root' +}) +export class ShowSongDataService { + private collection = 'shows'; + private subCollection = 'songs'; + + constructor(private dbService: DbService) { + } + + public list$ = (showId: string): Observable => this.dbService.col$(`${this.collection}/${showId}/${this.subCollection}`); + public read$ = (showId: string, songId: string): Observable => this.dbService.doc$(`${this.collection}/${showId}/${this.subCollection}/${songId}`); + public update = async (showId: string, songId: string, data: Partial): Promise => await this.dbService.doc(`${this.collection}/${showId}/${this.subCollection}/${songId}`).update(data); + public add = async (showId: string, data: Partial): Promise => (await this.dbService.col(`${this.collection}/${showId}/${this.subCollection}`).add(data)).id +} diff --git a/src/app/modules/shows/services/show-song.service.spec.ts b/src/app/modules/shows/services/show-song.service.spec.ts new file mode 100644 index 0000000..c42050c --- /dev/null +++ b/src/app/modules/shows/services/show-song.service.spec.ts @@ -0,0 +1,16 @@ +import {TestBed} from '@angular/core/testing'; + +import {ShowSongService} from './show-song.service'; + +describe('ShowSongService', () => { + let service: ShowSongService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(ShowSongService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/modules/shows/services/show-song.service.ts b/src/app/modules/shows/services/show-song.service.ts new file mode 100644 index 0000000..2f50a5c --- /dev/null +++ b/src/app/modules/shows/services/show-song.service.ts @@ -0,0 +1,16 @@ +import {Injectable} from '@angular/core'; +import {ShowSongDataService} from './show-song-data.service'; + +@Injectable({ + providedIn: 'root' +}) +export class ShowSongService { + + constructor(private showSongDataService: ShowSongDataService) { + } + + public async new$(showId: string, songId: string): Promise { + const data = {songId}; + return await this.showSongDataService.add(showId, data); + } +} diff --git a/src/app/modules/shows/services/show.ts b/src/app/modules/shows/services/show.ts index 125e061..95c50fe 100644 --- a/src/app/modules/shows/services/show.ts +++ b/src/app/modules/shows/services/show.ts @@ -10,3 +10,4 @@ export interface Show { public: boolean; reported: boolean; } + diff --git a/src/app/modules/shows/services/showSong.ts b/src/app/modules/shows/services/showSong.ts new file mode 100644 index 0000000..5706238 --- /dev/null +++ b/src/app/modules/shows/services/showSong.ts @@ -0,0 +1,4 @@ +export interface ShowSong { + id: string; + songId: string; +} diff --git a/src/app/modules/shows/show/show.component.html b/src/app/modules/shows/show/show.component.html index 82c9a34..7c67808 100644 --- a/src/app/modules/shows/show/show.component.html +++ b/src/app/modules/shows/show/show.component.html @@ -2,6 +2,14 @@ - +
+ + Lied hinzufügen... + + {{song.title}} + + + +
diff --git a/src/app/modules/shows/show/show.component.less b/src/app/modules/shows/show/show.component.less index e69de29..da0d815 100644 --- a/src/app/modules/shows/show/show.component.less +++ b/src/app/modules/shows/show/show.component.less @@ -0,0 +1,7 @@ +.add-row { + display: flex; + + .mat-form-field { + width: 100%; + } +} diff --git a/src/app/modules/shows/show/show.component.ts b/src/app/modules/shows/show/show.component.ts index 597bf29..e4dad23 100644 --- a/src/app/modules/shows/show/show.component.ts +++ b/src/app/modules/shows/show/show.component.ts @@ -1,9 +1,13 @@ import {Component, OnInit} from '@angular/core'; -import {map, switchMap} from 'rxjs/operators'; +import {map, switchMap, tap} from 'rxjs/operators'; import {ActivatedRoute} from '@angular/router'; import {ShowService} from '../services/show.service'; import {Observable} from 'rxjs'; import {Show} from '../services/show'; +import {SongService} from '../../songs/services/song.service'; +import {Song} from '../../songs/services/song'; +import {MatSelectChange} from '@angular/material/select'; +import {ShowSongService} from '../services/show-song.service'; @Component({ selector: 'app-show', @@ -12,18 +16,40 @@ import {Show} from '../services/show'; }) export class ShowComponent implements OnInit { public show$: Observable; + public songs$: Observable; + private showId: string; constructor( private activatedRoute: ActivatedRoute, - private showService: ShowService + private showService: ShowService, + private songService: SongService, + private showSongService: ShowSongService, ) { } ngOnInit(): void { this.show$ = this.activatedRoute.params.pipe( map(param => param.showId), + tap(_ => this.showId = _), switchMap(showId => this.showService.read$(showId)) ); + this.songs$ = this.songService.list$().pipe(map(_ => _ + .filter(_ => !!_.title) + .filter(_ => _.title !== 'nicht gefunden') + .filter(_ => _.title !== 'nicht vorhanden') + .sort((a, b) => { + if (a.title < b.title) { + return -1; + } + if (a.title > b.title) { + return 1; + } + return 0; + }))); } + public async onAddSongSelectionChanged(event: MatSelectChange) { + await this.showSongService.new$(this.showId, event.value); + event.source.value = null; + } }