diff --git a/src/pages/app.js b/src/pages/app.js index ef8d38a..46b7e32 100644 --- a/src/pages/app.js +++ b/src/pages/app.js @@ -1,15 +1,15 @@ -import React from 'react' -import -import { observer } from 'react-mobx' -import { render } from 'node-sass' +// import React from 'react' +// import +// import { observer } from 'react-mobx' +// import { render } from 'node-sass' -import Guest from './../stores/guest' +// import Guest from './../stores/guest' -@observer -class App { +// @observer +// class App { - render() { -
- } -} +// render() { +//
+// } +// } diff --git a/src/stores/APIAddress.ts b/src/stores/APIAddress.ts new file mode 100644 index 0000000..4aaf33b --- /dev/null +++ b/src/stores/APIAddress.ts @@ -0,0 +1,5 @@ +const address = 'localhost:9090' + +export { + address +} \ No newline at end of file diff --git a/src/stores/AppService.ts b/src/stores/AppService.ts new file mode 100644 index 0000000..3e8cc45 --- /dev/null +++ b/src/stores/AppService.ts @@ -0,0 +1,45 @@ +import { address } from './APIAddress' + +export class AbstractService { + + private async responseGD(address: string, method: string) { + const response = await fetch( address, { + method: method, + credentials: 'same-origin', + }) + return response.json() + } + + private async responseCRU(address: string, method: string, body: T) { + const response = await fetch( address, { + method: method, + credentials: 'same-origin', + body: JSON.stringify(body) + }) + return response.json() + } + + public async getList(endpoint: string) : Promise< Array > { + return await this.responseGD(address + endpoint, 'GET') + } + + public async getOne(endpoint: string) : Promise { + return await this.responseGD(address + endpoint, 'GET') + } + + public async post(endpoint: string, body: T) : Promise { + return await this.responseCRU(address + endpoint, 'POST', body) + } + + public async put(endpoint: string, body: T) : Promise { + return await this.responseCRU(address + endpoint, 'PUT', body) + } + + public async patch(endpoint: string, body: T) : Promise { + return await this.responseCRU(address + endpoint, 'PATCH', body) + } + + public async delete(endpoint: string) : Promise { + return await this.responseGD(address + endpoint, 'DELETE') + } +} \ No newline at end of file diff --git a/src/stores/guest.js b/src/stores/guest.js deleted file mode 100644 index e919b0e..0000000 --- a/src/stores/guest.js +++ /dev/null @@ -1,19 +0,0 @@ -import { observable, computed } from 'mobx' - -class Guest { - @observable id = '' - @observable ip = '' - @observable city = '' - @observable country = '' -} - -class User { - @observable id = -1 - @observable username = '' - @observable email = '' - @observable ip = '' - @observable city = '' - @observable country = '' - - @observable token = '' -} \ No newline at end of file