add file select for multiple country

This commit is contained in:
Kenta420 2023-10-20 17:05:24 +07:00
parent e5eee656d5
commit 652ecbbf1f
9 changed files with 294 additions and 47 deletions

View file

@ -12,8 +12,15 @@ interface RecipeParams {
search: string;
}
interface RecipeFiles {
[key: string]: string[];
}
@Injectable({ providedIn: 'root' })
export class RecipeService {
private countries: string[] = [];
private recipeFiles: RecipeFiles = {};
constructor(private _httpClient: HttpClient) {}
getRecipes(
@ -74,10 +81,29 @@ export class RecipeService {
});
}
getRecipeVersions(): Observable<string[]> {
return this._httpClient.get<string[]>(
environment.api + '/recipes/versions',
{ withCredentials: true, responseType: 'json' }
);
getRecipeCountries(): Observable<string[]> {
return this._httpClient
.get<string[]>(environment.api + '/recipes/versions', {
withCredentials: true,
responseType: 'json',
})
.pipe(tap((countries) => (this.countries = countries)));
}
getRecipeFiles(country: string): Observable<string[]> {
return this._httpClient
.get<string[]>(environment.api + '/recipes/versions/' + country, {
withCredentials: true,
responseType: 'json',
})
.pipe(tap((files) => (this.recipeFiles[country] = files)));
}
getRecipeFileCountries(): string[] {
return this.countries;
}
getRecipeFileNames(country: string): string[] {
return this.recipeFiles[country];
}
}