Files
diplom-frontend/app/lib/api/client/server.ts
2025-06-03 11:44:51 +03:00

86 lines
2.2 KiB
TypeScript

import axios from "../http-client";
import type { ChannelId, ChannelType, Server, ServerChannel, ServerId, ServerInvite } from "../types";
interface CreateServerRequest {
name: string;
iconId?: string;
}
interface CreateServerChannelRequest {
name: string;
type: ChannelType;
}
export async function list() {
const response = await axios.get("/servers");
return response.data as Server[];
}
export async function create(request: CreateServerRequest) {
const response = await axios.post("/servers", request);
return response.data as Server;
}
export async function get(serverId: ServerId) {
const response = await axios.get(`/servers/${serverId}`);
return response.data as Server;
}
export async function deleteServer(serverId: ServerId) {
const response = await axios.delete(`/servers/${serverId}`);
return response.data as Server;
}
export async function listChannels(serverId: ServerId) {
const response = await axios.get(`/servers/${serverId}/channels`);
return response.data as ServerChannel[];
}
export async function createChannel(serverId: ServerId, request: CreateServerChannelRequest) {
const response = await axios.post(`/servers/${serverId}/channels`, request);
return response.data as ServerChannel;
}
export async function getChannel(serverId: ServerId, channelId: ChannelId) {
const response = await axios.get(`/servers/${serverId}/channels/${channelId}`);
return response.data as ServerChannel;
}
export async function deleteChannel(serverId: ServerId, channelId: ChannelId) {
const response = await axios.delete(`/servers/${serverId}/channels/${channelId}`);
return response.data as ServerChannel;
}
export async function createInvite(serverId: ServerId) {
const response = await axios.post(`/servers/${serverId}/invites`);
return response.data as ServerInvite;
}
export async function getInvite(inviteCode: string) {
const response = await axios.get(`/invites/${inviteCode}`);
return response.data as Server;
}
export default {
create,
list,
listChannels,
get,
deleteServer,
createChannel,
getChannel,
deleteChannel,
createInvite,
getInvite,
};