Browse Source

get my curriculum backend

dmr1725 4 years ago
parent
commit
9a97a20858

+ 2
- 2
client/App.js View File

32
 
32
 
33
         try {
33
         try {
34
           // login user in backend
34
           // login user in backend
35
-          let response = await fetch('http://70eb11ac4839.ngrok.io/rest-auth/google/', {
35
+          let response = await fetch('http://145636c98edd.ngrok.io/rest-auth/google/', {
36
             method: 'POST',
36
             method: 'POST',
37
             headers: {
37
             headers: {
38
               'content-type': 'application/json'
38
               'content-type': 'application/json'
53
           const token = await SecureStore.getItemAsync('token')
53
           const token = await SecureStore.getItemAsync('token')
54
 
54
 
55
           // storing our id
55
           // storing our id
56
-          let id = await fetch('http://70eb11ac4839.ngrok.io/api/get_user_id', {
56
+          let id = await fetch('http://145636c98edd.ngrok.io/api/get_user_id', {
57
             method: 'GET',
57
             method: 'GET',
58
             headers: {
58
             headers: {
59
               'content-type': 'application/json',
59
               'content-type': 'application/json',

+ 3
- 2
client/Screens/AddTakenCourse.js View File

51
 
51
 
52
       let response = await axios({
52
       let response = await axios({
53
         method: 'POST',
53
         method: 'POST',
54
-        url: 'http://70eb11ac4839.ngrok.io/api/add_taken_course',
54
+        url: 'http://145636c98edd.ngrok.io/api/add_taken_course',
55
         headers: {
55
         headers: {
56
           'content-type': 'application/json',
56
           'content-type': 'application/json',
57
           Authorization: `Token ${token}`
57
           Authorization: `Token ${token}`
85
       const token = await SecureStore.getItemAsync('token')
85
       const token = await SecureStore.getItemAsync('token')
86
       const response = await axios({
86
       const response = await axios({
87
           method: 'GET',
87
           method: 'GET',
88
-          url: `http://70eb11ac4839.ngrok.io/api/find_course?code=${text}`,
88
+          url: `http://145636c98edd.ngrok.io/api/find_course?code=${text}`,
89
           headers: {
89
           headers: {
90
             'content-type': 'application/json',
90
             'content-type': 'application/json',
91
             Authorization: `Token ${token}`
91
             Authorization: `Token ${token}`
172
                     onValueChange={(itemValue, itemIndex) => setSemester(itemValue) }>
172
                     onValueChange={(itemValue, itemIndex) => setSemester(itemValue) }>
173
                     <Picker.Item label="1" value="1" />
173
                     <Picker.Item label="1" value="1" />
174
                     <Picker.Item label="2" value="2" />
174
                     <Picker.Item label="2" value="2" />
175
+                    <Picker.Item label="3" value="3" />
175
                 </Picker>
176
                 </Picker>
176
             </View>
177
             </View>
177
            <View style={{flex: 1, justifyContent: 'center'}}>
178
            <View style={{flex: 1, justifyContent: 'center'}}>

+ 1
- 1
client/Screens/HomeScreen.js View File

11
     console.log(token, id)
11
     console.log(token, id)
12
 
12
 
13
     let response = await Axios({
13
     let response = await Axios({
14
-      url: 'http://70eb11ac4839.ngrok.io/api/hello',
14
+      url: 'http://145636c98edd.ngrok.io/api/hello',
15
       method: 'GET',
15
       method: 'GET',
16
       headers: {
16
       headers: {
17
           Authorization: `Token ${token}`
17
           Authorization: `Token ${token}`

+ 2
- 2
client/Screens/SettingScreen.js View File

15
         let user_id = parseInt(id)
15
         let user_id = parseInt(id)
16
 
16
 
17
        try {
17
        try {
18
-        let response = await axios(`http://70eb11ac4839.ngrok.io/api/get_faculty_name?id=${user_id}`, {
18
+        let response = await axios(`http://145636c98edd.ngrok.io/api/get_faculty_name?id=${user_id}`, {
19
             method: 'GET',
19
             method: 'GET',
20
             headers: {
20
             headers: {
21
                 'content-type': 'application/json',
21
                 'content-type': 'application/json',
43
         try {
43
         try {
44
             let response = await axios({
44
             let response = await axios({
45
                 method: 'PATCH',
45
                 method: 'PATCH',
46
-                url: 'http://70eb11ac4839.ngrok.io/api/update_faculty',
46
+                url: 'http://145636c98edd.ngrok.io/api/update_faculty',
47
                 headers: {
47
                 headers: {
48
                     Authorization: `Token ${token}`
48
                     Authorization: `Token ${token}`
49
                 },
49
                 },

BIN
server/CompanionApp/__pycache__/urls.cpython-38.pyc View File


BIN
server/CompanionApp/__pycache__/views.cpython-38.pyc View File


+ 3
- 1
server/CompanionApp/urls.py View File

16
     url('api/find_course', views.findCourse),
16
     url('api/find_course', views.findCourse),
17
     url(r'^api/add_taken_course$', views.addTakenCourse),
17
     url(r'^api/add_taken_course$', views.addTakenCourse),
18
     url(r'^api/get_user_id$', views.getUserId),
18
     url(r'^api/get_user_id$', views.getUserId),
19
-    url('api/get_faculty_name', views.getFacultyUser)
19
+    url('api/get_faculty_name', views.getFacultyUser),
20
+    url('api/get_all_courses_user_has_taken', views.getAllCoursesUserHasTaken),
21
+    url('api/get_all_courses_by_semester', views.getAllCoursesBySemester)
20
 ]
22
 ]
21
 
23
 

+ 34
- 0
server/CompanionApp/views.py View File

209
         facultyName = cursor.fetchone()
209
         facultyName = cursor.fetchone()
210
         return JsonResponse({'FacultyName': facultyName}, status=status.HTTP_200_OK)
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
 @api_view(['GET', 'POST'])
247
 @api_view(['GET', 'POST'])
214
 def hello_world(request):
248
 def hello_world(request):