Initial Codebase
This is your codebase, before Qrambo was integrated.
You are using FAST-API to build your API.
main.py
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from datetime import datetime
from typing import Optional
from models import Journey, Scooter, Ticket
from request_models import OffboardRequest
app = FastAPI()
@app.post("/offboard-scooter")
async def offboard_scooter(request: OffboardRequest):
try: # Get journey and validate it belongs to the user and scooter
journey = await Journey.get(
id=request.journey_id,
user_id=request.user_id,
scooter_id=request.scooter_id,
status=Journey.STARTED
)
if not journey:
raise HTTPException(status_code=404, detail="Journey not found")
# Update journey status
journey.status = Journey.COMPLETED_REVIEWING
journey.end_time = datetime.now()
await journey.save()
# Mark scooter as available
scooter = journey.scooter
scooter.is_available = True
await scooter.save()
###########################
# TODO: Create a Ticket entity for the user if the scooter is not parked properly
# according to the offboarding photo
###########################
return {
'status': 'success',
'message': 'Scooter offboarded application got successfully',
'journey_id': request.journey_id
}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
Last updated on