update getting file recipe

This commit is contained in:
Kenta420 2023-10-24 18:01:52 +07:00
parent ea506b8128
commit 3bfbbd778a
10 changed files with 243 additions and 152 deletions

View file

@ -10,13 +10,15 @@ export class MaterialService {
getMaterialCodes(
matIds?: number[],
version?: string
country?: string,
filename?: string
): Observable<MaterialCode[]> {
return this._httpClient.get<MaterialCode[]>(
`${environment.api}/materials/code`,
{
params: {
version: version || '',
country: country || '',
filename: filename || '',
mat_ids: matIds?.join(',') || '',
},
withCredentials: true,
@ -26,13 +28,15 @@ export class MaterialService {
getMaterialSettingById(
id: number,
version?: string
country?: string,
filename?: string
): Observable<MaterialSetting> {
return this._httpClient.get<MaterialSetting>(
`${environment.api}/materials/setting/${id}`,
{
params: {
version: version || '',
country: country || '',
filename: filename || '',
},
withCredentials: true,
}

View file

@ -6,7 +6,8 @@ import { environment } from 'src/environments/environment';
import { RecipeMetaData } from 'src/app/shared/types/recipe';
interface RecipeParams {
version: string;
filename: string;
country: string;
offset: number;
take: number;
search: string;
@ -28,46 +29,49 @@ export class RecipeService {
take: 10,
offset: 0,
search: '',
version: this.getCurrentVersion(),
country: this.getCurrentCountry(),
filename: this.getCurrentFile(),
}
): Observable<{
fileName: string;
recipes: Recipe;
hasMore: boolean;
}> {
return this._httpClient
.get<{
fileName: string;
recipes: Recipe;
hasMore: boolean;
}>(environment.api + '/recipes', {
params: {
offset: params.offset,
take: params.take,
search: params.search,
version: params.version,
},
withCredentials: true,
responseType: 'json',
})
.pipe(
tap((data) => {
if (data.fileName !== this.getCurrentVersion()) {
localStorage.setItem('currentRecipeVersion', data.fileName);
}
})
);
return this._httpClient.get<{
fileName: string;
recipes: Recipe;
hasMore: boolean;
}>(environment.api + '/recipes', {
params: {
offset: params.offset,
take: params.take,
search: params.search,
country: params.country,
filename: params.filename,
},
withCredentials: true,
responseType: 'json',
});
}
getCurrentVersion(): string {
const currentRecipeVersion = localStorage.getItem('currentRecipeVersion');
if (currentRecipeVersion) {
return currentRecipeVersion;
getCurrentFile(): string {
const currentRecipeFile = localStorage.getItem('currentRecipeFile');
if (currentRecipeFile) {
return currentRecipeFile;
}
return 'coffeethai02_580.json';
}
getCurrentCountry(): string {
const currentRecipeCountry = localStorage.getItem('currentRecipeCountry');
if (currentRecipeCountry) {
return currentRecipeCountry;
}
return 'Thailand';
}
getRecipesById(id: string): Observable<{
recipe: Recipe01;
recipeMetaData: RecipeMetaData;
@ -103,23 +107,28 @@ export class RecipeService {
return this.countries;
}
getRecipeFileNames(country: string): string[] {
return this.recipeFiles[country];
getRecipeFileNames(country: string): string[] | null {
return this.recipeFiles[country] ?? null;
}
editChanges(version: string, change: any){
console.log("target version = ", version);
console.log("change in edit: ",change.value)
return this._httpClient.post<{
status: string
}>(
environment.api + ('/recipes/edit/'+version),
change.value,
{ withCredentials: true, responseType: 'json', }
).subscribe({
next(value) {
console.log(value, change.value)
},
});
editChanges(country: string, filename: string, change: any) {
console.log('target version = ', filename);
console.log('change in edit: ', change.value);
return this._httpClient
.post<{
status: string;
}>(
environment.api + ('/recipes/edit/' + country + '/' + filename),
change.value,
{
withCredentials: true,
responseType: 'json',
}
)
.subscribe({
next(value) {
console.log(value, change.value);
},
});
}
}