From a6045a8ba6c3347649575e39b32e2ef4f0d68ba7 Mon Sep 17 00:00:00 2001 From: Akito123321 Date: Mon, 17 Jun 2024 22:12:44 +0200 Subject: [PATCH] added finished api --- src/api.ts | 281 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 279 insertions(+), 2 deletions(-) diff --git a/src/api.ts b/src/api.ts index 1498b56..7eea69a 100644 --- a/src/api.ts +++ b/src/api.ts @@ -81,6 +81,31 @@ export interface StratRequest { 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 { public apiURL: string; @@ -212,7 +237,7 @@ export class API { return await response.json(); } - public async addStrat(groupId: string, strat: StratRequest): Promise { + public async addStrat(groupId: string, strat: StratRequest): Promise { const response = await fetch(this.apiURL + '/group/' + groupId + '/strat', { method: 'POST', headers: { @@ -239,7 +264,7 @@ export class API { await this.checkResponse(response); } - public async updateStrat(groupId: string, stratId: string, strat: StratRequest): Promise { + public async updateStrat(groupId: string, stratId: string, strat: StratRequest): Promise { const response = await fetch(this.apiURL + '/group/' + groupId + '/strat/' + stratId, { method: 'PUT', headers: { @@ -253,6 +278,258 @@ export class API { return await response.json(); } + + public async addMap(groupId: string, map: MapRequest): Promise { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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(''));