Download screenshot2-add-expense-sparse/environment/app/frontend/src/api.js from ApolloTeam/fullstackbench-tasks: direct link, hf CLI and curl.
- Browser
- Download file 1.86 kB
-
https://huggingface.co/datasets/ApolloTeam/fullstackbench-tasks/resolve/main/screenshot2-add-expense-sparse/environment/app/frontend/src/api.js
- Command line
-
hf download hf://datasets/ApolloTeam/fullstackbench-tasks/screenshot2-add-expense-sparse/environment/app/frontend/src/api.js
-
curl -L -o api.js https://huggingface.co/datasets/ApolloTeam/fullstackbench-tasks/resolve/main/screenshot2-add-expense-sparse/environment/app/frontend/src/api.js
1.86 kB
| // Use VITE_API_URL if set (e.g. by dashboard proxy), otherwise fall back to direct localhost. | |
| const BASE_URL = import.meta.env.VITE_API_URL || `http://localhost:${import.meta.env.VITE_API_PORT || 5001}/api`; | |
| async function request(path, options = {}) { | |
| const res = await fetch(`${BASE_URL}${path}`, { | |
| headers: { 'Content-Type': 'application/json' }, | |
| ...options, | |
| }); | |
| if (!res.ok) { | |
| const err = await res.json().catch(() => ({ error: res.statusText })); | |
| throw new Error(err.error || 'Request failed'); | |
| } | |
| return res.json(); | |
| } | |
| export function getUsers() { | |
| return request('/users'); | |
| } | |
| export function createUser(name, email) { | |
| return request('/users', { | |
| method: 'POST', | |
| body: JSON.stringify({ name, email }), | |
| }); | |
| } | |
| export function getGroups() { | |
| return request('/groups'); | |
| } | |
| export function createGroup(name, memberIds) { | |
| return request('/groups', { | |
| method: 'POST', | |
| body: JSON.stringify({ name, member_ids: memberIds }), | |
| }); | |
| } | |
| export function getGroupDetail(groupId) { | |
| return request(`/groups/${groupId}`); | |
| } | |
| export function getGroupBalances(groupId) { | |
| return request(`/groups/${groupId}/balances`); | |
| } | |
| export function createExpense(groupId, description, amount, paidById, splitAmong) { | |
| return request(`/groups/${groupId}/expenses`, { | |
| method: 'POST', | |
| body: JSON.stringify({ | |
| description, | |
| amount: parseFloat(amount), | |
| paid_by: paidById, | |
| split_among: splitAmong, | |
| }), | |
| }); | |
| } | |
| export function deleteExpense(groupId, expenseId) { | |
| return request(`/expenses/${expenseId}`, { | |
| method: 'DELETE', | |
| }); | |
| } | |
| export function settleUp(groupId, payerId, payeeId, amount) { | |
| return request(`/groups/${groupId}/settle`, { | |
| method: 'POST', | |
| body: JSON.stringify({ | |
| payer_id: payerId, | |
| payee_id: payeeId, | |
| amount: parseFloat(amount), | |
| }), | |
| }); | |
| } | |