diff --git a/backend/gestion/routes/routes.go b/backend/gestion/routes/routes.go index e419cad7..68c6da1b 100644 --- a/backend/gestion/routes/routes.go +++ b/backend/gestion/routes/routes.go @@ -319,6 +319,7 @@ func SetupRoutes(router *gin.Engine, database *db.Database, geoService *services cabineGroupV1.POST("/telegram/link-token", handlers.GenerateAdminLinkToken) cabineGroupV1.DELETE("/telegram/unlink", handlers.UnlinkAdminTelegram) + cabineGroupV1.GET("/commands", handlers.GetAllCommands) cabineGroupV1.GET("/commands/:id/items", handlers.ShowItems) cabineGroupV1.POST("/commands/:id/confirm-reception", handlers.StaffApproveDelivery) cabineGroupV1.POST("/commands/:id/assign", handlers.AssignDeliveryPerson) @@ -327,9 +328,10 @@ func SetupRoutes(router *gin.Engine, database *db.Database, geoService *services cabineGroupV1.PUT("/items/:item_id/status", handlers.UpdateItemStatus) cabineGroupV1.GET("/commands/:id/deliveryman/location", handlers.GetDeliverymanLocationForCommand) cabineGroupV1.GET("/all/deliveryman", handlers.GetAllDeliveryMen) + cabineGroupV1.GET("/delivery-persons/:username", handlers.GetDeliveryPersonDetails) + cabineGroupV1.GET("/all/clients", handlers.GetAllClients) cabineGroupV1.DELETE("/commands/:id", handlers.DeleteCommandByCabine) cabineGroupV1.POST("/commands/:id/propose-address", handlers.ProposeAddressChange) - // ⭐ NOUVEAU - ANNULATION PAR CABINE cabineGroupV1.GET("/commands/cancelled", handlers.GetAllCancelledOrders) cabineGroupV1.GET("/client/:username/penalties", handlers.GetClientPenaltiesAdmin) // Voir pénalités client cabineGroupV1.POST("/client/:username/penalties/reset", handlers.ResetClientPenaltiesAdmin) // Reset pénalités diff --git a/frontend-admin/src/api/api_cabine.ts b/frontend-admin/src/api/api_cabine.ts index d9b037c8..1be5da95 100644 --- a/frontend-admin/src/api/api_cabine.ts +++ b/frontend-admin/src/api/api_cabine.ts @@ -194,7 +194,7 @@ export const getAllDeliveryPersonsWithDetails = async (): Promise<{ users.map(async (u: any): Promise => { try { const { data: details } = await apiClient.get( - `${V2}/admin/protected/delivery-persons/${u.username}`, + `${API}/delivery-persons/${u.username}`, ); const d = details.deliveryman || details; const parsedStatus = parseStatus(d.status); @@ -367,7 +367,7 @@ export const markCabineNotificationsRead = async (): Promise => { export const getPublicSettings = async (): Promise => { try { const { data } = await apiClient.get( - `https://5.181.0.112.nip.io/api/v1/app-settings`, + `${API_BASE_URL}/api/v1/app-settings`, ); return { penalties_enabled: data.penalties_enabled ?? true, @@ -427,11 +427,41 @@ export const getAllAddresses = async (): Promise< })); }; +// ============================================ +// COMMANDES — CABINE +// ============================================ + +export const getCabineCommands = async (): Promise<{ + success: boolean; + commands: any[]; + count: number; +}> => { + try { + const { data } = await apiClient.get(`${API}/commands`); + return { success: true, commands: data.commands || [], count: data.count || 0 }; + } catch { + return { success: false, commands: [], count: 0 }; + } +}; + +// ============================================ +// CLIENTS — CABINE +// ============================================ + +export const getCabineAllClients = async (): Promise => { + try { + const { data } = await apiClient.get(`${API}/all/clients`); + return data.clients || []; + } catch { + return []; + } +}; + // ============================================ // TELEGRAM — CABINE // ============================================ -const CABINE_API = "https://5.181.0.112.nip.io/api/v1/cabine"; +const CABINE_API = `${API_BASE_URL}/api/v1/cabine`; export const getCabineTelegramStatus = async (): Promise<{ linked: boolean; diff --git a/frontend-admin/src/screens/cabine/DashboardScreen.tsx b/frontend-admin/src/screens/cabine/DashboardScreen.tsx index 62b439fc..5849937b 100644 --- a/frontend-admin/src/screens/cabine/DashboardScreen.tsx +++ b/frontend-admin/src/screens/cabine/DashboardScreen.tsx @@ -15,8 +15,8 @@ import { spacing, fontSize, borderRadius } from "../../theme"; import { useTheme } from "../../context/ThemeContext"; import { shadows } from "../../theme/shadows"; import { useAuth } from "../../auth/AuthContext"; -import { getAllCommands } from "../../api/api_admin"; import { + getCabineCommands, getAllDeliveryPersonsWithDetails, getCabineTelegramStatus, generateCabineLinkToken, @@ -46,7 +46,7 @@ export default function DashboardScreen() { const loadStats = useCallback(async () => { try { const [allCmd, livreursRes] = await Promise.all([ - getAllCommands(), + getCabineCommands(), getAllDeliveryPersonsWithDetails(), ]); const cmds = allCmd.commands; diff --git a/frontend-admin/src/screens/cabine/OrdersScreen.tsx b/frontend-admin/src/screens/cabine/OrdersScreen.tsx index 89be366d..402eebd9 100644 --- a/frontend-admin/src/screens/cabine/OrdersScreen.tsx +++ b/frontend-admin/src/screens/cabine/OrdersScreen.tsx @@ -12,7 +12,6 @@ import { import { Ionicons } from "@expo/vector-icons"; import { spacing, fontSize, borderRadius } from "../../theme"; import { useTheme } from "../../context/ThemeContext"; -import { getAllCommands } from "../../api/api_admin"; import { getCommandItems, deleteCommand, @@ -21,6 +20,7 @@ import { getCabineLivreursList, assignDeliveryPersonByCabine, proposeAddressChangeCabine, + getCabineCommands, } from "../../api/api_cabine"; import type { CommandResponse } from "../../api/types"; import StatusBadge from "../../components/StatusBadge"; @@ -78,7 +78,7 @@ export default function OrdersScreen() { const loadData = useCallback(async () => { try { - const result = await getAllCommands(); + const result = await getCabineCommands(); setCommands( result.commands.filter( (c: CommandResponse) => diff --git a/frontend-admin/src/screens/cabine/UsersScreen.tsx b/frontend-admin/src/screens/cabine/UsersScreen.tsx index 15db6309..c3021539 100644 --- a/frontend-admin/src/screens/cabine/UsersScreen.tsx +++ b/frontend-admin/src/screens/cabine/UsersScreen.tsx @@ -2,8 +2,7 @@ import React, { useState, useEffect, useCallback, useMemo } from "react"; import { View, Text, StyleSheet, FlatList, RefreshControl } from "react-native"; import { spacing, fontSize } from "../../theme"; import { useTheme } from "../../context/ThemeContext"; -import { getAllClients } from "../../api/api_admin"; -import { applyClientPenalty, resetClientPenalties, resetClientPoints, getPublicSettings } from "../../api/api_cabine"; +import { applyClientPenalty, resetClientPenalties, resetClientPoints, getPublicSettings, getCabineAllClients } from "../../api/api_cabine"; import type { PublicSettings } from "../../api/api_cabine"; import type { ClientResponse } from "../../api/types"; import LoadingSpinner from "../../components/ui/LoadingSpinner"; @@ -35,7 +34,7 @@ export default function UsersScreen() { const loadData = useCallback(async () => { try { const [clientsData, settings] = await Promise.all([ - getAllClients(), + getCabineAllClients(), getPublicSettings(), ]); setClients(clientsData);