@@ -41,6 +41,7 @@ pub struct CreateHospitalRequest {
4141 pub has_blood_bank : bool ,
4242 pub accepting_donors : bool ,
4343 pub donating_operating_hours : Option < String > ,
44+ pub blood_inventory : Option < Vec < BloodInventoryUpdate > > ,
4445}
4546
4647#[ derive( Debug , Deserialize , ToSchema ) ]
@@ -145,7 +146,7 @@ pub async fn create_hospital(
145146 accepting_donors : hospital. accepting_donors ,
146147 donating_operating_hours : hospital. donating_operating_hours ,
147148 created_at : hospital. created_at ,
148- blood_inventory : vec ! [ ] , // New hospital has no inventory yet
149+ blood_inventory : hospitals :: service :: get_hospital_inventory ( & mut conn , hospital. id ) ? ,
149150 } ;
150151
151152 Ok ( ApiResponse :: success_with_message (
@@ -447,19 +448,44 @@ pub async fn upload_accreditation_doc(
447448 get,
448449 path = "/api/hospitals" ,
449450 responses(
450- ( status = 200 , body = ApiResponse <Vec <Hospital >>) ,
451+ ( status = 200 , body = ApiResponse <Vec <HospitalResponse >>) ,
451452 ( status = 500 )
452453 ) ,
453454 tag = "hospitals"
454455) ]
455456pub async fn get_hospitals (
456457 State ( state) : State < AppState > ,
457- ) -> Result < ApiResponse < Vec < Hospital > > , AppError > {
458+ ) -> Result < ApiResponse < Vec < HospitalResponse > > , AppError > {
458459 let mut conn = state. pool . get ( ) ?;
459460 let hospitals = hospitals:: service:: get_hospitals ( & mut conn) ?;
461+
462+ let mut response = Vec :: new ( ) ;
463+ for hospital in hospitals {
464+ let inventory = hospitals:: service:: get_hospital_inventory ( & mut conn, hospital. id ) ?;
465+ response. push ( HospitalResponse {
466+ id : hospital. id ,
467+ name : hospital. name ,
468+ hospital_type : hospital. hospital_type ,
469+ address : hospital. address ,
470+ city : hospital. city ,
471+ country : hospital. country ,
472+ primary_phone : hospital. primary_phone ,
473+ emergency_phone : hospital. emergency_phone ,
474+ email : hospital. email ,
475+ license_number : hospital. license_number ,
476+ accreditation_doc_url : hospital. accreditation_doc_url ,
477+ license_status : hospital. license_status ,
478+ has_blood_bank : hospital. has_blood_bank ,
479+ accepting_donors : hospital. accepting_donors ,
480+ donating_operating_hours : hospital. donating_operating_hours ,
481+ created_at : hospital. created_at ,
482+ blood_inventory : inventory,
483+ } ) ;
484+ }
485+
460486 Ok ( ApiResponse :: success_with_message (
461487 "Hospitals retrieved successfully" ,
462- hospitals ,
488+ response ,
463489 ) )
464490}
465491
0 commit comments