From 32c64a5399bdd06c35ba7a5eb1191626b08033eb Mon Sep 17 00:00:00 2001 From: saeid_01 Date: Tue, 9 Jul 2019 02:18:16 +0430 Subject: [PATCH] create structure urls --- public/mix-manifest.json | 8 ++-- resources/js/Global/components/Tiles/Tile.vue | 2 +- resources/js/Global/mixins/api.js | 13 +++++ resources/js/Global/mixins/global.js | 4 +- resources/js/Global/utils/api/apiHandler.js | 7 +++ .../js/Global/utils/api/factory/apiFactory.js | 7 +++ .../utils/api/factory/apollo/apolloApi.js | 41 ++++++++++++++++ .../utils/api/factory/axios/axiosApi.js | 47 +++++++++++++++++++ 8 files changed, 122 insertions(+), 7 deletions(-) create mode 100644 resources/js/Global/mixins/api.js create mode 100644 resources/js/Global/utils/api/apiHandler.js create mode 100644 resources/js/Global/utils/api/factory/apiFactory.js create mode 100644 resources/js/Global/utils/api/factory/apollo/apolloApi.js create mode 100644 resources/js/Global/utils/api/factory/axios/axiosApi.js diff --git a/public/mix-manifest.json b/public/mix-manifest.json index f39ab6c..3684805 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -1,6 +1,6 @@ { - "/js/vue/Authentication/app.js": "/js/vue/Authentication/app.js?id=584db8725dd8389d6625", - "/js/vue/Home/app.js": "/js/vue/Home/app.js?id=2c594e6374c9a8a0ea78", - "/js/vue/Modules/CRM/app.js": "/js/vue/Modules/CRM/app.js?id=0c0fad3f977417217589", - "/js/vue/User/app.js": "/js/vue/User/app.js?id=d5b0a3c5d8bd997a7f4c" + "/js/vue/Authentication/app.js": "/js/vue/Authentication/app.js?id=ada36e14123738cce4a1", + "/js/vue/Home/app.js": "/js/vue/Home/app.js?id=4389447314d810908e49", + "/js/vue/Modules/CRM/app.js": "/js/vue/Modules/CRM/app.js?id=59997cc242d94438537d", + "/js/vue/User/app.js": "/js/vue/User/app.js?id=32e40e7920eba25a4bb2" } diff --git a/resources/js/Global/components/Tiles/Tile.vue b/resources/js/Global/components/Tiles/Tile.vue index dad199b..69babc2 100644 --- a/resources/js/Global/components/Tiles/Tile.vue +++ b/resources/js/Global/components/Tiles/Tile.vue @@ -7,7 +7,7 @@
{{ TitleFa }}
{{ TitleEn }}
- +
{{ Quantity }} diff --git a/resources/js/Global/mixins/api.js b/resources/js/Global/mixins/api.js new file mode 100644 index 0000000..c8483ee --- /dev/null +++ b/resources/js/Global/mixins/api.js @@ -0,0 +1,13 @@ +import axiosApi from '@Global/utils/api/factory/axios/axiosApi' +import apolloApi from '@Global/utils/api/factory/axios/axiosApi' +import apiHandler from '@Global/utils/api/apiHandler' + +export const api = (url) => { + apiHandler.request(new url['type']+'Api'(url)); +} + +export default { + methods: { + $_api: api(url) + }, +} \ No newline at end of file diff --git a/resources/js/Global/mixins/global.js b/resources/js/Global/mixins/global.js index fe20b2a..1b8c867 100644 --- a/resources/js/Global/mixins/global.js +++ b/resources/js/Global/mixins/global.js @@ -1,7 +1,7 @@ const global = { methods: { - getPath(subPath) { - return 'http://127.0.0.1:8000/' + subPath; + $_getPath(subPath) { + return '/' + subPath; } } }; diff --git a/resources/js/Global/utils/api/apiHandler.js b/resources/js/Global/utils/api/apiHandler.js new file mode 100644 index 0000000..321f3ab --- /dev/null +++ b/resources/js/Global/utils/api/apiHandler.js @@ -0,0 +1,7 @@ +export default class apiHandler { + + request(apiMethod) { + return apiMethod.Handle(); + } + +} \ No newline at end of file diff --git a/resources/js/Global/utils/api/factory/apiFactory.js b/resources/js/Global/utils/api/factory/apiFactory.js new file mode 100644 index 0000000..cc99373 --- /dev/null +++ b/resources/js/Global/utils/api/factory/apiFactory.js @@ -0,0 +1,7 @@ +export default class apiFactory { + + Handle() { + return this.init(); + } + +} \ No newline at end of file diff --git a/resources/js/Global/utils/api/factory/apollo/apolloApi.js b/resources/js/Global/utils/api/factory/apollo/apolloApi.js new file mode 100644 index 0000000..ef4a3c7 --- /dev/null +++ b/resources/js/Global/utils/api/factory/apollo/apolloApi.js @@ -0,0 +1,41 @@ +import apiFactory from "../apiFactory"; + +export default class apolloApi extends apiFactory { + + constructor(urlObj) { + super(); + this.staticMethods = ["query", "mutations"]; + + this.method = urlObj.method; + this.gql = urlObj.gql; + this.variables = urlObj.variables; + } + + init() { + if (this.checkMethod()) { + return this[this.method](); + } + } + + checkMethod() { + return this.staticMethods.includes(this.method); + } + + query() { + const query = this.gql; + const variables = this.variables; + return apollo.query({ + query, + variables + }); + } + + mutate() { + const mutation = this.gql; + const variables = this.variables; + return apollo.mutate({ + mutation, + variables + }); + } +} diff --git a/resources/js/Global/utils/api/factory/axios/axiosApi.js b/resources/js/Global/utils/api/factory/axios/axiosApi.js new file mode 100644 index 0000000..ed4e961 --- /dev/null +++ b/resources/js/Global/utils/api/factory/axios/axiosApi.js @@ -0,0 +1,47 @@ +import apiFactory from "../apiFactory"; +import axios from "axios"; + +export default class axiosApi extends apiFactory { + + constructor(urlObj) { + super(); + this.staticMethods = ["get", "post", "put", "delete"]; + + this.method = urlObj.method; + this.url = urlObj.url; + this.data = urlObj.data; + } + + init() { + if (this.checkMethod()) { + return this[this.method](); + } + } + + checkMethod() { + return this.staticMethods.includes(this.method); + } + + get() { + const params = this.data; + return axios.get(this.url, { + params + }); + } + + post() { + return axios.post(this.url, this.data); + } + + put() { + const data = this.data; + data['_method'] = 'put'; + return axios.put(this.url, data); + } + + delete() { + const data = this.data; + data['_method'] = 'delete'; + return axios.put(this.url, data); + } +}