|
@@ -209,6 +209,40 @@ def getFacultyUser(request):
|
209
|
209
|
facultyName = cursor.fetchone()
|
210
|
210
|
return JsonResponse({'FacultyName': facultyName}, status=status.HTTP_200_OK)
|
211
|
211
|
|
|
212
|
+@api_view(['GET'])
|
|
213
|
+def getAllCoursesUserHasTaken(request):
|
|
214
|
+ if request.method == 'GET':
|
|
215
|
+ user_id = int(request.query_params['user_id'])
|
|
216
|
+ cursor = connection.cursor()
|
|
217
|
+ cursor.execute(f'SELECT c.name, c.code, c.creditos, m.user_id_id, m.year, m.semestre, m.grade FROM "CompanionApp_curso" c INNER JOIN "CompanionApp_matricula" m ON (c.id = m.course_id_id) where m.user_id_id = {user_id} and m.grade <> \'N%\' order by m.year ASC, m.semestre ASC')
|
|
218
|
+ fetchCourses = cursor.fetchall()
|
|
219
|
+ courses = []
|
|
220
|
+ # convert courses to an array of objects
|
|
221
|
+ for i in range(0, len(fetchCourses)):
|
|
222
|
+ dic = {'name': fetchCourses[i][0], 'code': fetchCourses[i][1], 'creditos': fetchCourses[i][2], 'year': fetchCourses[i][4], 'semestre': fetchCourses[i][5], 'grade': fetchCourses[i][6]}
|
|
223
|
+ courses.append(dic)
|
|
224
|
+
|
|
225
|
+ return JsonResponse({'list': courses}, status=status.HTTP_200_OK)
|
|
226
|
+
|
|
227
|
+@api_view(['GET'])
|
|
228
|
+def getAllCoursesBySemester(request):
|
|
229
|
+ if request.method == 'GET':
|
|
230
|
+ user_id = int(request.query_params['user_id'])
|
|
231
|
+ year = int(request.query_params['year'])
|
|
232
|
+ semestre = int(request.query_params['semestre'])
|
|
233
|
+ cursor = connection.cursor()
|
|
234
|
+ cursor.execute(f'SELECT c.name, c.code, c.creditos, m.user_id_id, m.year, m.semestre, m.grade FROM "CompanionApp_curso" c INNER JOIN "CompanionApp_matricula" m ON (c.id = m.course_id_id) where m.user_id_id = {user_id} and m.year = {year} and m.semestre = {semestre} and m.grade <> \'N%\' ')
|
|
235
|
+ fetchCourses = cursor.fetchall()
|
|
236
|
+ courses = []
|
|
237
|
+
|
|
238
|
+ # convert courses to an array of objects
|
|
239
|
+ for i in range(0, len(fetchCourses)):
|
|
240
|
+ dic = {'name': fetchCourses[i][0], 'code': fetchCourses[i][1], 'creditos': fetchCourses[i][2], 'year': fetchCourses[i][4], 'semestre': fetchCourses[i][5], 'grade': fetchCourses[i][6]}
|
|
241
|
+ courses.append(dic)
|
|
242
|
+
|
|
243
|
+ return JsonResponse({'list': courses}, status=status.HTTP_200_OK)
|
|
244
|
+
|
|
245
|
+
|
212
|
246
|
|
213
|
247
|
@api_view(['GET', 'POST'])
|
214
|
248
|
def hello_world(request):
|