From b1639f5d9b6bf31e6ebd0d9720591251a2c08fbb Mon Sep 17 00:00:00 2001 From: Urtzi Alfaro Date: Wed, 23 Jul 2025 10:02:48 +0200 Subject: [PATCH] Add new frontend - fix 19 --- frontend/src/api/services/authService.ts | 49 +++++- frontend/src/api/services/dataService.ts | 38 ++++- .../src/api/services/forecastingService.ts | 25 ++- .../src/api/services/notificationService.ts | 17 +- frontend/src/api/services/tenantService.ts | 19 ++- frontend/src/api/services/trainingService.ts | 45 +++++- frontend/src/api/types/api.ts | 150 ------------------ 7 files changed, 168 insertions(+), 175 deletions(-) diff --git a/frontend/src/api/services/authService.ts b/frontend/src/api/services/authService.ts index 99f62291..27042420 100644 --- a/frontend/src/api/services/authService.ts +++ b/frontend/src/api/services/authService.ts @@ -2,13 +2,46 @@ import { apiClient } from '../base/apiClient'; import { tokenManager } from '../auth/tokenManager'; import { - ApiResponse, - LoginRequest, - RegisterRequest, - TokenResponse, - UserProfile, + ApiResponse } from '../types/api'; + +// Auth types +export interface LoginRequest { + email: string; + password: string; +} + +export interface RegisterRequest { + email: string; + password: string; + full_name: string; + phone?: string; + language?: string; +} + +export interface TokenResponse { + access_token: string; + refresh_token: string; + token_type: string; + expires_in: number; +} + +export interface UserProfile { + id: string; + email: string; + full_name: string; + is_active: boolean; + is_verified: boolean; + tenant_id?: string; + role: string; + phone?: string; + language: string; + timezone: string; + created_at?: string; + last_login?: string; +} + export class AuthService { /** * Check if user is authenticated (has valid token) @@ -27,7 +60,7 @@ export class AuthService { * Get current user profile */ async getCurrentUser(): Promise { - const response = await apiClient.get>('/users/me'); + const response = await apiClient.get('/users/me'); return response.data!; } @@ -141,11 +174,11 @@ export class AuthService { * Update user profile */ async updateProfile(updates: Partial): Promise { - const response = await apiClient.put>( + const response = await apiClient.put( '/api/v1/users/me', updates ); - return response.data!; + return response; } /** diff --git a/frontend/src/api/services/dataService.ts b/frontend/src/api/services/dataService.ts index 86d6d314..6578f38b 100644 --- a/frontend/src/api/services/dataService.ts +++ b/frontend/src/api/services/dataService.ts @@ -1,11 +1,7 @@ // src/api/services/DataService.ts import { apiClient } from '../base/apiClient'; import { - ApiResponse, - SalesRecord, - CreateSalesRequest, - WeatherData, - TrafficData, + ApiResponse } from '../types/api'; export interface DashboardStats { @@ -33,6 +29,38 @@ export interface DataValidation { duplicates: number; } +// Data types +export interface WeatherData { + date: string; + temperature: number; + humidity: number; + precipitation: number; + wind_speed: number; +} + +export interface TrafficData { + date: string; + traffic_volume: number; + pedestrian_count: number; +} + +export interface SalesRecord { + id: string; + tenant_id: string; + product_name: string; + quantity_sold: number; + revenue: number; + date: string; + created_at: string; +} + +export interface CreateSalesRequest { + product_name: string; + quantity_sold: number; + revenue: number; + date: string; +} + export class DataService { /** * Upload sales history file diff --git a/frontend/src/api/services/forecastingService.ts b/frontend/src/api/services/forecastingService.ts index d8fb9ff1..c8e93c2f 100644 --- a/frontend/src/api/services/forecastingService.ts +++ b/frontend/src/api/services/forecastingService.ts @@ -1,11 +1,30 @@ // src/api/services/ForecastingService.ts import { apiClient } from '../base/apiClient'; import { - ApiResponse, - ForecastRecord, - ForecastRequest, + ApiResponse } from '../types/api'; +// Forecast types +export interface ForecastRecord { + id: string; + tenant_id: string; + product_name: string; + forecast_date: string; + predicted_quantity: number; + confidence_lower: number; + confidence_upper: number; + model_version: string; + created_at: string; +} + +export interface ForecastRequest { + product_name?: string; + forecast_days?: number; + include_confidence?: boolean; +} + + + export interface SingleForecastRequest { product_name: string; forecast_date: string; diff --git a/frontend/src/api/services/notificationService.ts b/frontend/src/api/services/notificationService.ts index 048d85cf..38d7e93f 100644 --- a/frontend/src/api/services/notificationService.ts +++ b/frontend/src/api/services/notificationService.ts @@ -2,8 +2,8 @@ import { apiClient } from '../base/apiClient'; import { ApiResponse, - NotificationSettings, -} from '../types/api'; + NotificationSettings +} from '@/api/services'; export interface NotificationCreate { type: 'email' | 'whatsapp' | 'push'; @@ -101,6 +101,19 @@ export interface BulkNotificationStatus { completed_at?: string; } +// Notification types +export interface NotificationSettings { + email_enabled: boolean; + whatsapp_enabled: boolean; + training_notifications: boolean; + forecast_notifications: boolean; + alert_thresholds: { + low_stock_percentage: number; + high_demand_increase: number; + }; +} + + export class NotificationService { /** * Send single notification diff --git a/frontend/src/api/services/tenantService.ts b/frontend/src/api/services/tenantService.ts index 048efc39..5ae9af12 100644 --- a/frontend/src/api/services/tenantService.ts +++ b/frontend/src/api/services/tenantService.ts @@ -1,9 +1,8 @@ // src/api/services/TenantService.ts import { apiClient } from '../base/apiClient'; import { - ApiResponse, - TenantInfo, // Assuming TenantInfo is equivalent to TenantResponse from backend -} from '../types/api'; + ApiResponse +} from '@/api/services'; export interface TenantCreate { name: string; @@ -92,6 +91,20 @@ export interface TenantMemberResponse { // Add any other fields expected from the backend's TenantMemberResponse } +// Tenant types +export interface TenantInfo { + id: string; + name: string; + email: string; + phone: string; + address: string; + latitude: number; + longitude: number; + business_type: string; + is_active: boolean; + created_at: string; +} + export class TenantService { /** * Register a new bakery (tenant) diff --git a/frontend/src/api/services/trainingService.ts b/frontend/src/api/services/trainingService.ts index 7b3cc25e..1a7aad93 100644 --- a/frontend/src/api/services/trainingService.ts +++ b/frontend/src/api/services/trainingService.ts @@ -1,12 +1,49 @@ // src/api/services/TrainingService.ts import { apiClient } from '../base/apiClient'; import { - ApiResponse, - TrainingRequest, - TrainingJobStatus, - TrainedModel, + ApiResponse } from '../types/api'; +import { + ApiResponse +} from '@/api/services'; + +export interface TrainingJobStatus { + id: string; + tenant_id: string; + status: 'queued' | 'running' | 'completed' | 'failed' | 'cancelled'; + progress: number; + current_step?: string; + started_at: string; + completed_at?: string; + duration_seconds?: number; + models_trained?: Record; + metrics?: Record; + error_message?: string; +} + +export interface TrainingRequest { + force_retrain?: boolean; + products?: string[]; + training_days?: number; +} + +export interface TrainedModel { + id: string; + product_name: string; + model_type: string; + model_version: string; + mape?: number; + rmse?: number; + mae?: number; + r2_score?: number; + training_samples?: number; + features_used?: string[]; + is_active: boolean; + created_at: string; + last_used_at?: string; +} + export interface TrainingJobProgress { id: string; status: 'queued' | 'running' | 'completed' | 'failed' | 'cancelled'; diff --git a/frontend/src/api/types/api.ts b/frontend/src/api/types/api.ts index 87022eab..48dff4d7 100644 --- a/frontend/src/api/types/api.ts +++ b/frontend/src/api/types/api.ts @@ -18,153 +18,3 @@ export interface ApiError { timestamp?: string; } -// Auth types -export interface LoginRequest { - email: string; - password: string; -} - -export interface RegisterRequest { - email: string; - password: string; - full_name: string; - phone?: string; - language?: string; -} - -export interface TokenResponse { - access_token: string; - refresh_token: string; - token_type: string; - expires_in: number; -} - -export interface UserProfile { - id: string; - email: string; - full_name: string; - is_active: boolean; - is_verified: boolean; - tenant_id?: string; - role: string; - phone?: string; - language: string; - timezone: string; - created_at?: string; - last_login?: string; -} - -// Tenant types -export interface TenantInfo { - id: string; - name: string; - email: string; - phone: string; - address: string; - latitude: number; - longitude: number; - business_type: string; - is_active: boolean; - created_at: string; -} - -// Sales types -export interface SalesRecord { - id: string; - tenant_id: string; - product_name: string; - quantity_sold: number; - revenue: number; - date: string; - created_at: string; -} - -export interface CreateSalesRequest { - product_name: string; - quantity_sold: number; - revenue: number; - date: string; -} - -// Training types -export interface TrainingJobStatus { - id: string; - tenant_id: string; - status: 'queued' | 'running' | 'completed' | 'failed' | 'cancelled'; - progress: number; - current_step?: string; - started_at: string; - completed_at?: string; - duration_seconds?: number; - models_trained?: Record; - metrics?: Record; - error_message?: string; -} - -export interface TrainingRequest { - force_retrain?: boolean; - products?: string[]; - training_days?: number; -} - -export interface TrainedModel { - id: string; - product_name: string; - model_type: string; - model_version: string; - mape?: number; - rmse?: number; - mae?: number; - r2_score?: number; - training_samples?: number; - features_used?: string[]; - is_active: boolean; - created_at: string; - last_used_at?: string; -} - -// Forecast types -export interface ForecastRecord { - id: string; - tenant_id: string; - product_name: string; - forecast_date: string; - predicted_quantity: number; - confidence_lower: number; - confidence_upper: number; - model_version: string; - created_at: string; -} - -export interface ForecastRequest { - product_name?: string; - forecast_days?: number; - include_confidence?: boolean; -} - -// Data types -export interface WeatherData { - date: string; - temperature: number; - humidity: number; - precipitation: number; - wind_speed: number; -} - -export interface TrafficData { - date: string; - traffic_volume: number; - pedestrian_count: number; -} - -// Notification types -export interface NotificationSettings { - email_enabled: boolean; - whatsapp_enabled: boolean; - training_notifications: boolean; - forecast_notifications: boolean; - alert_thresholds: { - low_stock_percentage: number; - high_demand_increase: number; - }; -}