Explorar el Código

get my curriculum backend

dmr1725 hace 4 años
padre
commit
9a97a20858

+ 2
- 2
client/App.js Ver fichero

@@ -32,7 +32,7 @@ export default function App() {
32 32
 
33 33
         try {
34 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 36
             method: 'POST',
37 37
             headers: {
38 38
               'content-type': 'application/json'
@@ -53,7 +53,7 @@ export default function App() {
53 53
           const token = await SecureStore.getItemAsync('token')
54 54
 
55 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 57
             method: 'GET',
58 58
             headers: {
59 59
               'content-type': 'application/json',

+ 3
- 2
client/Screens/AddTakenCourse.js Ver fichero

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

+ 1
- 1
client/Screens/HomeScreen.js Ver fichero

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

+ 2
- 2
client/Screens/SettingScreen.js Ver fichero

@@ -15,7 +15,7 @@ export default function SettingScreen() {
15 15
         let user_id = parseInt(id)
16 16
 
17 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 19
             method: 'GET',
20 20
             headers: {
21 21
                 'content-type': 'application/json',
@@ -43,7 +43,7 @@ export default function SettingScreen() {
43 43
         try {
44 44
             let response = await axios({
45 45
                 method: 'PATCH',
46
-                url: 'http://70eb11ac4839.ngrok.io/api/update_faculty',
46
+                url: 'http://145636c98edd.ngrok.io/api/update_faculty',
47 47
                 headers: {
48 48
                     Authorization: `Token ${token}`
49 49
                 },

BIN
server/CompanionApp/__pycache__/urls.cpython-38.pyc Ver fichero


BIN
server/CompanionApp/__pycache__/views.cpython-38.pyc Ver fichero


+ 3
- 1
server/CompanionApp/urls.py Ver fichero

@@ -16,6 +16,8 @@ urlpatterns = [
16 16
     url('api/find_course', views.findCourse),
17 17
     url(r'^api/add_taken_course$', views.addTakenCourse),
18 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 Ver fichero

@@ -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):