Improve code legibility by introducing gameState enum
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import axios, { AxiosPromise, AxiosRequestConfig, AxiosResponse } from 'axios'
|
||||
import {CreateGameObject} from "@/objects/objects";
|
||||
import axios, {AxiosPromise, AxiosRequestConfig, AxiosResponse} from 'axios'
|
||||
import {JoinCreateGameObject, IsStartedObject, ApiObject} from "@/objects/objects";
|
||||
|
||||
export default class PerudoApi {
|
||||
private static baseUrl = 'http://localhost:8000/'
|
||||
@@ -7,19 +7,40 @@ export default class PerudoApi {
|
||||
private static objectInstance?: PerudoApi;
|
||||
|
||||
public static get instance(): PerudoApi {
|
||||
if(typeof PerudoApi.objectInstance === 'undefined') {
|
||||
if (typeof PerudoApi.objectInstance === 'undefined') {
|
||||
PerudoApi.objectInstance = new PerudoApi();
|
||||
}
|
||||
return PerudoApi.objectInstance;
|
||||
}
|
||||
|
||||
public createGame(name: string):Promise<CreateGameObject> {
|
||||
return this.get<CreateGameObject>(PerudoApi.baseUrl + 'game/create?name=' + name)
|
||||
.then((response: AxiosResponse<CreateGameObject>) => {
|
||||
public createGame(name: string): Promise<JoinCreateGameObject> {
|
||||
return this.get<JoinCreateGameObject>(PerudoApi.baseUrl + 'game/create?name=' + name)
|
||||
.then((response: AxiosResponse<JoinCreateGameObject>) => {
|
||||
return response.data;
|
||||
})
|
||||
}
|
||||
|
||||
public joinGame(name: string, code: string): Promise<JoinCreateGameObject> {
|
||||
return this.get<JoinCreateGameObject>(PerudoApi.baseUrl + 'game/join/' + code + '?name=' + name)
|
||||
.then((response: AxiosResponse<JoinCreateGameObject>) => {
|
||||
return response.data;
|
||||
})
|
||||
}
|
||||
|
||||
public startedGame(playerId: string): Promise<IsStartedObject> {
|
||||
return this.get<IsStartedObject>(PerudoApi.baseUrl + 'game/started/' + playerId)
|
||||
.then((response: AxiosResponse<IsStartedObject>) => {
|
||||
return response.data;
|
||||
})
|
||||
}
|
||||
|
||||
public startGame(playerId: string): Promise<ApiObject> {
|
||||
return this.get<ApiObject>(PerudoApi.baseUrl + 'game/start/' + playerId)
|
||||
.then((response: AxiosResponse<ApiObject>) => {
|
||||
return response.data;
|
||||
});
|
||||
}
|
||||
|
||||
private get<T = any>(url: string, getParameters?: Record<string, any>) {
|
||||
return axios.get(url).then((response: AxiosResponse<T>) => {
|
||||
return response;
|
||||
|
||||
Reference in New Issue
Block a user