diff --git a/src/redux/asyncThunks/abstractService.js b/src/redux/asyncThunks/abstractService.js index 0f873c6..5063c49 100644 --- a/src/redux/asyncThunks/abstractService.js +++ b/src/redux/asyncThunks/abstractService.js @@ -16,7 +16,7 @@ const _getList = async (endpoint, token) => { const _getOne = async (endpoint, objectId, token) => { return await responseAbstract( - endpoint + '/' + objectId, + endpoint + objectId, 'GET', token, defaultBody @@ -34,7 +34,7 @@ const _post = async (endpoint, body, token) => { const _patch = async (endpoint, objectId, body, token) => { return await responseAbstract( - endpoint + '/' + objectId, + endpoint + objectId, 'PATCH', token, body @@ -43,7 +43,7 @@ const _patch = async (endpoint, objectId, body, token) => { const _put = async (endpoint, objectId, body, token) => { return await responseAbstract( - endpoint + '/' + objectId, + endpoint + objectId, 'PUT', token, body @@ -52,7 +52,7 @@ const _put = async (endpoint, objectId, body, token) => { const _delete = async (endpoint, objectId, token) => { return await responseAbstract( - endpoint + '/' + objectId, + endpoint + objectId, 'DELETE', token, defaultBody @@ -73,22 +73,30 @@ const responseAbstract = async (endpoint, method, token, body) => { } const headerBuilder = (url, method, token, body) => { - let headers = { - url: url, - method: method, - headers: { - 'Authorization': token, - 'accept': 'application/json', - 'Content-Type': 'application/json', + headers = { + 'Authorization': token, + 'accept': 'application/json', + 'Content-Type': 'application/json', } - } - if (method === 'PUT' || method === 'POST' || method === 'PATCH') { - headers = Object.assign({}, headers, { - data: JSON.stringify(body), - withCredentials: true, - }) - } - return headers + if ('file' in body) { + headers = { + 'Authorization': token, + 'accept': 'multipart/form-data', + 'Content-Type': 'multipart/form-data', + } + } + let headers = { + url: url, + method: method, + headers: headers + } + if (method === 'PUT' || method === 'POST' || method === 'PATCH') { + headers = Object.assign({}, headers, { + data: JSON.stringify(body), + withCredentials: true, + }) + } + return headers } diff --git a/src/redux/asyncThunks/modelCrudAsyncThunk.js b/src/redux/asyncThunks/modelCrudAsyncThunk.js index 3de5608..4f38010 100644 --- a/src/redux/asyncThunks/modelCrudAsyncThunk.js +++ b/src/redux/asyncThunks/modelCrudAsyncThunk.js @@ -1,7 +1,7 @@ import { createAsyncThunk } from '@reduxjs/toolkit' import abstractService from './abstractService' -let endpoint = '/model' +let endpoint = '/model/' const fetchGetAllModels = createAsyncThunk( @@ -47,6 +47,7 @@ const fetchUploadModel = createAsyncThunk( ) => { let formData = FormData() formData.append("blend", body.file) + body.file = formData return await abstractService._post( trueEndpoint, body, @@ -56,6 +57,7 @@ const fetchUploadModel = createAsyncThunk( ) export default { - fetchGetAllModels, - fetchGetOneModelAndDownload, + fetchGetAllModels, + fetchGetOneModelAndDownload, + fetchUploadModel } \ No newline at end of file diff --git a/src/redux/asyncThunks/renderCrudAsyncThunk.js b/src/redux/asyncThunks/renderCrudAsyncThunk.js index e69de29..13a6186 100644 --- a/src/redux/asyncThunks/renderCrudAsyncThunk.js +++ b/src/redux/asyncThunks/renderCrudAsyncThunk.js @@ -0,0 +1,39 @@ +import { createAsyncThunk } from '@reduxjs/toolkit' +import abstractService from './abstractService' + +let endpoint = '/render/' + + +const fetchGetAllRenders = createAsyncThunk( + 'model/fetchGetAllModels', + async ( + token, + thunkAPI + ) => { + return await abstractService._getList(endpoint, token) + } +) + +/** + * @param body: + * param token: base64 token, + * param id: render id + */ +const fetchGetOneRenderAndDownload = createAsyncThunk( + 'model/fetchGetAllModels', + async ( + body, + thunkAPI + ) => { + return await abstractService._getOne( + trueEndpoint, + body.id, + body.token + ) + } +) + +export default { + fetchGetAllRenders, + fetchGetOneRenderAndDownload +} \ No newline at end of file diff --git a/src/redux/asyncThunks/userAuthAsyncThunk.js b/src/redux/asyncThunks/userAuthAsyncThunk.js index e69de29..03557e8 100644 --- a/src/redux/asyncThunks/userAuthAsyncThunk.js +++ b/src/redux/asyncThunks/userAuthAsyncThunk.js @@ -0,0 +1,27 @@ +import { createAsyncThunk } from '@reduxjs/toolkit' +import abstractService from './abstractService' + +let endpoint = '/user/auth' + +/** + * @param body: + * param username: username string + * param password: password string + */ +const fetchLogin = createAsyncThunk( + 'model/fetchGetAllModels', + async ( + body, + thunkAPI + ) => { + return await abstractService._post( + endpoint, + body, + '' + ) + } +) + +export default { + fetchLogin +} \ No newline at end of file diff --git a/src/redux/asyncThunks/userCrudAsyncThunk.js b/src/redux/asyncThunks/userCrudAsyncThunk.js index e69de29..442d33c 100644 --- a/src/redux/asyncThunks/userCrudAsyncThunk.js +++ b/src/redux/asyncThunks/userCrudAsyncThunk.js @@ -0,0 +1,43 @@ +import { createAsyncThunk } from '@reduxjs/toolkit' +import abstractService from './abstractService' + +let endpoint = '/model/' + + +const fetchGetAllUsers = createAsyncThunk( + 'model/fetchGetAllModels', + async ( + token, + thunkAPI + ) => { + return await abstractService._getList( + endpoint, + token + ) + } +) + +/** + * @param body: + * param username: username string + * param password: password string + * param email: email string + */ +const fetchRegister = createAsyncThunk( + 'model/fetchGetAllModels', + async ( + body, + thunkAPI + ) => { + return await abstractService._post( + trueEndpoint, + body, + '' + ) + } +) + +export default { + fetchGetAllUsers, + fetchRegister +} \ No newline at end of file