diff --git a/package.json b/package.json index 35e2c0c..94fad0f 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "nft-max-react", + "name": "myFit-App", "version": "0.1.0", "private": true, "dependencies": { @@ -8,6 +8,7 @@ "@testing-library/jest-dom": "^5.11.4", "@testing-library/react": "^11.1.0", "@testing-library/user-event": "^12.1.10", + "axios": "^0.24.0", "chart.js": "^3.7.1", "chartjs": "^0.3.24", "faker": "^6.6.6", diff --git a/src/services/SiteService.js b/src/services/SiteService.js new file mode 100644 index 0000000..339cca5 --- /dev/null +++ b/src/services/SiteService.js @@ -0,0 +1,83 @@ +import React from "react"; +import Axios from "axios"; + +class SiteService { + constructor() { + console.log("Er are here anyway"); + } + // Blog Data {Get} + blogData() { + return this.getAuxEnd("/blogdata", null); + } + + // Country Data {GET} + countryData() { + return this.getAuxEnd("/country", null); + } + + // Contact Data{POST} + contactData() { + return this.postAuxEnd("/contact", null) + } + + faqData() { + return this.getAuxEnd("/faq", null); + } + + priceData() { + return this.getAuxEnd("/pricing", null); + } + + //---------------------------------------- ----- + //---------------------------------------- ----- + // Unified call below + //---------------------------------------- ----- + //---------------------------------------- ----- + getAuxEnd(uri, reqData) { + const endPoint = process.env.REACT_APP_AUX_ENDPOINT + uri; + return Axios.get(endPoint) + .then((response) => { + // console.log(response); + // res = response; + // console.log("~~~~~~~ Toks2 GET ~~~~~~~~"); + return response; + }) + .catch((error) => { + if (error.response) { + //response status is an error code + console.log(error.response.status); + } else if (error.request) { + //response not received though the request was sent + console.log(error.request); + } else { + //an error occurred when setting up the request + console.log(error.message); + } + }); + } + + postAuxEnd(uri, reqData) { + const endPoint = process.env.REACT_APP_AUX_ENDPOINT + uri; + return Axios.post(endPoint, reqData) + .then((response) => { + console.log(response); + // res = response; + console.log("~~~~~~~ Toks2 POST ~~~~~~~~"); + return response; + }) + .catch((error) => { + if (error.response) { + //response status is an error code + console.log(error.response.status); + } else if (error.request) { + //response not received though the request was sent + console.log(error.request); + } else { + //an error occurred when setting up the request + console.log(error.message); + } + }); + } +} + +export default SiteService; diff --git a/src/services/UsersService.js b/src/services/UsersService.js new file mode 100644 index 0000000..a52c627 --- /dev/null +++ b/src/services/UsersService.js @@ -0,0 +1,91 @@ +import React from "react"; +import Axios from "axios"; + +class usersService { + constructor() { + console.log("Er are here anyway"); + } + + logInUser(reqData) { + debugger; + /* + clean up the request data here + */ + return this.postAuxEnd("/login", reqData); + } + + //---------------------------------------- ----- + //---------------------------------------- ----- + // Unified call below + //---------------------------------------- ----- + //---------------------------------------- ----- + getAuxEnd(uri, reqData) { + const endPoint = process.env.REACT_APP_USERS_ENDPOINT + uri; + return Axios.get(endPoint) + .then((response) => { + // console.log(response); + // res = response; + // console.log("~~~~~~~ Toks2 GET ~~~~~~~~"); + return response; + }) + .catch((error) => { + if (error.response) { + //response status is an error code + console.log(error.response.status); + } else if (error.request) { + //response not received though the request was sent + console.log(error.request); + } else { + //an error occurred when setting up the request + console.log(error.message); + } + }); + } + + postAuxEnd(uri, reqData) { + const endPoint = process.env.REACT_APP_USERS_ENDPOINT + uri; + const token = '..your token..' + let axiosConfig = { + headers: { + 'Accept': 'application/json', + 'Access-Control-Allow-Origin': '*', + 'Content-Type': 'application/json;charset=UTF-8', + 'Authorization': `Basic ${token}`, + } + }; + //Access-Control-Allow-Origin + var postData = { + email: "test@test.com", + password: "password" + }; + Axios.defaults.headers.post['Content-Type'] ='application/json;charset=utf-8'; + Axios.defaults.headers.post['Access-Control-Allow-Origin'] = '*'; + return Axios.post(endPoint, postData,axiosConfig) + .then((response) => { + console.log(response); + // res = response; + console.log("~~~~~~~ Toks2 POST ~~~~~~~~"); + return response; + }) + .catch((error) => { + if (error.response) { + //response status is an error code + console.log("ERROR-------------------------------------------------------"); + console.log(error.response.status); + console.log("ERROR-------------------------------------------------------"); + } else if (error.request) { + //response not received though the request was sent + console.log("ERROR2-------------------------------------------------------"); + console.log(error.request); + console.log("ERROR2-------------------------------------------------------"); + } else { + //an error occurred when setting up the request + console.log("ERROR3-------------------------------------------------------"); + console.log(error.message); + console.log("ERROR3-------------------------------------------------------"); + } + }); + } +} + +export default usersService;