Skip to content

Commit c97c55a

Browse files
committed
added all apis to redux
1 parent 34e2ff0 commit c97c55a

File tree

8 files changed

+165
-8
lines changed

8 files changed

+165
-8
lines changed

VITask Android/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,7 @@ buck-out/
6262
check.js
6363
timetableapi.json
6464
classesapi.json
65-
authenticate.json
65+
authenticate.json
66+
acadhistory.json
67+
marks.json
68+
moodleapi.json

VITask Android/actions/actions.js

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ import {
1515
FETCH_MARKS_REQUEST,
1616
FETCH_MARKS_SUCCESS,
1717
FETCH_MARKS_ERROR,
18+
19+
FETCH_MOODLE_ASSIGNMENTS_REQUEST,
20+
FETCH_MOODLE_ASSIGNMENTS_SUCCESS,
21+
FETCH_MOODLE_ASSIGNMENTS_ERROR,
22+
FETCH_MOODLE_ASSIGNMENTS_SYNC,
23+
24+
FETCH_ACADHISTORY_REQUEST,
25+
FETCH_ACADHISTORY_SUCCESS,
26+
FETCH_ACADHISTORY_ERROR,
27+
1828
} from './types'
1929

2030

@@ -93,7 +103,47 @@ import {
93103

94104
const fetchMarksError = (err)=>{
95105
return{
96-
type : FETCH_MARKS_SUCCESS,
106+
type : FETCH_MARKS_ERROR,
107+
error : err
108+
}
109+
}
110+
111+
const fetchMoodleAssignmentsRequest = ()=>{
112+
return{
113+
type : FETCH_MOODLE_ASSIGNMENTS_REQUEST
114+
}
115+
}
116+
117+
const fetchMoodleAssignmentsSuccess = (assignments) =>{
118+
return{
119+
type : FETCH_MOODLE_ASSIGNMENTS_SUCCESS,
120+
data : assignments
121+
}
122+
}
123+
124+
const fetchMoodleAssignmentsError = (err) =>{
125+
return{
126+
type : FETCH_MOODLE_ASSIGNMENTS_ERROR,
127+
error : err
128+
}
129+
}
130+
131+
const fetchAcadHistoryRequest = () =>{
132+
return{
133+
type : FETCH_ACADHISTORY_REQUEST
134+
}
135+
}
136+
137+
const fetchAcadHistorySuccess = (acadHistory) =>{
138+
return{
139+
type : FETCH_ACADHISTORY_SUCCESS,
140+
data : acadHistory
141+
}
142+
}
143+
144+
const fetchAcadHistoryError = (err) =>{
145+
return{
146+
type : FETCH_ATTENDANCE_ERROR,
97147
error : err
98148
}
99149
}
@@ -108,6 +158,8 @@ import {
108158
const ORIGINAL_ATTENDANCE = `https://vitask.me/classesapi?token={state.reducer.userInfo.APItoken}`
109159
const ORIGINAL_TIMETABLE = `https://vitask.me/timetableapi?token={state.reducer.userInfo.APItoken}`
110160
const ORIGINAL_MARKS = 'https://vitask.me/marksapi?token={state.reducer.userInfo.APItoken}'
161+
const ORIGINAL_MOODLE = 'https://vitask.me/moodleapi?token={state.reducer.userInfo.APItoken}'
162+
const ORIGINAL_ACADEMIC_HISTORY = "https://vitask.me/acadhistoryapi?token={state.reducer.userInfo.APItoken}"
111163

112164
export const loginVTOP =(username, password) => {
113165
return dispatch=>{
@@ -171,4 +223,34 @@ import {
171223
})
172224
.catch(err=> dispatch(fetchMarksError(err)))
173225
}
226+
}
227+
228+
export const fetchMoodleAssignments = ()=>{
229+
return (dispatch, getState)=>{
230+
const state = getState()
231+
dispatch(fetchMoodleAssignmentsRequest)
232+
fetch('https://jsonplaceholder.typicode.com/posts')
233+
.then(res =>{
234+
res = require('../moodleapi.json')
235+
return res
236+
}).then(res =>{
237+
dispatch(fetchMoodleAssignmentsSuccess(res))
238+
})
239+
.catch(err => dispatch(fetchMoodleAssignmentsError(err)))
240+
}
241+
}
242+
243+
export const fetchAcadHistory = () =>{
244+
return(dispatch,getState) =>{
245+
const state = getState()
246+
dispatch(fetchAcadHistoryRequest)
247+
fetch('https://jsonplaceholder.typicode.com/posts')
248+
.then(res =>{
249+
res = require('../acadhistory.json')
250+
return res
251+
}).then(res =>{
252+
dispatch(fetchAcadHistorySuccess(res))
253+
})
254+
.catch(err =>{dispatch((fetchAcadHistoryError(err)))})
255+
}
174256
}

VITask Android/actions/types.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ export const FETCH_MARKS_SUCCESS = "FETCH_MARKS_SUCCESS"
2121
export const FETCH_MARKS_ERROR = "FETCH_MARKS_ERROR"
2222
export const SYNC_MARKS = "SYNC_MARKS"
2323

24+
export const FETCH_MOODLE_ASSIGNMENTS_REQUEST = "FETCH_MOODLE_ASSIGNMENTS"
25+
export const FETCH_MOODLE_ASSIGNMENTS_SUCCESS = "FETCH_MOODLE_ASSIGNMENTS_SUCCESS"
26+
export const FETCH_MOODLE_ASSIGNMENTS_ERROR = "FETCH_MOODLE_ASSIGNMENTS_ERROR"
27+
export const FETCH_MOODLE_ASSIGNMENTS_SYNC = "FETCH_MOODLE_ASSIGNMENTS_SYNC"
28+
29+
export const FETCH_ACADHISTORY_REQUEST = "FETCH_ACADHISTORY_REQUEST"
30+
export const FETCH_ACADHISTORY_SUCCESS = "FETCH_ACADHISTORY_SUCCESS"
31+
export const FETCH_ACADHISTORY_ERROR = "FETCH_ACADHISTORY_SUCCESS"
32+
2433

2534
// These are only for using developement purpose to save api calls, instead api calls are done to dummy server
2635
export const DEV_LOAD_ATTENDANCE = "DEV_LOAD_ATTENDANCE"
Binary file not shown.

VITask Android/reducer/reducer.js

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ import {
1111
FETCH_TIMETABLE_SUCCESS,
1212
FETCH_TIMETABLE_ERROR,
1313

14-
REFORMAT_DATA,
1514
FETCH_MARKS_SUCCESS,
1615
FETCH_MARKS_REQUEST,
17-
FETCH_MARKS_ERROR
16+
FETCH_MARKS_ERROR,
17+
18+
FETCH_MOODLE_ASSIGNMENTS_REQUEST,
19+
FETCH_MOODLE_ASSIGNMENTS_SUCCESS,
20+
FETCH_MOODLE_ASSIGNMENTS_ERROR,
21+
FETCH_MOODLE_ASSIGNMENTS_SYNC,
22+
23+
REFORMAT_DATA,
24+
FETCH_ACADHISTORY_REQUEST,
25+
FETCH_ACADHISTORY_SUCCESS,
1826
} from '../actions/types'
1927
import { createStore, applyMiddleware, combineReducers } from "redux";
2028
import thunkMiddleware from 'redux-thunk'
@@ -167,14 +175,14 @@ const reducer = (state = initialState, action)=>{
167175
case FETCH_TIMETABLE_ERROR:
168176
return {
169177
...state,
170-
status: "ERROR",
178+
status : "ERROR",
171179
error : action.error
172180
}
173181

174182
case FETCH_MARKS_REQUEST:
175183
return{
176184
...state,
177-
status:"REQUEST_MARKS",
185+
status : "REQUEST_MARKS",
178186
error : ""
179187
}
180188

@@ -191,6 +199,48 @@ const reducer = (state = initialState, action)=>{
191199
status : "ERROR",
192200
error : action.error
193201
}
202+
203+
case FETCH_MOODLE_ASSIGNMENTS_REQUEST:
204+
return{
205+
...state,
206+
status : "REQUEST_MOODLE_ASSIGNMENTS",
207+
error : ""
208+
}
209+
210+
case FETCH_MOODLE_ASSIGNMENTS_SUCCESS:
211+
return{
212+
...state,
213+
status : "MOODLE_ASSIGNMENTS_COMPLETE",
214+
assignments : action.data
215+
}
216+
217+
case FETCH_MOODLE_ASSIGNMENTS_ERROR:
218+
return{
219+
...state,
220+
staus : "ERROR",
221+
error : action.error
222+
}
223+
224+
case FETCH_ACADHISTORY_REQUEST:
225+
return{
226+
...state,
227+
status : "REQUEST_ACADHISTORY",
228+
error : ""
229+
}
230+
231+
case FETCH_ACADHISTORY_SUCCESS:
232+
return{
233+
...state,
234+
status : "ACADHISTORY_COMPLETE",
235+
acadhistory : action.data
236+
}
237+
238+
case FETCH_ATTENDANCE_ERROR:
239+
return{
240+
...state,
241+
status : "ERROR",
242+
error : action.error
243+
}
194244

195245
case REFORMAT_DATA:
196246
// This will be called only once and reformate the api

VITask Android/screens/DashboardScreen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class DashboardScreen extends Component {
1919

2020
componentDidMount(){
2121
console.log(Object.keys(this.props))
22-
console.log(this.props.state.marks)
22+
console.log(this.props.state.acadhistory)
2323
let totalClass = 0
2424
let totalLab = 0
2525
for(classes of this.state.timetable){

VITask Android/screens/LoadingScreen.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {
88
fetchAttendance,
99
fetchTimetable,
1010
reformatData,
11-
fetchMarks
11+
fetchMarks,
12+
fetchMoodleAssignments,
13+
fetchAcadHistory
1214
} from '../actions/actions'
1315

1416
class LoadingScreen extends Component {
@@ -70,6 +72,8 @@ class LoadingScreen extends Component {
7072
// Timetable complete, call the attendance api
7173
this.props.getAttendance()
7274
this.props.getMarks()
75+
this.props.getMoodle()
76+
this.props.getAcadHistory()
7377
this.setState({
7478
text:"And before we forget...",
7579
process: "Getting your Attendance"
@@ -185,6 +189,12 @@ const mapDispatchToProps = (dispatch) => {
185189
getMarks:()=>{
186190
dispatch(fetchMarks())
187191
},
192+
getMoodle:()=>{
193+
dispatch(fetchMoodleAssignments())
194+
},
195+
getAcadHistory:()=>{
196+
dispatch(fetchAcadHistory())
197+
},
188198
reformat: ()=>{
189199
dispatch(reformatData())
190200
}

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)