added finished api
This commit is contained in:
parent
15134f2f43
commit
a6045a8ba6
281
src/api.ts
281
src/api.ts
@ -81,6 +81,31 @@ export interface StratRequest {
|
|||||||
success: number,
|
success: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface MapRequest {
|
||||||
|
name: string,
|
||||||
|
image: File,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProfileRequest {
|
||||||
|
name: string,
|
||||||
|
image: File,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PlayerTypeRequest {
|
||||||
|
name: string,
|
||||||
|
task: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface StratStateRequest {
|
||||||
|
description: string,
|
||||||
|
image: File,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LineupRequest {
|
||||||
|
description: string,
|
||||||
|
image: File,
|
||||||
|
}
|
||||||
|
|
||||||
export class API {
|
export class API {
|
||||||
public apiURL: string;
|
public apiURL: string;
|
||||||
|
|
||||||
@ -212,7 +237,7 @@ export class API {
|
|||||||
return await response.json();
|
return await response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async addStrat(groupId: string, strat: StratRequest): Promise<Strat> {
|
public async addStrat(groupId: string, strat: StratRequest): Promise<Group> {
|
||||||
const response = await fetch(this.apiURL + '/group/' + groupId + '/strat', {
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/strat', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@ -239,7 +264,7 @@ export class API {
|
|||||||
await this.checkResponse(response);
|
await this.checkResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateStrat(groupId: string, stratId: string, strat: StratRequest): Promise<Strat> {
|
public async updateStrat(groupId: string, stratId: string, strat: StratRequest): Promise<Group> {
|
||||||
const response = await fetch(this.apiURL + '/group/' + groupId + '/strat/' + stratId, {
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/strat/' + stratId, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
@ -253,6 +278,258 @@ export class API {
|
|||||||
|
|
||||||
return await response.json();
|
return await response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async addMap(groupId: string, map: MapRequest): Promise<Group> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/map', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
},
|
||||||
|
body: JSON.stringify(map)
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async removeMap(groupId: string, mapId: string): Promise<void> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/map/' + mapId, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateMap(groupId: string, mapId: string, map: MapRequest): Promise<Group> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/map/' + mapId, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
},
|
||||||
|
body: JSON.stringify(map)
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async addProfileToGroup(groupId: string, profile: ProfileRequest): Promise<Group> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/profile', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
},
|
||||||
|
body: JSON.stringify(profile)
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async removeProfileToGroup(groupId: string, profileId: string): Promise<void> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/profile/' + profileId, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateProfileToGroup(groupId: string, profileId: string, profile: ProfileRequest): Promise<Group> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/profile/' + profileId, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
},
|
||||||
|
body: JSON.stringify(profile)
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async addPlayerType(groupId: string, stratId: string, playerType: PlayerTypeRequest): Promise<Group> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/strat/' + stratId + '/player-type', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
},
|
||||||
|
body: JSON.stringify(playerType)
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async removePlayerType(groupId: string, stratId: string, playerTypeId: string): Promise<void> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/strat/' + stratId + '/player-type/' + playerTypeId, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updatePlayerType(groupId: string, profileId: string, stratId: string, playerTypeId: string, playerType: PlayerTypeRequest): Promise<Group> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/strat/' + stratId + '/player-type/' + playerTypeId, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
},
|
||||||
|
body: JSON.stringify(playerType)
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async addProfileToPlayerType(groupId: string, stratId: string, playerTypeId: string, profile: ProfileRequest): Promise<Group> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/strat/' + stratId + '/player-type/' + playerTypeId + '/profile', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
},
|
||||||
|
body: JSON.stringify(profile)
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async removeProfileToPlayerType(groupId: string, stratId: string, playerTypeId: string, profileId: string): Promise<void> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/strat/' + stratId + '/player-type/' + playerTypeId + '/profile/' + profileId, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateProfileToPlayerType(groupId: string, profileId: string, stratId: string, playerTypeId: string, profile: ProfileRequest): Promise<Group> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/strat/' + stratId + '/player-type/' + playerTypeId + '/profile/' + profileId, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
},
|
||||||
|
body: JSON.stringify(profile)
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async addStratState(groupId: string, stratId: string, stratState: StratStateRequest): Promise<Group> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/strat/' + stratId + '/strat-state', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
},
|
||||||
|
body: JSON.stringify(stratState)
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async removeStratState(groupId: string, stratId: string, stratStateId: string): Promise<void> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/strat/' + stratId + '/strat-state/' + stratStateId, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateStratState(groupId: string, profileId: string, stratId: string, stratStateId: string, stratState: StratStateRequest): Promise<Group> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/strat/' + stratId + '/strat-state/' + stratStateId, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
},
|
||||||
|
body: JSON.stringify(stratState)
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async addLineup(groupId: string, stratId: string, stratStateId: string, lineup: LineupRequest): Promise<Group> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/strat/' + stratId + '/strat-state/' + stratStateId + '/lineup', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
},
|
||||||
|
body: JSON.stringify(lineup)
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async removeLineup(groupId: string, stratId: string, stratStateId: string, lineupId: string): Promise<void> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/strat/' + stratId + '/strat-state/' + stratStateId + '/lineup/' + lineupId, {
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateLineup(groupId: string, profileId: string, stratId: string, stratStateId: string, lineupId: string, lineup: LineupRequest): Promise<Group> {
|
||||||
|
const response = await fetch(this.apiURL + '/group/' + groupId + '/strat/' + stratId + '/strat-state/' + stratStateId + '/lineup/' + lineupId, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': 'Bearer ' + this.ensureLoggedIn().token
|
||||||
|
},
|
||||||
|
body: JSON.stringify(lineup)
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.checkResponse(response);
|
||||||
|
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const [api, setAPI] = createSignal(new API(''));
|
export const [api, setAPI] = createSignal(new API(''));
|
||||||
|
Loading…
Reference in New Issue
Block a user