UPDATE
This commit is contained in:
@@ -11,6 +11,7 @@ import type {
|
||||
import { normalizeRecommendationTaskStatus } from "./recommendationTask";
|
||||
|
||||
const PREFIX = "/api/fertilization-recommendation";
|
||||
const RECOMMEND_PREFIX = "/api/fertilization";
|
||||
|
||||
export interface FarmData {
|
||||
soilType: string;
|
||||
@@ -21,12 +22,15 @@ export interface FarmData {
|
||||
export interface GrowthStage {
|
||||
id: string;
|
||||
icon: string;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export interface CropOption {
|
||||
id: string;
|
||||
labelKey: string;
|
||||
labelKey?: string;
|
||||
name?: string;
|
||||
icon: string;
|
||||
growthStages?: string[];
|
||||
}
|
||||
|
||||
export interface FertilizationConfigResponse {
|
||||
@@ -107,7 +111,7 @@ export const fertilizationRecommendationService = {
|
||||
): Promise<FertilizationRecommendResponse> {
|
||||
return unwrap(
|
||||
apiClient.post<ApiResponse<FertilizationRecommendResponse>>(
|
||||
`${PREFIX}/recommend/`,
|
||||
`${RECOMMEND_PREFIX}/recommend/`,
|
||||
payload ?? {},
|
||||
),
|
||||
).then((response) =>
|
||||
|
||||
@@ -11,6 +11,7 @@ import type {
|
||||
import { normalizeRecommendationTaskStatus } from "./recommendationTask";
|
||||
|
||||
const PREFIX = "/api/irrigation-recommendation";
|
||||
const RECOMMEND_PREFIX = "/api/irrigation";
|
||||
|
||||
export interface FarmInfo {
|
||||
soilType: string;
|
||||
@@ -20,8 +21,10 @@ export interface FarmInfo {
|
||||
|
||||
export interface CropOption {
|
||||
id: string;
|
||||
labelKey: string;
|
||||
labelKey?: string;
|
||||
name?: string;
|
||||
icon: string;
|
||||
growthStages?: string[];
|
||||
}
|
||||
|
||||
export interface IrrigationMethod {
|
||||
@@ -48,6 +51,7 @@ export interface IrrigationPlan {
|
||||
export interface IrrigationRecommendPayload {
|
||||
farm_uuid: string;
|
||||
crop_id?: string;
|
||||
growth_stage?: string;
|
||||
irrigation_method_id?: string;
|
||||
farm_data?: Partial<FarmInfo>;
|
||||
soilType?: string;
|
||||
@@ -156,7 +160,7 @@ export const irrigationRecommendationService = {
|
||||
): Promise<IrrigationRecommendResponse> {
|
||||
return unwrap(
|
||||
apiClient.post<ApiResponse<IrrigationRecommendResponse>>(
|
||||
`${PREFIX}/recommend/`,
|
||||
`${RECOMMEND_PREFIX}/recommend/`,
|
||||
payload ?? {},
|
||||
),
|
||||
).then((response) =>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { apiClient } from "../client";
|
||||
|
||||
const PREFIX = "/api/plants";
|
||||
|
||||
export interface SelectedPlant {
|
||||
name: string;
|
||||
icon: string;
|
||||
growth_stages: string[];
|
||||
}
|
||||
|
||||
interface ApiResponse<T> {
|
||||
code: number;
|
||||
msg: string;
|
||||
data: T;
|
||||
}
|
||||
|
||||
async function unwrap<T>(promise: Promise<ApiResponse<T>>): Promise<T> {
|
||||
const res = await promise;
|
||||
return res.data;
|
||||
}
|
||||
|
||||
export const selectedPlantsService = {
|
||||
getSelected(farmUuid: string): Promise<SelectedPlant[]> {
|
||||
return unwrap(
|
||||
apiClient.get<ApiResponse<SelectedPlant[]>>(
|
||||
`${PREFIX}/selected/?farm_uuid=${encodeURIComponent(farmUuid)}`,
|
||||
),
|
||||
);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user