@@ -2,6 +2,7 @@ use crate::error::AppError;
22use crate :: http:: ui:: models:: warehouse;
33use crate :: state:: AppState ;
44use axum:: { extract:: Path , extract:: State , Json } ;
5+ use control_plane:: models:: { Warehouse as WarehouseModel , WarehouseCreateRequest } ;
56use utoipa:: OpenApi ;
67use uuid:: Uuid ;
78
@@ -31,14 +32,33 @@ pub struct ApiDoc;
3132 path = "/ui/warehouses" ,
3233 operation_id = "webWarehousesDashboard" ,
3334 responses(
34- ( status = 200 , description = "List all warehouses" , body = Vec < warehouse:: WarehousesDashboard > ) ,
35+ ( status = 200 , description = "List all warehouses" , body = warehouse:: WarehousesDashboard ) ,
3536 ( status = 500 , description = "Internal server error" )
3637 )
3738) ]
3839pub async fn list_warehouses (
3940 State ( state) : State < AppState > ,
40- ) -> Result < Json < Vec < warehouse:: WarehousesDashboard > > , AppError > {
41- Ok ( Json ( vec ! [ ] ) )
41+ ) -> Result < Json < warehouse:: WarehousesDashboard > , AppError > {
42+ let warehouses = state. control_svc . list_warehouses ( ) . await ?;
43+ let storage_profiles = state. control_svc . list_profiles ( ) . await ?;
44+ let mut extended_warehouses = Vec :: new ( ) ;
45+
46+ for warehouse in warehouses {
47+ let mut extended_warehouse =
48+ warehouse:: WarehouseExtended :: new ( warehouse. clone ( ) . into ( ) , Default :: default ( ) ) ;
49+ if let Some ( profile) = storage_profiles
50+ . iter ( )
51+ . find ( |p| p. id == extended_warehouse. storage_profile_id )
52+ {
53+ extended_warehouse. storage_profile = profile. clone ( ) . into ( ) ;
54+ extended_warehouses. push ( extended_warehouse)
55+ }
56+ }
57+ Ok ( Json ( warehouse:: WarehousesDashboard {
58+ warehouses : extended_warehouses,
59+ statistics : Default :: default ( ) ,
60+ compaction_summary : None ,
61+ } ) )
4262}
4363
4464#[ utoipa:: path(
@@ -49,25 +69,28 @@ pub async fn list_warehouses(
4969 ( "warehouseId" = Uuid , Path , description = "Warehouse ID" )
5070 ) ,
5171 responses(
52- ( status = 200 , description = "Warehouse found" , body = warehouse:: Warehouse ) ,
72+ ( status = 200 , description = "Warehouse found" , body = warehouse:: WarehouseExtended ) ,
5373 ( status = 404 , description = "Warehouse not found" )
5474 )
5575) ]
5676pub async fn get_warehouse (
5777 State ( state) : State < AppState > ,
5878 Path ( warehouse_id) : Path < Uuid > ,
59- ) -> Result < Json < warehouse:: Warehouse > , AppError > {
60- // let warehouse = state.warehouse_service.get_warehouse(warehouse_id).await?;
61- Ok ( Json ( warehouse:: Warehouse {
62- name : "" . to_string ( ) ,
63- storage_profile_id : Default :: default ( ) ,
64- key_prefix : "key" . to_string ( ) ,
65- id : Default :: default ( ) ,
66- external_id : Default :: default ( ) ,
67- location : "" . to_string ( ) ,
68- created_at : Default :: default ( ) ,
69- updated_at : Default :: default ( ) ,
70- } ) )
79+ ) -> Result < Json < warehouse:: WarehouseExtended > , AppError > {
80+ let warehouse = state. control_svc . get_warehouse ( warehouse_id) . await ?;
81+
82+ let mut extended_warehouse =
83+ warehouse:: WarehouseExtended :: new ( warehouse. into ( ) , Default :: default ( ) ) ;
84+
85+ if let Ok ( profile) = state
86+ . control_svc
87+ . get_profile ( extended_warehouse. storage_profile_id )
88+ . await
89+ {
90+ extended_warehouse. storage_profile = profile. into ( ) ;
91+ }
92+
93+ Ok ( Json ( extended_warehouse) )
7194}
7295
7396#[ utoipa:: path(
@@ -85,22 +108,25 @@ pub async fn create_warehouse(
85108 State ( state) : State < AppState > ,
86109 Json ( payload) : Json < warehouse:: CreateWarehousePayload > ,
87110) -> Result < Json < warehouse:: Warehouse > , AppError > {
88- Ok ( Json ( warehouse:: Warehouse {
89- name : "" . to_string ( ) ,
90- storage_profile_id : Default :: default ( ) ,
91- key_prefix : "" . to_string ( ) ,
92- id : Default :: default ( ) ,
93- external_id : Default :: default ( ) ,
94- location : "" . to_string ( ) ,
95- created_at : Default :: default ( ) ,
96- updated_at : Default :: default ( ) ,
97- } ) )
111+ let request: WarehouseCreateRequest = payload. into ( ) ;
112+
113+ state
114+ . control_svc
115+ . get_profile ( request. storage_profile_id )
116+ . await
117+ . map_err ( |e| AppError :: from ( e) ) ?;
118+ let warehouse: WarehouseModel = state
119+ . control_svc
120+ . create_warehouse ( & request)
121+ . await
122+ . map_err ( |e| AppError :: from ( e) ) ?;
123+ Ok ( Json ( warehouse. into ( ) ) )
98124}
99125
100126#[ utoipa:: path(
101127 delete,
102128 path = "/ui/warehouses/{warehouseId}" ,
103- operation_id = "webCeleteWarehouse " ,
129+ operation_id = "webCreteWarehouse " ,
104130 params(
105131 ( "warehouseId" = Uuid , Path , description = "Warehouse ID" )
106132 ) ,
@@ -112,6 +138,11 @@ pub async fn create_warehouse(
112138pub async fn delete_warehouse (
113139 State ( state) : State < AppState > ,
114140 Path ( warehouse_id) : Path < Uuid > ,
115- ) -> Result < ( ) , AppError > {
116- Ok ( ( ) )
141+ ) -> Result < Json < ( ) > , AppError > {
142+ state
143+ . control_svc
144+ . delete_warehouse ( warehouse_id)
145+ . await
146+ . map_err ( |e| AppError :: from ( e) ) ?;
147+ Ok ( Json ( ( ) ) )
117148}
0 commit comments