We use a single, well-organized API service with clear namespaces for different user roles.
import { ApiService } from '@/lib/api';
// Authentication
const loginResponse = await ApiService.auth.login({ role: 'admin', username: 'admin@email.com', password: 'password' });
await ApiService.auth.logout();
const tokenValid = await ApiService.auth.validateToken();
// Admin Operations
const tasks = await ApiService.admin.getAllTasks();
const newTask = await ApiService.admin.createTask({ title: 'New Task', round_num: 1, teamId: 1 });
const leaderboard = await ApiService.admin.getLeaderboard();
const teams = await ApiService.admin.getAllTeams();
// Team Operations
const teamDetails = await ApiService.team.getDetails(1);
const teamTasks = await ApiService.team.getTasks(1);
await ApiService.team.submitTask(1, 2, { teamNotes: 'Completed successfully' });
await ApiService.team.uploadGalleryImage(1, fileObject);import { authAPI, adminAPI, teamAPI } from '@/lib/api';
const tasks = await adminAPI.getAllTasks();
const teamDetails = await teamAPI.getDetails(1);login()- User authenticationlogout()- Clear sessionvalidateToken()- Check token validity
- Tasks: CRUD operations, completion, assignment
- Teams: View all teams, get team details
- Leaderboard: View and update rankings
- Problem Statements: Full CRUD + CSV upload
- Announcements: Full CRUD operations
- Dashboard: Admin dashboard data
- Profile: Get/update team details
- Tasks: View assigned tasks, submit solutions
- Problem Statements: Read-only access
- Gallery: Upload/remove team images
- Announcements: Read-only access
- Single Source of Truth: One API service to maintain
- Clear Organization: Role-based namespaces
- Type Safety: Full TypeScript support
- Consistent Error Handling: Centralized interceptors
- Easy to Use: Intuitive method names and structure