Compare commits

..

2 commits

Author SHA1 Message Date
c4251d9f51
fix: Added unfinished api routes to backend 2024-02-12 11:08:34 +01:00
1974152b48
Chore: Update api paths 2024-02-12 11:06:29 +01:00
7 changed files with 216 additions and 54 deletions

View file

@ -10,7 +10,7 @@
"version": "0.0.0" "version": "0.0.0"
}, },
"paths": { "paths": {
"/api/config/boot": { "/api/boot/config": {
"get": { "get": {
"tags": ["Guild configs"], "tags": ["Guild configs"],
"summary": "Find a guild's config by ID", "summary": "Find a guild's config by ID",
@ -41,7 +41,7 @@
] ]
} }
}, },
"/api/config/{guildId}": { "/api/{guildId}/config": {
"get": { "get": {
"tags": ["Guild configs"], "tags": ["Guild configs"],
"summary": "Find a guild's config by ID", "summary": "Find a guild's config by ID",
@ -118,7 +118,7 @@
] ]
} }
}, },
"/api/tp_messages/{guildId}": { "/api/{guildId}/tp_messages": {
"get": { "get": {
"tags": ["Time planning messages"], "tags": ["Time planning messages"],
"summary": "Find the tp_messages of guild by ID", "summary": "Find the tp_messages of guild by ID",
@ -208,7 +208,56 @@
] ]
} }
}, },
"/api/match/{guildId}/{channelId}": { "/api/{guildId}/matches": {
"get": {
"tags": ["Matches"],
"summary": "Find all matches of guild by ID",
"description": "Returns tp_messages for a guild",
"operationId": "getMatchesOfGuildById",
"parameters": [
{
"name": "guildId",
"in": "path",
"description": "ID of guild's tp_messages to return",
"required": true,
"schema": {
"type": "string",
"format": "varchar(20)"
}
}
],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/tp_messages"
}
}
}
}
},
"204": {
"description": "Time planning not enabled for this guild"
},
"400": {
"description": "Invalid ID supplied"
},
"404": {
"description": "Guild not found"
}
},
"security": [
{
"api_key": []
}
]
}
},
"/api/{guildId}/matches/{channelId}": {
"post": { "post": {
"tags": ["Matches"], "tags": ["Matches"],
"summary": "Save a new created match in channel of guild by IDs", "summary": "Save a new created match in channel of guild by IDs",
@ -264,7 +313,7 @@
] ]
} }
}, },
"/api/match/{guildId}/{channelId}/{matchMessageId}": { "/api/{guildId}/matches/{channelId}/{matchMessageId}": {
"put": { "put": {
"tags": ["Matches"], "tags": ["Matches"],
"summary": "Set state for match of guild by IDs", "summary": "Set state for match of guild by IDs",
@ -329,55 +378,6 @@
} }
] ]
} }
},
"/api/match/{guildId}": {
"get": {
"tags": ["Matches"],
"summary": "Find all matches of guild by ID",
"description": "Returns tp_messages for a guild",
"operationId": "getMatchesOfGuildById",
"parameters": [
{
"name": "guildId",
"in": "path",
"description": "ID of guild's tp_messages to return",
"required": true,
"schema": {
"type": "string",
"format": "varchar(20)"
}
}
],
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/tp_messages"
}
}
}
}
},
"204": {
"description": "Time planning not enabled for this guild"
},
"400": {
"description": "Invalid ID supplied"
},
"404": {
"description": "Guild not found"
}
},
"security": [
{
"api_key": []
}
]
}
} }
}, },
"components": { "components": {

View file

@ -0,0 +1,48 @@
import { APIEvent } from "@solidjs/start/server/types";
import { eq } from "drizzle-orm";
import db from "~/drizzle";
import { guilds } from "~/drizzle/schema";
export const GET = async ({ params }: APIEvent) => {
const guild = await db.query.guilds
.findFirst({
where: eq(guilds.id, params.guildId),
with: {
timePlanning: { with: { messages: true } },
matches: true,
},
})
.execute();
if (!guild)
return new Response(JSON.stringify({ error: "No such guild found." }), {
status: 404,
});
return guild;
};
export const DELETE = async ({ params }: APIEvent) => {
const guildQuery = await db.query.guilds
.findFirst({
where: eq(guilds.id, params.guildId),
with: {
timePlanning: { with: { messages: true } },
matches: true,
},
})
.execute();
if (!guildQuery)
return new Response(JSON.stringify({ error: "No such guild found." }), {
status: 404,
});
const guild = await db
.delete(guilds)
.where(eq(guilds.id, params.guildId))
.returning()
.execute();
return guild;
};

View file

@ -0,0 +1,24 @@
import { APIEvent } from "@solidjs/start/server/types";
import { eq } from "drizzle-orm";
import db from "~/drizzle";
import { guilds } from "~/drizzle/schema";
export const PUT = async ({ params }: APIEvent) => {
const guild = await db.query.guilds
.findFirst({
where: eq(guilds.id, params.guildId),
with: {
timePlanning: { with: { messages: true } },
matches: true,
},
})
.execute();
if (!guild)
return new Response(JSON.stringify({ error: "No such guild found." }), {
status: 404,
});
return "TODO";
// return guild.timePlanning;
};

View file

@ -0,0 +1,24 @@
import { APIEvent } from "@solidjs/start/server/types";
import { eq } from "drizzle-orm";
import db from "~/drizzle";
import { guilds } from "~/drizzle/schema";
export const POST = async ({ params }: APIEvent) => {
const guild = await db.query.guilds
.findFirst({
where: eq(guilds.id, params.guildId),
with: {
timePlanning: { with: { messages: true } },
matches: true,
},
})
.execute();
if (!guild)
return new Response(JSON.stringify({ error: "No such guild found." }), {
status: 404,
});
return "TODO";
// return guild.timePlanning;
};

View file

@ -0,0 +1,24 @@
import { APIEvent } from "@solidjs/start/server/types";
import { eq } from "drizzle-orm";
import db from "~/drizzle";
import { guilds } from "~/drizzle/schema";
export const GET = async ({ params }: APIEvent) => {
const guild = await db.query.guilds
.findFirst({
where: eq(guilds.id, params.guildId),
with: {
timePlanning: { with: { messages: true } },
matches: true,
},
})
.execute();
if (!guild)
return new Response(JSON.stringify({ error: "No such guild found." }), {
status: 404,
});
return "TODO";
// return guild.timePlanning;
};

View file

@ -0,0 +1,28 @@
import { APIEvent } from "@solidjs/start/server/types";
import { eq } from "drizzle-orm";
import db from "~/drizzle";
import { guilds } from "~/drizzle/schema";
export const GET = async ({ params }: APIEvent) => {
const guild = await db.query.guilds
.findFirst({
where: eq(guilds.id, params.guildId),
with: {
timePlanning: { with: { messages: true } },
matches: true,
},
})
.execute();
if (!guild)
return new Response(JSON.stringify({ error: "No such guild found." }), {
status: 404,
});
return "TODO";
// return guild.timePlanning;
};
export const PUT = async () => {
return "TODO";
};

View file

@ -0,0 +1,14 @@
import db from "~/drizzle";
export const GET = async () => {
const guilds = await db.query.guilds
.findMany({
with: {
timePlanning: { with: { messages: true } },
matches: true,
},
})
.execute();
return { guilds };
};