Browse Source

see gpa frontend and backend

dmr1725 4 years ago
parent
commit
bfe0935f7a

+ 9
- 3
client/App.js View File

@@ -1,6 +1,6 @@
1 1
 import { StatusBar } from 'expo-status-bar';
2 2
 import React, {useState} from 'react';
3
-import { StyleSheet, Text, View } from 'react-native';
3
+import { StyleSheet, Text, View, Platform } from 'react-native';
4 4
 import * as Google from "expo-google-app-auth";
5 5
 import {SocialIcon, socialIcon} from 'react-native-elements'
6 6
 import {createDrawerNavigator} from '@react-navigation/drawer'
@@ -15,9 +15,14 @@ import MyCurriculum from './Screens/MyCurriculum'
15 15
 
16 16
 const Drawer = createDrawerNavigator()
17 17
 
18
+console.log(Platform.OS)
19
+
18 20
 const IOS_CLIENT_ID =
19 21
   "116415331974-tf6sehooctplmmn7j0gt831mdf1oqipl.apps.googleusercontent.com";
20 22
 
23
+const ANDROID_CLIENT_ID = 
24
+  "116415331974-72n6g689k4me386dod763gi31vpuh71a.apps.googleusercontent.com";
25
+  // 116415331974-72n6g689k4me386dod763gi31vpuh71a.apps.googleusercontent.com
21 26
 export default function App() {
22 27
   const [hasToken, setHasToken] = useState(false)
23 28
   
@@ -25,6 +30,7 @@ export default function App() {
25 30
     try {
26 31
       const result = await Google.logInAsync({
27 32
         iosClientId: IOS_CLIENT_ID,
33
+        androidClientId: ANDROID_CLIENT_ID,
28 34
         scopes: ["profile", "email"]
29 35
       })
30 36
 
@@ -33,7 +39,7 @@ export default function App() {
33 39
 
34 40
         try {
35 41
           // login user in backend
36
-          let response = await fetch('http://8ad793de242b.ngrok.io/rest-auth/google/', {
42
+          let response = await fetch('http://356b92b5f6b5.ngrok.io/rest-auth/google/', {
37 43
             method: 'POST',
38 44
             headers: {
39 45
               'content-type': 'application/json'
@@ -54,7 +60,7 @@ export default function App() {
54 60
           const token = await SecureStore.getItemAsync('token')
55 61
 
56 62
           // storing our id
57
-          let id = await fetch('http://8ad793de242b.ngrok.io/api/get_user_id', {
63
+          let id = await fetch('http://356b92b5f6b5.ngrok.io/api/get_user_id', {
58 64
             method: 'GET',
59 65
             headers: {
60 66
               'content-type': 'application/json',

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

@@ -51,7 +51,7 @@ const AddTakenCourse = () => {
51 51
 
52 52
       let response = await axios({
53 53
         method: 'POST',
54
-        url: 'http://8ad793de242b.ngrok.io/api/add_taken_course',
54
+        url: 'http://356b92b5f6b5.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://8ad793de242b.ngrok.io/api/find_course?code=${text}`,
88
+          url: `http://356b92b5f6b5.ngrok.io/api/find_course?code=${text}`,
89 89
           headers: {
90 90
             'content-type': 'application/json',
91 91
             Authorization: `Token ${token}`

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

@@ -4,6 +4,8 @@ import * as SecureStore from 'expo-secure-store';
4 4
 import Axios from 'axios';
5 5
 
6 6
 
7
+
8
+
7 9
 function HomeScreen({ navigation }) {
8 10
   const credentials = async ()=>{
9 11
     const token = await SecureStore.getItemAsync('token')
@@ -11,7 +13,7 @@ function HomeScreen({ navigation }) {
11 13
     console.log(token, id)
12 14
 
13 15
     let response = await Axios({
14
-      url: 'http://8ad793de242b.ngrok.io/api/hello',
16
+      url: 'http://356b92b5f6b5.ngrok.io/api/hello',
15 17
       method: 'GET',
16 18
       headers: {
17 19
           Authorization: `Token ${token}`

+ 27
- 3
client/Screens/MyCurriculum.js View File

@@ -7,12 +7,34 @@ import * as SecureStore from 'expo-secure-store';
7 7
 
8 8
 
9 9
 const MyCurriculum = () =>{
10
-    const [year, setYear] = useState(2)
10
+    const [year, setYear] = useState(1)
11
+    const [gpa, setGpa] = useState('')
11 12
     const [semester, setSemester] = useState(1)
12 13
     const [tableHead, setTableHead] = useState(['','Code', 'Title', 'Credits', 'Grade'])
13 14
     const [tableData, setTableData] = useState([])
14 15
     const [tableTitle, setTableTitle] = useState([])
15 16
 
17
+    const getMyGPA = async()=>{
18
+        const token = await SecureStore.getItemAsync('token')
19
+        let id = await SecureStore.getItemAsync('id')
20
+        let user_id = parseInt(id)
21
+
22
+        try {
23
+            let response = await axios('http://356b92b5f6b5.ngrok.io/api/see_gpa', {
24
+                method: 'POST',
25
+                headers: {
26
+                    Authorization: `Token ${token}`
27
+                },
28
+                data: {
29
+                    user_id: user_id
30
+                }
31
+            })
32
+            setGpa(response.data["gpa"][0])
33
+        } catch(e){
34
+            console.log(e)
35
+        }
36
+    }
37
+
16 38
     const getMyCurriculum = async()=>{
17 39
         const token = await SecureStore.getItemAsync('token')
18 40
         let id = await SecureStore.getItemAsync('id')
@@ -21,7 +43,7 @@ const MyCurriculum = () =>{
21 43
         let numbers = []
22 44
 
23 45
         try {
24
-            let response = await axios(`http://8ad793de242b.ngrok.io/api/get_all_courses_by_semester?user_id=${user_id}&year=${year}&semestre=${semester}`, {
46
+            let response = await axios(`http://356b92b5f6b5.ngrok.io/api/get_all_courses_by_semester?user_id=${user_id}&year=${year}&semestre=${semester}`, {
25 47
                 method: 'GET',
26 48
                 headers: {
27 49
                     'content-type': 'application/json',
@@ -51,11 +73,13 @@ const MyCurriculum = () =>{
51 73
     useEffect(()=>{
52 74
         console.log('dimelo')
53 75
         getMyCurriculum()
54
-    }, [year, semester])
76
+        getMyGPA()
77
+    }, [year, semester, gpa])
55 78
 
56 79
 
57 80
     return (
58 81
         <View style={styles.container}>
82
+            <Text>Total GPA: {gpa}</Text>
59 83
             <Table borderStyle={{borderWidth: 2, borderColor: '#0f0f0f'}}>
60 84
                 <Row data={tableHead} flexArr={[0.9, 3.5, 10, 2.3, 2.3]} style={styles.head} textStyle={styles.text}/>
61 85
                 <TableWrapper style={styles.wrapper}>

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

@@ -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://8ad793de242b.ngrok.io/api/get_faculty_name?id=${user_id}`, {
18
+        let response = await axios(`http://356b92b5f6b5.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://8ad793de242b.ngrok.io/api/update_faculty',
46
+                url: 'http://356b92b5f6b5.ngrok.io/api/update_faculty',
47 47
                 headers: {
48 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


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

@@ -18,6 +18,7 @@ urlpatterns = [
18 18
     url(r'^api/get_user_id$', views.getUserId),
19 19
     url('api/get_faculty_name', views.getFacultyUser),
20 20
     url('api/get_all_courses_user_has_taken', views.getAllCoursesUserHasTaken),
21
-    url('api/get_all_courses_by_semester', views.getAllCoursesBySemester)
21
+    url('api/get_all_courses_by_semester', views.getAllCoursesBySemester),
22
+    url('api/see_gpa', views.seeGPA)
22 23
 ]
23 24
 

+ 13
- 2
server/CompanionApp/views.py View File

@@ -1,6 +1,6 @@
1 1
 import sys
2 2
 import json
3
-sys.path.insert(1,'C:/Users/diego/Documents/companion_app_gh/organizar/')
3
+sys.path.insert(1,'C:/Users/diego/Documents/companion_app/organizar/')
4 4
 
5 5
 
6 6
 from organizar import files3
@@ -48,7 +48,7 @@ def insertarTodosLosCursos(request):
48 48
         i = 1
49 49
         for file in files3:
50 50
             check = file['file'].split('.')
51
-            path = "C:/Users/diego/Documents/companion_app_gh/segundo_sem" if check[0][-1] == '2' else "C:/Users/diego/Documents/companion_app_gh/primer_sem"
51
+            path = "C:/Users/diego/Documents/companion_app/segundo_sem" if check[0][-1] == '2' else "C:/Users/diego/Documents/companion_app/primer_sem"
52 52
             with open(path + '/' + file['file']) as f:
53 53
                 data = json.load(f)
54 54
                 fac_id = file['num']
@@ -242,6 +242,17 @@ def getAllCoursesBySemester(request):
242 242
             
243 243
         return JsonResponse({'list': courses}, status=status.HTTP_200_OK)
244 244
 
245
+@api_view(['POST',])
246
+def seeGPA(request):
247
+    if request.method == 'POST':
248
+        user_id = int(request.data['user_id'])
249
+        cursor = connection.cursor()
250
+        cursor.execute(f'SELECT gpa from "CompanionApp_user" where id={user_id}')
251
+        GPA = cursor.fetchone()
252
+        return JsonResponse({'gpa': GPA}, status = status.HTTP_200_OK)
253
+
254
+
255
+
245 256
 
246 257
 
247 258
 @api_view(['GET', 'POST'])