add abstract service app && APIAddress -> /stores
parent
7058f9d7ed
commit
74d7cc50c4
|
|
@ -1,15 +1,15 @@
|
||||||
import React from 'react'
|
// import React from 'react'
|
||||||
import
|
// import
|
||||||
import { observer } from 'react-mobx'
|
// import { observer } from 'react-mobx'
|
||||||
import { render } from 'node-sass'
|
// import { render } from 'node-sass'
|
||||||
|
|
||||||
import Guest from './../stores/guest'
|
// import Guest from './../stores/guest'
|
||||||
|
|
||||||
@observer
|
// @observer
|
||||||
class App {
|
// class App {
|
||||||
|
|
||||||
render() {
|
// render() {
|
||||||
<div></div>
|
// <div></div>
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
const address = 'localhost:9090'
|
||||||
|
|
||||||
|
export {
|
||||||
|
address
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
import { address } from './APIAddress'
|
||||||
|
|
||||||
|
export class AbstractService<T> {
|
||||||
|
|
||||||
|
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<T> > {
|
||||||
|
return await this.responseGD(address + endpoint, 'GET')
|
||||||
|
}
|
||||||
|
|
||||||
|
public async getOne(endpoint: string) : Promise<T> {
|
||||||
|
return await this.responseGD(address + endpoint, 'GET')
|
||||||
|
}
|
||||||
|
|
||||||
|
public async post(endpoint: string, body: T) : Promise<T> {
|
||||||
|
return await this.responseCRU(address + endpoint, 'POST', body)
|
||||||
|
}
|
||||||
|
|
||||||
|
public async put(endpoint: string, body: T) : Promise<T> {
|
||||||
|
return await this.responseCRU(address + endpoint, 'PUT', body)
|
||||||
|
}
|
||||||
|
|
||||||
|
public async patch(endpoint: string, body: T) : Promise<T> {
|
||||||
|
return await this.responseCRU(address + endpoint, 'PATCH', body)
|
||||||
|
}
|
||||||
|
|
||||||
|
public async delete(endpoint: string) : Promise<T> {
|
||||||
|
return await this.responseGD(address + endpoint, 'DELETE')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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 = ''
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue