update recipe detail and recipe detail list

This commit is contained in:
Kenta420 2023-11-24 17:47:44 +07:00
parent 8b45ed53ee
commit d52cad09fd
16 changed files with 947 additions and 458 deletions

View file

@ -1,3 +1,50 @@
export type RecipeOverview = {
id: string;
productCode: string;
name: string;
otherName: string;
description: string;
lastUpdated: Date;
};
export type RecipesDashboard = {
configNumber: number;
LastUpdated: Date;
filename: string;
};
export type RecipeOverviewList = {
result: RecipeOverview[];
hasMore: boolean;
totalCount: number;
};
export type RecipeDetail = {
name: string;
otherName: string;
description: string;
otherDescription: string;
lastUpdated: Date;
picture: string;
};
export type RecipeDetailMat = {
materialID: number;
name: string;
mixOrder: number;
feedParameter: number;
feedPattern: number;
isUse: boolean;
materialPathId: number;
powderGram: number;
powderTime: number;
stirTime: number;
syrupGram: number;
syrupTime: number;
waterCold: number;
waterYield: number;
};
export interface Recipe {
Timestamp: Date;
MachineSetting: MachineSetting;

View file

@ -1,18 +1,31 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, tap } from 'rxjs';
import { Recipe, Recipe01 } from '../models/recipe.model';
import {
Recipe,
Recipe01,
RecipeDetail,
RecipeDetailMat,
RecipeOverview,
RecipeOverviewList,
RecipesDashboard,
} from '../models/recipe.model';
import { environment } from 'src/environments/environment';
import { RecipeMetaData } from 'src/app/shared/types/recipe';
interface RecipeParams {
type RecipeOverviewParams = {
filename: string;
country: string;
materialIds: number[];
offset: number;
take: number;
search: string;
}
};
type RecipeDashboardParams = {
filename: string;
country: string;
};
interface RecipeFiles {
[key: string]: string[];
@ -25,36 +38,80 @@ export class RecipeService {
constructor(private _httpClient: HttpClient) {}
getRecipes(
params: RecipeParams = {
take: 10,
offset: 0,
search: '',
getRecipesDashboard(
params: RecipeDashboardParams = {
country: this.getCurrentCountry(),
filename: this.getCurrentFile(),
}
): Observable<RecipesDashboard> {
return this._httpClient.get<RecipesDashboard>(
environment.api + '/recipes/dashboard',
{
params: {
country: params.country,
filename: params.filename,
},
withCredentials: true,
responseType: 'json',
}
);
}
getRecipeOverview(
params: RecipeOverviewParams = {
country: this.getCurrentCountry(),
filename: this.getCurrentFile(),
materialIds: [],
offset: 0,
take: 20,
search: '',
}
): 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,
country: params.country,
filename: params.filename,
material_ids: params.materialIds.join(','),
},
withCredentials: true,
responseType: 'json',
});
): Observable<RecipeOverviewList> {
return this._httpClient.get<RecipeOverviewList>(
environment.api + '/recipes/overview',
{
params: {
country: params.country,
filename: params.filename,
materialIds: params.materialIds.join(','),
offset: params.offset.toString(),
take: params.take.toString(),
search: params.search,
},
withCredentials: true,
responseType: 'json',
}
);
}
getRecipeDetail(productCode: string): Observable<RecipeDetail> {
return this._httpClient.get<RecipeDetail>(
environment.api + '/recipes/' + productCode,
{
params: {
filename: this.getCurrentFile(),
country: this.getCurrentCountry(),
},
withCredentials: true,
responseType: 'json',
}
);
}
getRecipeDetailMat(
productCode: string
): Observable<{ result: RecipeDetailMat[] }> {
return this._httpClient.get<{ result: RecipeDetailMat[] }>(
environment.api + '/recipes/' + productCode + '/mat',
{
params: {
filename: this.getCurrentFile(),
country: this.getCurrentCountry(),
},
withCredentials: true,
responseType: 'json',
}
);
}
getCurrentFile(): string {