19 lines
717 B
Python
19 lines
717 B
Python
from fastapi import FastAPI, HTTPException, Response
|
|
from utils.feed_generator import generate_feed_of_user, USER_NOT_FOUND, CANNOT_ACCESS_INSTANCE, INVALID_HANDLE
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.get("/feed/{user_handle}")
|
|
def get_feed_of_user(user_handle: str):
|
|
feed = generate_feed_of_user(user_handle)
|
|
|
|
if feed == USER_NOT_FOUND:
|
|
return HTTPException(status_code=404, detail="The user cannot be found.")
|
|
if feed == CANNOT_ACCESS_INSTANCE:
|
|
return HTTPException(status_code=400, detail="Cannot access the instance.")
|
|
if feed == INVALID_HANDLE:
|
|
return HTTPException(status_code=400, detail="The handle is invalid.")
|
|
|
|
return Response(content=feed, media_type="application/xml")
|