import { Injectable, Inject } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; import { League } from 'src/modules/game/model/league.model'; import { API_BASE_URL } from 'src/modules/common/type/injection-token.type'; import { Page } from 'src/modules/common/data/model/page'; import { map } from 'rxjs/operators'; @Injectable() export class LeagueService { constructor( @Inject(API_BASE_URL) private apiBaseUrl: string, private httpClient: HttpClient ) {} public getAllLeague(): Observable> { return this.httpClient.get>(`${this.apiBaseUrl}/league`, {}); } public regist(league: League): Observable { const engName = league.engName; const korName = league.korName; const sevenName = league.sevenName; const engCountry = league.engCountry; const korCountry = league.korCountry; const sportsEntities = league.sportsEntities; return this.httpClient .post(`${this.apiBaseUrl}/league`, { engName, korName, sevenName, engCountry, korCountry, sportsEntities }) .pipe( map(res => { console.log('league regist response: ' + res); return res; }) ); } public updateLeague(league: League): Observable { const id = league.id; const engName = league.engName; const korName = league.korName; const sevenName = league.sevenName; const engCountry = league.engCountry; const korCountry = league.korCountry; const sportsEntities = league.sportsEntities; return this.httpClient .put(`${this.apiBaseUrl}/league/${id}`, { id, engName, korName, sevenName, engCountry, korCountry, sportsEntities }) .pipe( map(res => { console.log('league update response: ' + res); return res; }) ); } }