import { axios } from "@/api/index"; import { Edition } from "@/data/edition"; import { prepare } from "@/routing"; import { EditionDTO, editionDtoTransformer, editionTeaserDtoTransformer } from "@/api/dto/edition"; const EDITIONS_ENDPOINT = "/editions"; const EDITION_INFO_ENDPOINT = "/editions/:key"; const REGISTER_ENDPOINT = "/register"; export async function available() { const response = await axios.get(EDITIONS_ENDPOINT); return (response.data || []).map(editionTeaserDtoTransformer.transform); } export async function join(key: string): Promise { try { await axios.post(REGISTER_ENDPOINT, JSON.stringify(key), { headers: { "Content-Type": "application/json" } }); return true; } catch (error) { console.error(error); return false; } } export async function get(key: string): Promise { const response = await axios.get(prepare(EDITION_INFO_ENDPOINT, { key })); const dto = response.data; return editionDtoTransformer.transform(dto); }