Newer
Older
2024-hinata / fanfarm-share / fanfarm-frontend / src / fanfarm.api.js
@hinata0428 hinata0428 on 3 Jun 1 KB add
const API_BASE = "http://localhost:4567/api";

export async function getRecruitments() {
  const res = await fetch(`${API_BASE}/recruitments`);
  return await res.json();
}

export async function postRecruitment(data) {
  const res = await fetch(`${API_BASE}/recruitments`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(data),
  });
  return await res.json();
}

export async function getApplies() {
  const res = await fetch(`${API_BASE}/applies`);
  return await res.json();
}

export async function postApply(data) {
  const res = await fetch(`${API_BASE}/applies`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(data),
  });
  return await res.json();
}

export async function getMatches() {
  const res = await fetch(`${API_BASE}/matches`);
  return await res.json();
}

export async function postMatch(data) {
  const res = await fetch(`${API_BASE}/matches`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(data),
  });
  return await res.json();
}

export async function getMessages(match_id) {
  const res = await fetch(`${API_BASE}/messages?match_id=${match_id}`);
  return await res.json();
}

export async function postMessage(data) {
  const res = await fetch(`${API_BASE}/messages`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(data),
  });
  return await res.json();
}