File size: 2,138 Bytes
4f7effb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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}")