Nattyboi's picture
added some routes
4f7effb
raw
history blame
2.14 kB
from fastapi import FastAPI,HTTPException
from gamification.objects import *
from gamification.logic import *
from pydantic import BaseModel
from typing import Optional
from bson import ObjectId
class EditableUserLevel(BaseModel):
levelId : str
maxPoints : Optional[int]= None
minPoints : Optional[int]= None
levelName : Optional[str]= None
careerPath : Optional[str]= None
levelNumber : Optional[int]= None
# To convert MongoDB ObjectId to string, if needed
class Config:
json_encoders = {
ObjectId: str
}
gamification = FastAPI()
@gamification.post("/create-feedback",tags=["user"])
def create_feedback(user_feedback:UserFeedback)->bool:
try:
result = create_feedback_func(user_feedback)
return {"message":result}
except Exception as e:
raise HTTPException(status_code=500,detail=f"{e}")
@gamification.post("/get-leaderboard",tags=["user"])
def get_leaderboard_details():
pass
@gamification.get("/get-feedback",tags=["admin"])
def get_feedback()->List[UserFeedback]:
feedbacks = get_all_feedback_func()
return feedbacks
@gamification.post("/create-level",tags=["admin"])
def create_level(level_obj:UserLevel)->bool:
result = create_level_func(document=level_obj)
return {"message":result}
@gamification.get("/get-level",tags=["admin","user"])
def get_level_details_and_information()->List[UserLevel]:
levels= get_all_levels_func()
return levels
@gamification.patch("/edit-level",tags=["admin"])
def edit_level(level_obj:EditableUserLevel)->int:
result = edit_level_func(level_id=level_obj.levelId,levelName=level_obj.levelName,careerPath=level_obj.careerPath,minPoints=level_obj.minPoints,maxPoints=level_obj.maxPoints,levelNumber=level_obj.levelNumber)
return {"message":result}
@gamification.delete("/delete-level/{levelId}",tags=["admin"])
def delete_level(levelId)->bool:
try:
result = delete_level_func(level_id=levelId)
return {"message":result}
except Exception as e:
raise HTTPException(status_code=500,detail=f"{e}")