File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ from fastapi import FastAPI
2+ from uuid import uuid4
3+ from datetime import datetime
4+ from shared .event_schema .ride_events import RideRequestedEvent
5+ from shared .event_bus .kafka_producer import publish_event
6+ from shared .config import settings
7+ from shared .logging_config import setup_logging
8+
9+ app = FastAPI ()
10+ logger = setup_logging ()
11+
12+
13+ @app .post ("/request-ride" )
14+ def request_ride (rider_id : str , pickup_lat : float , pickup_lng : float ,
15+ destination_lat : float , destination_lng : float ):
16+
17+ ride_event = RideRequestedEvent (
18+ ride_id = uuid4 (),
19+ rider_id = rider_id ,
20+ pickup_lat = pickup_lat ,
21+ pickup_lng = pickup_lng ,
22+ destination_lat = destination_lat ,
23+ destination_lng = destination_lng ,
24+ timestamp = datetime .utcnow ()
25+ )
26+
27+ publish_event (settings .KAFKA_TOPIC_RIDE_REQUESTED , ride_event .dict ())
28+ logger .info ("Ride requested" , extra = {"ride_id" : str (ride_event .ride_id )})
29+
30+ return {"status" : "Ride request submitted" }
You can’t perform that action at this time.
0 commit comments