Nattyboi commited on
Commit
0c202c6
·
1 Parent(s): 357f5eb

updated get levels

Browse files
Files changed (3) hide show
  1. README.md +0 -1
  2. gamification/levelLogic.py +19 -11
  3. gamification/routes.py +11 -0
README.md CHANGED
@@ -8,4 +8,3 @@ pinned: false
8
  license: apache-2.0
9
  ---
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
8
  license: apache-2.0
9
  ---
10
 
 
gamification/levelLogic.py CHANGED
@@ -36,7 +36,8 @@ def create_level_func(document:UserLevel,)->bool:
36
 
37
 
38
 
39
- def get_all_levels_func() -> List[UserLevel]:
 
40
  # MongoDB URI and configuration
41
  db_uri = MONGO_URI
42
  db_name = "crayonics"
@@ -44,16 +45,23 @@ def get_all_levels_func() -> List[UserLevel]:
44
  client = MongoClient(db_uri)
45
  db = client[db_name]
46
  collection = db[collection_name]
47
-
48
- # Fetch all documents from the collection
49
- levels_cursor = collection.find() # This returns a cursor to the documents
50
-
51
- # Convert the cursor to a list of UserLevel objects
52
- levels = [UserLevel(**level) for level in levels_cursor]
53
- returning_levels= [returns for returns in levels if (returns.levelName!="default" and returns.careerPath!="default")]
54
-
55
- return returning_levels
56
-
 
 
 
 
 
 
 
57
 
58
 
59
  def delete_level_func(level_id,)->bool:
 
36
 
37
 
38
 
39
+ def get_all_levels_func(admin=False,career=None ) -> List[UserLevel]:
40
+
41
  # MongoDB URI and configuration
42
  db_uri = MONGO_URI
43
  db_name = "crayonics"
 
45
  client = MongoClient(db_uri)
46
  db = client[db_name]
47
  collection = db[collection_name]
48
+ levels_cursor = collection.find()
49
+ if admin == False: # case where the person making a request is not an admin
50
+ if career == None:
51
+ # Convert the cursor to a list of UserLevel objects
52
+ levels = [UserLevel(**level) for level in levels_cursor]
53
+ returning_levels= [returns for returns in levels ]
54
+ return returning_levels
55
+ else:
56
+ levels = [UserLevel(**level) for level in levels_cursor]
57
+ returning_levels= [returns for returns in levels if (returns.careerPath==career)]
58
+ return returning_levels
59
+ else: # case where the person making a request is an admin
60
+ levels = [UserLevel(**level) for level in levels_cursor]
61
+ returning_levels= [returns for returns in levels if (returns.levelName!="default" and returns.careerPath!="default")]
62
+ return returning_levels
63
+
64
+
65
 
66
 
67
  def delete_level_func(level_id,)->bool:
gamification/routes.py CHANGED
@@ -106,6 +106,17 @@ def get_level_details_and_information()->List[UserLevel]:
106
  levels= get_all_levels_func()
107
  return levels
108
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
  @gamification.patch("/edit-level",tags=["admin"])
111
  def edit_level(level_obj:EditableUserLevel):
 
106
  levels= get_all_levels_func()
107
  return levels
108
 
109
+ @gamification.get("/admin/get-level",tags=["admin","user"])
110
+ def get_level_details_and_information()->List[UserLevel]:
111
+ levels= get_all_levels_func(admin=True)
112
+ return levels
113
+
114
+ @gamification.get("/get-level/{careerPath}",tags=["user"])
115
+ def get_level_details_and_information(careerPath:str)->List[UserLevel]:
116
+ levels= get_all_levels_func(career=careerPath)
117
+ return levels
118
+
119
+
120
 
121
  @gamification.patch("/edit-level",tags=["admin"])
122
  def edit_level(level_obj:EditableUserLevel):