diff --git a/fittrackee_api/fittrackee_api/users/auth.py b/fittrackee_api/fittrackee_api/users/auth.py
index 4418036c..6f6faaf3 100644
--- a/fittrackee_api/fittrackee_api/users/auth.py
+++ b/fittrackee_api/fittrackee_api/users/auth.py
@@ -287,10 +287,9 @@ def del_picture(user_id):
db.session.commit()
response_object = {
- 'status': 'success',
- 'message': 'User picture delete.'
+ 'status': 'no content'
}
- return jsonify(response_object), 200
+ return jsonify(response_object), 204
except (exc.IntegrityError, ValueError) as e:
db.session.rollback()
diff --git a/fittrackee_client/src/actions/activities.js b/fittrackee_client/src/actions/activities.js
index 0cc90cb9..a166891b 100644
--- a/fittrackee_client/src/actions/activities.js
+++ b/fittrackee_client/src/actions/activities.js
@@ -1,7 +1,6 @@
import { parse } from 'date-fns'
import FitTrackeeGenericApi from '../fitTrackeeApi'
-import FitTrackeeApi from '../fitTrackeeApi/activities'
import { history } from '../index'
import { formatChartData } from '../utils'
import { setError, setLoading } from './index'
@@ -27,8 +26,8 @@ export const setChartData = chartData => ({
chartData,
})
-export const addActivity = form => dispatch => FitTrackeeApi
- .addActivity(form)
+export const addActivity = form => dispatch => FitTrackeeGenericApi
+ .addDataWithFile('activities', form)
.then(ret => {
if (ret.status === 'created') {
if (ret.data.activities.length === 0) {
@@ -48,8 +47,8 @@ export const addActivity = form => dispatch => FitTrackeeApi
.catch(error => dispatch(setError(`activities: ${error}`)))
-export const addActivityWithoutGpx = form => dispatch => FitTrackeeApi
- .addActivityWithoutGpx(form)
+export const addActivityWithoutGpx = form => dispatch => FitTrackeeGenericApi
+ .addData('activities/no_gpx', form)
.then(ret => {
if (ret.status === 'created') {
dispatch(loadProfile())
@@ -63,8 +62,8 @@ export const addActivityWithoutGpx = form => dispatch => FitTrackeeApi
export const getActivityGpx = activityId => dispatch => {
if (activityId) {
- return FitTrackeeApi
- .getActivityGpx(activityId)
+ return FitTrackeeGenericApi
+ .getData(`activities/${activityId}/gpx`)
.then(ret => {
if (ret.status === 'success') {
dispatch(setGpx(ret.data.gpx))
@@ -80,8 +79,8 @@ export const getActivityGpx = activityId => dispatch => {
export const getActivityChartData = activityId => dispatch => {
if (activityId) {
- return FitTrackeeApi
- .getActivityChartData(activityId)
+ return FitTrackeeGenericApi
+ .getData(`activities/${activityId}/chart_data`)
.then(ret => {
if (ret.status === 'success') {
dispatch(setChartData(formatChartData(ret.data.chart_data)))
diff --git a/fittrackee_client/src/actions/stats.js b/fittrackee_client/src/actions/stats.js
index 4fe2fee3..ef2c7c6b 100644
--- a/fittrackee_client/src/actions/stats.js
+++ b/fittrackee_client/src/actions/stats.js
@@ -1,8 +1,8 @@
-import FitTrackeeApi from '../fitTrackeeApi/stats'
+import FitTrackeeGenericApi from '../fitTrackeeApi'
import { setData, setError } from './index'
-export const getStats = (userId, type, data) => dispatch => FitTrackeeApi
- .getStats(userId, type, data)
+export const getStats = (userId, type, data) => dispatch => FitTrackeeGenericApi
+ .getData(`stats/${userId}/${type}`, data)
.then(ret => {
if (ret.status === 'success') {
dispatch(setData('statistics', ret.data))
diff --git a/fittrackee_client/src/actions/user.js b/fittrackee_client/src/actions/user.js
index d90ca41d..a59317b1 100644
--- a/fittrackee_client/src/actions/user.js
+++ b/fittrackee_client/src/actions/user.js
@@ -1,3 +1,4 @@
+import FitTrackeeGenericApi from '../fitTrackeeApi'
import FitTrackeeApi from '../fitTrackeeApi/user'
import { history } from '../index'
import { generateIds } from '../utils'
@@ -18,8 +19,17 @@ const ProfileUpdateError = message => ({
type: 'PROFILE_UPDATE_ERROR', message
})
-export const getProfile = () => dispatch => FitTrackeeApi
- .getProfile()
+export const logout = () => ({ type: 'LOGOUT' })
+
+export const loadProfile = () => dispatch => {
+ if (window.localStorage.getItem('authToken')) {
+ return dispatch(getProfile())
+ }
+ return { type: 'LOGOUT' }
+}
+
+export const getProfile = () => dispatch => FitTrackeeGenericApi
+ .getData('auth/profile')
.then(ret => {
if (ret.status === 'success') {
dispatch(getData('sports'))
@@ -32,9 +42,8 @@ export const getProfile = () => dispatch => FitTrackeeApi
throw error
})
-
-export const register = formData => dispatch => FitTrackeeApi
- .register(formData)
+export const loginOrRegister = (target, formData) => dispatch => FitTrackeeApi
+ .loginOrRegister(target, formData)
.then(ret => {
if (ret.status === 'success') {
window.localStorage.setItem('authToken', ret.auth_token)
@@ -46,29 +55,6 @@ export const register = formData => dispatch => FitTrackeeApi
throw error
})
-
-export const login = formData => dispatch => FitTrackeeApi
- .login(formData)
- .then(ret => {
- if (ret.status === 'success') {
- window.localStorage.setItem('authToken', ret.auth_token)
- return dispatch(getProfile())
- }
- return dispatch(AuthError(ret.message))
- })
- .catch(error => {
- throw error
- })
-
-export const loadProfile = () => dispatch => {
- if (window.localStorage.getItem('authToken')) {
- return dispatch(getProfile())
- }
- return { type: 'LOGOUT' }
-}
-
-export const logout = () => ({ type: 'LOGOUT' })
-
const RegisterFormControl = formData => {
const errMsg = []
if (formData.username.length < 3 || formData.username.length > 12) {
@@ -84,15 +70,13 @@ const RegisterFormControl = formData => {
}
export const handleUserFormSubmit = (formData, formType) => dispatch => {
- if (formType === 'Login') {
- return dispatch(login(formData))
+ if (formType === 'register') {
+ const ret = RegisterFormControl(formData)
+ if (ret.length > 0) {
+ return dispatch(AuthErrors(generateIds(ret)))
+ }
}
- // formType === 'Register'
- const ret = RegisterFormControl(formData)
- if (ret.length === 0) {
- return dispatch(register(formData))
- }
- return dispatch(AuthErrors(generateIds(ret)))
+ return dispatch(loginOrRegister(formType, formData))
}
export const handleProfileFormSubmit = formData => dispatch => {
@@ -101,8 +85,8 @@ export const handleProfileFormSubmit = formData => dispatch => {
'Password and password confirmation don\'t match.'
))
}
- return FitTrackeeApi
- .updateProfile(formData)
+ return FitTrackeeGenericApi
+ .postData('auth/profile/edit', formData)
.then(ret => {
if (ret.status === 'success') {
dispatch(getProfile())
@@ -120,8 +104,8 @@ export const uploadPicture = event => dispatch => {
const form = new FormData()
form.append('file', event.target.picture.files[0])
event.target.reset()
- return FitTrackeeApi
- .updatePicture(form)
+ return FitTrackeeGenericApi
+ .addDataWithFile('auth/picture', form)
.then(ret => {
if (ret.status === 'success') {
return dispatch(getProfile())
@@ -136,10 +120,10 @@ export const uploadPicture = event => dispatch => {
export const deletePicture = () => dispatch => FitTrackeeApi
.deletePicture()
.then(ret => {
- if (ret.status === 'success') {
+ if (ret.status === 204) {
return dispatch(getProfile())
}
- dispatch(PictureError(ret.message))
+ return dispatch(PictureError(ret.message))
})
.catch(error => {
throw error
diff --git a/fittrackee_client/src/components/App.jsx b/fittrackee_client/src/components/App.jsx
index 0308a795..016c7bae 100644
--- a/fittrackee_client/src/components/App.jsx
+++ b/fittrackee_client/src/components/App.jsx
@@ -43,7 +43,7 @@ export default class App extends React.Component {