REFACTOR ALL APIs
This commit is contained in:
@@ -1,39 +1,57 @@
|
||||
// ================================================================
|
||||
// frontend/src/api/services/production.ts
|
||||
// ================================================================
|
||||
/**
|
||||
* Production API Service - Handles all production-related API calls
|
||||
* Production Service - Complete backend alignment
|
||||
*
|
||||
* Backend API structure (3-tier architecture):
|
||||
* - ATOMIC: production_batches.py, production_schedules.py
|
||||
* - OPERATIONS: production_operations.py (batch lifecycle, capacity management)
|
||||
* - ANALYTICS: analytics.py, production_dashboard.py
|
||||
*
|
||||
* Last Updated: 2025-10-05
|
||||
* Status: ✅ Complete - Zero drift with backend
|
||||
*/
|
||||
|
||||
import { apiClient } from '../client/apiClient';
|
||||
import {
|
||||
// Types
|
||||
// Batches
|
||||
ProductionBatchResponse,
|
||||
ProductionBatchCreate,
|
||||
ProductionBatchUpdate,
|
||||
ProductionBatchStatusUpdate,
|
||||
ProductionBatchListResponse,
|
||||
ProductionBatchFilters,
|
||||
BatchStatistics,
|
||||
// Schedules
|
||||
ProductionScheduleResponse,
|
||||
ProductionScheduleCreate,
|
||||
ProductionScheduleUpdate,
|
||||
ProductionScheduleFilters,
|
||||
// Capacity
|
||||
ProductionCapacityResponse,
|
||||
ProductionCapacityFilters,
|
||||
// Quality
|
||||
QualityCheckResponse,
|
||||
QualityCheckCreate,
|
||||
QualityCheckFilters,
|
||||
// Analytics
|
||||
ProductionPerformanceAnalytics,
|
||||
YieldTrendsAnalytics,
|
||||
TopDefectsAnalytics,
|
||||
EquipmentEfficiencyAnalytics,
|
||||
CapacityBottlenecks,
|
||||
// Dashboard
|
||||
ProductionDashboardSummary,
|
||||
BatchStatistics,
|
||||
} from '../types/production';
|
||||
|
||||
export class ProductionService {
|
||||
private baseUrl = '/production';
|
||||
private baseUrl = '/tenants';
|
||||
|
||||
// ================================================================
|
||||
// PRODUCTION BATCH ENDPOINTS
|
||||
// ================================================================
|
||||
// ===================================================================
|
||||
// ATOMIC: Production Batches CRUD
|
||||
// Backend: services/production/app/api/production_batches.py
|
||||
// ===================================================================
|
||||
|
||||
async getBatches(
|
||||
tenantId: string,
|
||||
@@ -49,13 +67,15 @@ export class ProductionService {
|
||||
if (filters?.page_size) params.append('page_size', filters.page_size.toString());
|
||||
|
||||
const queryString = params.toString();
|
||||
const url = `/tenants/${tenantId}${this.baseUrl}/batches${queryString ? `?${queryString}` : ''}`;
|
||||
const url = `${this.baseUrl}/${tenantId}/production/batches${queryString ? `?${queryString}` : ''}`;
|
||||
|
||||
return apiClient.get<ProductionBatchListResponse>(url);
|
||||
}
|
||||
|
||||
async getBatch(tenantId: string, batchId: string): Promise<ProductionBatchResponse> {
|
||||
return apiClient.get<ProductionBatchResponse>(`/tenants/${tenantId}${this.baseUrl}/batches/${batchId}`);
|
||||
return apiClient.get<ProductionBatchResponse>(
|
||||
`${this.baseUrl}/${tenantId}/production/batches/${batchId}`
|
||||
);
|
||||
}
|
||||
|
||||
async createBatch(
|
||||
@@ -63,7 +83,7 @@ export class ProductionService {
|
||||
batchData: ProductionBatchCreate
|
||||
): Promise<ProductionBatchResponse> {
|
||||
return apiClient.post<ProductionBatchResponse>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/batches`,
|
||||
`${this.baseUrl}/${tenantId}/production/batches`,
|
||||
batchData
|
||||
);
|
||||
}
|
||||
@@ -74,41 +94,13 @@ export class ProductionService {
|
||||
batchData: ProductionBatchUpdate
|
||||
): Promise<ProductionBatchResponse> {
|
||||
return apiClient.put<ProductionBatchResponse>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/batches/${batchId}`,
|
||||
`${this.baseUrl}/${tenantId}/production/batches/${batchId}`,
|
||||
batchData
|
||||
);
|
||||
}
|
||||
|
||||
async deleteBatch(tenantId: string, batchId: string): Promise<void> {
|
||||
return apiClient.delete<void>(`/tenants/${tenantId}${this.baseUrl}/batches/${batchId}`);
|
||||
}
|
||||
|
||||
async updateBatchStatus(
|
||||
tenantId: string,
|
||||
batchId: string,
|
||||
statusData: ProductionBatchStatusUpdate
|
||||
): Promise<ProductionBatchResponse> {
|
||||
return apiClient.patch<ProductionBatchResponse>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/batches/${batchId}/status`,
|
||||
statusData
|
||||
);
|
||||
}
|
||||
|
||||
async startBatch(tenantId: string, batchId: string): Promise<ProductionBatchResponse> {
|
||||
return apiClient.post<ProductionBatchResponse>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/batches/${batchId}/start`
|
||||
);
|
||||
}
|
||||
|
||||
async completeBatch(
|
||||
tenantId: string,
|
||||
batchId: string,
|
||||
completionData?: { actual_quantity?: number; notes?: string }
|
||||
): Promise<ProductionBatchResponse> {
|
||||
return apiClient.post<ProductionBatchResponse>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/batches/${batchId}/complete`,
|
||||
completionData || {}
|
||||
);
|
||||
return apiClient.delete<void>(`${this.baseUrl}/${tenantId}/production/batches/${batchId}`);
|
||||
}
|
||||
|
||||
async getBatchStatistics(
|
||||
@@ -121,14 +113,15 @@ export class ProductionService {
|
||||
if (endDate) params.append('end_date', endDate);
|
||||
|
||||
const queryString = params.toString();
|
||||
const url = `/tenants/${tenantId}${this.baseUrl}/batches/stats${queryString ? `?${queryString}` : ''}`;
|
||||
const url = `${this.baseUrl}/${tenantId}/production/batches/stats${queryString ? `?${queryString}` : ''}`;
|
||||
|
||||
return apiClient.get<BatchStatistics>(url);
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// PRODUCTION SCHEDULE ENDPOINTS
|
||||
// ================================================================
|
||||
// ===================================================================
|
||||
// ATOMIC: Production Schedules CRUD
|
||||
// Backend: services/production/app/api/production_schedules.py
|
||||
// ===================================================================
|
||||
|
||||
async getSchedules(
|
||||
tenantId: string,
|
||||
@@ -137,18 +130,21 @@ export class ProductionService {
|
||||
const params = new URLSearchParams();
|
||||
if (filters?.start_date) params.append('start_date', filters.start_date);
|
||||
if (filters?.end_date) params.append('end_date', filters.end_date);
|
||||
if (filters?.is_finalized !== undefined) params.append('is_finalized', filters.is_finalized.toString());
|
||||
if (filters?.is_finalized !== undefined)
|
||||
params.append('is_finalized', filters.is_finalized.toString());
|
||||
if (filters?.page) params.append('page', filters.page.toString());
|
||||
if (filters?.page_size) params.append('page_size', filters.page_size.toString());
|
||||
|
||||
const queryString = params.toString();
|
||||
const url = `/tenants/${tenantId}${this.baseUrl}/schedules${queryString ? `?${queryString}` : ''}`;
|
||||
const url = `${this.baseUrl}/${tenantId}/production/schedules${queryString ? `?${queryString}` : ''}`;
|
||||
|
||||
return apiClient.get(url);
|
||||
}
|
||||
|
||||
async getSchedule(tenantId: string, scheduleId: string): Promise<ProductionScheduleResponse> {
|
||||
return apiClient.get<ProductionScheduleResponse>(`/tenants/${tenantId}${this.baseUrl}/schedules/${scheduleId}`);
|
||||
return apiClient.get<ProductionScheduleResponse>(
|
||||
`${this.baseUrl}/${tenantId}/production/schedules/${scheduleId}`
|
||||
);
|
||||
}
|
||||
|
||||
async createSchedule(
|
||||
@@ -156,7 +152,7 @@ export class ProductionService {
|
||||
scheduleData: ProductionScheduleCreate
|
||||
): Promise<ProductionScheduleResponse> {
|
||||
return apiClient.post<ProductionScheduleResponse>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/schedules`,
|
||||
`${this.baseUrl}/${tenantId}/production/schedules`,
|
||||
scheduleData
|
||||
);
|
||||
}
|
||||
@@ -167,28 +163,64 @@ export class ProductionService {
|
||||
scheduleData: ProductionScheduleUpdate
|
||||
): Promise<ProductionScheduleResponse> {
|
||||
return apiClient.put<ProductionScheduleResponse>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/schedules/${scheduleId}`,
|
||||
`${this.baseUrl}/${tenantId}/production/schedules/${scheduleId}`,
|
||||
scheduleData
|
||||
);
|
||||
}
|
||||
|
||||
async deleteSchedule(tenantId: string, scheduleId: string): Promise<void> {
|
||||
return apiClient.delete<void>(`/tenants/${tenantId}${this.baseUrl}/schedules/${scheduleId}`);
|
||||
return apiClient.delete<void>(`${this.baseUrl}/${tenantId}/production/schedules/${scheduleId}`);
|
||||
}
|
||||
|
||||
async getTodaysSchedule(tenantId: string): Promise<ProductionScheduleResponse | null> {
|
||||
return apiClient.get<ProductionScheduleResponse | null>(
|
||||
`${this.baseUrl}/${tenantId}/production/schedules/today`
|
||||
);
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
// OPERATIONS: Batch Lifecycle Management
|
||||
// Backend: services/production/app/api/production_operations.py
|
||||
// ===================================================================
|
||||
|
||||
async updateBatchStatus(
|
||||
tenantId: string,
|
||||
batchId: string,
|
||||
statusData: ProductionBatchStatusUpdate
|
||||
): Promise<ProductionBatchResponse> {
|
||||
return apiClient.patch<ProductionBatchResponse>(
|
||||
`${this.baseUrl}/${tenantId}/production/batches/${batchId}/status`,
|
||||
statusData
|
||||
);
|
||||
}
|
||||
|
||||
async startBatch(tenantId: string, batchId: string): Promise<ProductionBatchResponse> {
|
||||
return apiClient.post<ProductionBatchResponse>(
|
||||
`${this.baseUrl}/${tenantId}/production/batches/${batchId}/start`
|
||||
);
|
||||
}
|
||||
|
||||
async completeBatch(
|
||||
tenantId: string,
|
||||
batchId: string,
|
||||
completionData?: { actual_quantity?: number; notes?: string }
|
||||
): Promise<ProductionBatchResponse> {
|
||||
return apiClient.post<ProductionBatchResponse>(
|
||||
`${this.baseUrl}/${tenantId}/production/batches/${batchId}/complete`,
|
||||
completionData || {}
|
||||
);
|
||||
}
|
||||
|
||||
async finalizeSchedule(tenantId: string, scheduleId: string): Promise<ProductionScheduleResponse> {
|
||||
return apiClient.post<ProductionScheduleResponse>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/schedules/${scheduleId}/finalize`
|
||||
`${this.baseUrl}/${tenantId}/production/schedules/${scheduleId}/finalize`
|
||||
);
|
||||
}
|
||||
|
||||
async getTodaysSchedule(tenantId: string): Promise<ProductionScheduleResponse | null> {
|
||||
return apiClient.get<ProductionScheduleResponse | null>(`/tenants/${tenantId}${this.baseUrl}/schedules/today`);
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// PRODUCTION CAPACITY ENDPOINTS
|
||||
// ================================================================
|
||||
// ===================================================================
|
||||
// OPERATIONS: Capacity Management
|
||||
// Backend: services/production/app/api/production_operations.py
|
||||
// ===================================================================
|
||||
|
||||
async getCapacity(
|
||||
tenantId: string,
|
||||
@@ -197,27 +229,36 @@ export class ProductionService {
|
||||
const params = new URLSearchParams();
|
||||
if (filters?.resource_type) params.append('resource_type', filters.resource_type);
|
||||
if (filters?.date) params.append('date', filters.date);
|
||||
if (filters?.availability !== undefined) params.append('availability', filters.availability.toString());
|
||||
if (filters?.availability !== undefined)
|
||||
params.append('availability', filters.availability.toString());
|
||||
if (filters?.page) params.append('page', filters.page.toString());
|
||||
if (filters?.page_size) params.append('page_size', filters.page_size.toString());
|
||||
|
||||
const queryString = params.toString();
|
||||
const url = `/tenants/${tenantId}${this.baseUrl}/capacity${queryString ? `?${queryString}` : ''}`;
|
||||
const url = `${this.baseUrl}/${tenantId}/production/capacity${queryString ? `?${queryString}` : ''}`;
|
||||
|
||||
return apiClient.get(url);
|
||||
}
|
||||
|
||||
async getCapacityByDate(tenantId: string, date: string): Promise<ProductionCapacityResponse[]> {
|
||||
return apiClient.get<ProductionCapacityResponse[]>(`/tenants/${tenantId}${this.baseUrl}/capacity/date/${date}`);
|
||||
return apiClient.get<ProductionCapacityResponse[]>(
|
||||
`${this.baseUrl}/${tenantId}/production/capacity/date/${date}`
|
||||
);
|
||||
}
|
||||
|
||||
async getCapacityByResource(tenantId: string, resourceId: string): Promise<ProductionCapacityResponse[]> {
|
||||
return apiClient.get<ProductionCapacityResponse[]>(`/tenants/${tenantId}${this.baseUrl}/capacity/resource/${resourceId}`);
|
||||
async getCapacityByResource(
|
||||
tenantId: string,
|
||||
resourceId: string
|
||||
): Promise<ProductionCapacityResponse[]> {
|
||||
return apiClient.get<ProductionCapacityResponse[]>(
|
||||
`${this.baseUrl}/${tenantId}/production/capacity/resource/${resourceId}`
|
||||
);
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// QUALITY CHECK ENDPOINTS
|
||||
// ================================================================
|
||||
// ===================================================================
|
||||
// OPERATIONS: Quality Checks
|
||||
// Backend: services/production/app/api/production_operations.py
|
||||
// ===================================================================
|
||||
|
||||
async getQualityChecks(
|
||||
tenantId: string,
|
||||
@@ -233,13 +274,15 @@ export class ProductionService {
|
||||
if (filters?.page_size) params.append('page_size', filters.page_size.toString());
|
||||
|
||||
const queryString = params.toString();
|
||||
const url = `/tenants/${tenantId}${this.baseUrl}/quality-checks${queryString ? `?${queryString}` : ''}`;
|
||||
const url = `${this.baseUrl}/${tenantId}/production/quality-checks${queryString ? `?${queryString}` : ''}`;
|
||||
|
||||
return apiClient.get(url);
|
||||
}
|
||||
|
||||
async getQualityCheck(tenantId: string, checkId: string): Promise<QualityCheckResponse> {
|
||||
return apiClient.get<QualityCheckResponse>(`/tenants/${tenantId}${this.baseUrl}/quality-checks/${checkId}`);
|
||||
return apiClient.get<QualityCheckResponse>(
|
||||
`${this.baseUrl}/${tenantId}/production/quality-checks/${checkId}`
|
||||
);
|
||||
}
|
||||
|
||||
async createQualityCheck(
|
||||
@@ -247,18 +290,24 @@ export class ProductionService {
|
||||
checkData: QualityCheckCreate
|
||||
): Promise<QualityCheckResponse> {
|
||||
return apiClient.post<QualityCheckResponse>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/quality-checks`,
|
||||
`${this.baseUrl}/${tenantId}/production/quality-checks`,
|
||||
checkData
|
||||
);
|
||||
}
|
||||
|
||||
async getQualityChecksByBatch(tenantId: string, batchId: string): Promise<QualityCheckResponse[]> {
|
||||
return apiClient.get<QualityCheckResponse[]>(`/tenants/${tenantId}${this.baseUrl}/quality-checks/batch/${batchId}`);
|
||||
async getQualityChecksByBatch(
|
||||
tenantId: string,
|
||||
batchId: string
|
||||
): Promise<QualityCheckResponse[]> {
|
||||
return apiClient.get<QualityCheckResponse[]>(
|
||||
`${this.baseUrl}/${tenantId}/production/quality-checks/batch/${batchId}`
|
||||
);
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// ANALYTICS ENDPOINTS
|
||||
// ================================================================
|
||||
// ===================================================================
|
||||
// ANALYTICS: Performance & Trends
|
||||
// Backend: services/production/app/api/analytics.py
|
||||
// ===================================================================
|
||||
|
||||
async getPerformanceAnalytics(
|
||||
tenantId: string,
|
||||
@@ -266,7 +315,7 @@ export class ProductionService {
|
||||
endDate: string
|
||||
): Promise<ProductionPerformanceAnalytics> {
|
||||
return apiClient.get<ProductionPerformanceAnalytics>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/analytics/performance?start_date=${startDate}&end_date=${endDate}`
|
||||
`${this.baseUrl}/${tenantId}/production/analytics/performance?start_date=${startDate}&end_date=${endDate}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -275,7 +324,7 @@ export class ProductionService {
|
||||
period: 'week' | 'month' = 'week'
|
||||
): Promise<YieldTrendsAnalytics> {
|
||||
return apiClient.get<YieldTrendsAnalytics>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/analytics/yield-trends?period=${period}`
|
||||
`${this.baseUrl}/${tenantId}/production/analytics/yield-trends?period=${period}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -289,7 +338,7 @@ export class ProductionService {
|
||||
if (endDate) params.append('end_date', endDate);
|
||||
|
||||
const queryString = params.toString();
|
||||
const url = `/tenants/${tenantId}${this.baseUrl}/analytics/defects${queryString ? `?${queryString}` : ''}`;
|
||||
const url = `${this.baseUrl}/${tenantId}/production/analytics/defects${queryString ? `?${queryString}` : ''}`;
|
||||
|
||||
return apiClient.get<TopDefectsAnalytics>(url);
|
||||
}
|
||||
@@ -304,40 +353,42 @@ export class ProductionService {
|
||||
if (endDate) params.append('end_date', endDate);
|
||||
|
||||
const queryString = params.toString();
|
||||
const url = `/tenants/${tenantId}${this.baseUrl}/analytics/equipment-efficiency${queryString ? `?${queryString}` : ''}`;
|
||||
const url = `${this.baseUrl}/${tenantId}/production/analytics/equipment-efficiency${queryString ? `?${queryString}` : ''}`;
|
||||
|
||||
return apiClient.get<EquipmentEfficiencyAnalytics>(url);
|
||||
}
|
||||
|
||||
async getCapacityBottlenecks(
|
||||
tenantId: string,
|
||||
days: number = 7
|
||||
): Promise<CapacityBottlenecks> {
|
||||
async getCapacityBottlenecks(tenantId: string, days: number = 7): Promise<CapacityBottlenecks> {
|
||||
return apiClient.get<CapacityBottlenecks>(
|
||||
`/tenants/${tenantId}${this.baseUrl}/analytics/capacity-bottlenecks?days=${days}`
|
||||
`${this.baseUrl}/${tenantId}/production/analytics/capacity-bottlenecks?days=${days}`
|
||||
);
|
||||
}
|
||||
|
||||
// ================================================================
|
||||
// DASHBOARD ENDPOINTS
|
||||
// ================================================================
|
||||
// ===================================================================
|
||||
// ANALYTICS: Dashboard
|
||||
// Backend: services/production/app/api/production_dashboard.py
|
||||
// ===================================================================
|
||||
|
||||
async getDashboardSummary(tenantId: string): Promise<ProductionDashboardSummary> {
|
||||
return apiClient.get<ProductionDashboardSummary>(`/tenants/${tenantId}${this.baseUrl}/dashboard/summary`);
|
||||
return apiClient.get<ProductionDashboardSummary>(
|
||||
`${this.baseUrl}/${tenantId}/production/dashboard/summary`
|
||||
);
|
||||
}
|
||||
|
||||
async getDailyProductionPlan(tenantId: string, date?: string): Promise<any> {
|
||||
const queryString = date ? `?date=${date}` : '';
|
||||
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/dashboard/daily-plan${queryString}`);
|
||||
return apiClient.get(`${this.baseUrl}/${tenantId}/production/dashboard/daily-plan${queryString}`);
|
||||
}
|
||||
|
||||
async getProductionRequirements(tenantId: string, date: string): Promise<any> {
|
||||
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/dashboard/requirements/${date}`);
|
||||
return apiClient.get(`${this.baseUrl}/${tenantId}/production/dashboard/requirements/${date}`);
|
||||
}
|
||||
|
||||
async getCapacityOverview(tenantId: string, date?: string): Promise<any> {
|
||||
const queryString = date ? `?date=${date}` : '';
|
||||
return apiClient.get(`/tenants/${tenantId}${this.baseUrl}/dashboard/capacity-overview${queryString}`);
|
||||
return apiClient.get(
|
||||
`${this.baseUrl}/${tenantId}/production/dashboard/capacity-overview${queryString}`
|
||||
);
|
||||
}
|
||||
|
||||
async getQualityOverview(
|
||||
@@ -350,11 +401,11 @@ export class ProductionService {
|
||||
if (endDate) params.append('end_date', endDate);
|
||||
|
||||
const queryString = params.toString();
|
||||
const url = `/tenants/${tenantId}${this.baseUrl}/dashboard/quality-overview${queryString ? `?${queryString}` : ''}`;
|
||||
const url = `${this.baseUrl}/${tenantId}/production/dashboard/quality-overview${queryString ? `?${queryString}` : ''}`;
|
||||
|
||||
return apiClient.get(url);
|
||||
}
|
||||
}
|
||||
|
||||
export const productionService = new ProductionService();
|
||||
export default productionService;
|
||||
export default productionService;
|
||||
|
||||
Reference in New Issue
Block a user