@@ -102,9 +102,48 @@ async def get_user_myQuestion(user_id: str, npages: int, itemsPerPage: int = -1)
102
102
for i in range (0 , npages ):
103
103
if len (q_list ) < i * itemsPerPage :
104
104
pages [f"page_#{ i } " ] = []
105
- elif len (q_list ) < itemsPerPage + ( i * itemsPerPage ):
106
- pages [f"page_#{ i } " ] = q_list [i * itemsPerPage :len (q_list )- 1 ]
105
+ elif len (q_list ) < itemsPerPage + ( i * itemsPerPage ):
106
+ pages [f"page_#{ i } " ] = q_list [i * itemsPerPage :len (q_list ) - 1 ]
107
107
else :
108
108
pages [f"page_#{ i } " ] = q_list [i * itemsPerPage :itemsPerPage + (i * itemsPerPage )]
109
109
user_questions ["my_Questions" ] = pages
110
110
return JSONResponse (user_questions )
111
+
112
+
113
+ @app .get ("/v1/searchCourses" )
114
+ async def search_courses (query : str , limit : int = 10 ):
115
+ result = db [DbName .COURSE .value ].find ({"name" : {'$regex' : f'(?i){ query } ' }}, {'_id' : 0 })
116
+ result = await result .to_list (limit )
117
+ if result :
118
+ return JSONResponse (status_code = status .HTTP_200_OK , content = result )
119
+ result = db [DbName .QUESTION .value ].find ({"content.name.text" : {'$regex' : f'(?i){ query } ' }},
120
+ {'_id' : 0 , 'quiz_ref' : 0 })
121
+ result = await result .to_list (limit )
122
+ if result :
123
+ return JSONResponse (status_code = status .HTTP_200_OK , content = result )
124
+ return JSONResponse (status_code = status .HTTP_404_NOT_FOUND ,
125
+ content = f"No course found" )
126
+
127
+
128
+ @app .get ("/v1/searchQuestion" )
129
+ async def search_question (query : str , course_id : str , limit : int = 10 ):
130
+ result = db [DbName .QUESTION .value ].find (
131
+ {"content.name.text" : {'$regex' : f'(?i){ query } ' }, "course.id" : course_id }, {'_id' : 0 , 'quiz_ref' : 0 })
132
+ result = await result .to_list (limit )
133
+ if result :
134
+ return JSONResponse (status_code = status .HTTP_200_OK , content = result )
135
+
136
+ result = db [DbName .QUESTION .value ].find (
137
+ {"tags" : {'$regex' : f'(?i){ query } ' }, "course.id" : course_id }, {'_id' : 0 , 'quiz_ref' : 0 })
138
+ result = await result .to_list (limit )
139
+ if result :
140
+ return JSONResponse (status_code = status .HTTP_200_OK , content = result )
141
+
142
+ result = db [DbName .QUESTION .value ].find (
143
+ {"content.questiontext.text" : {'$regex' : f'(?i){ query } ' }, "course.id" : course_id }, {'_id' : 0 , 'quiz_ref' : 0 })
144
+ result = await result .to_list (limit )
145
+ if result :
146
+ return JSONResponse (status_code = status .HTTP_200_OK , content = result )
147
+
148
+ return JSONResponse (status_code = status .HTTP_404_NOT_FOUND ,
149
+ content = f"No question found" )
0 commit comments