Add organization and task queue features
- Introduced new models for `Organization` and `ReviewTask` to manage organizations and review tasks. - Implemented API endpoints for CRUD operations on organizations and tasks, including scanning organizations for repositories and PRs. - Developed a background worker for sequential processing of review tasks with priority handling and automatic retries. - Created frontend components for managing organizations and monitoring task queues, including real-time updates and filtering options. - Added comprehensive documentation for organization features and quick start guides. - Fixed UI issues and improved navigation for better user experience.
This commit is contained in:
108
frontend/src/api/organizations.ts
Normal file
108
frontend/src/api/organizations.ts
Normal file
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* Organization API client
|
||||
*/
|
||||
|
||||
import {
|
||||
Organization,
|
||||
OrganizationCreate,
|
||||
OrganizationUpdate,
|
||||
OrganizationScanResult,
|
||||
TaskListResponse,
|
||||
TaskStatus,
|
||||
WorkerStatus,
|
||||
} from '../types/organization';
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_API_URL || '/api';
|
||||
|
||||
// Organizations
|
||||
|
||||
export async function getOrganizations(skip = 0, limit = 100): Promise<{ items: Organization[]; total: number }> {
|
||||
const response = await fetch(`${API_BASE_URL}/organizations?skip=${skip}&limit=${limit}`);
|
||||
if (!response.ok) throw new Error('Failed to fetch organizations');
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function getOrganization(id: number): Promise<Organization> {
|
||||
const response = await fetch(`${API_BASE_URL}/organizations/${id}`);
|
||||
if (!response.ok) throw new Error('Failed to fetch organization');
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function createOrganization(data: OrganizationCreate): Promise<Organization> {
|
||||
const response = await fetch(`${API_BASE_URL}/organizations`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.detail || 'Failed to create organization');
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function updateOrganization(id: number, data: OrganizationUpdate): Promise<Organization> {
|
||||
const response = await fetch(`${API_BASE_URL}/organizations/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.detail || 'Failed to update organization');
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function deleteOrganization(id: number): Promise<void> {
|
||||
const response = await fetch(`${API_BASE_URL}/organizations/${id}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to delete organization');
|
||||
}
|
||||
|
||||
export async function scanOrganization(id: number): Promise<OrganizationScanResult> {
|
||||
const response = await fetch(`${API_BASE_URL}/organizations/${id}/scan`, {
|
||||
method: 'POST',
|
||||
});
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.detail || 'Failed to scan organization');
|
||||
}
|
||||
return response.json();
|
||||
}
|
||||
|
||||
// Tasks
|
||||
|
||||
export async function getTasks(status?: TaskStatus, skip = 0, limit = 100): Promise<TaskListResponse> {
|
||||
const params = new URLSearchParams({ skip: skip.toString(), limit: limit.toString() });
|
||||
if (status) params.append('status', status);
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/tasks?${params}`);
|
||||
if (!response.ok) throw new Error('Failed to fetch tasks');
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function getWorkerStatus(): Promise<WorkerStatus> {
|
||||
const response = await fetch(`${API_BASE_URL}/tasks/worker/status`);
|
||||
if (!response.ok) throw new Error('Failed to fetch worker status');
|
||||
return response.json();
|
||||
}
|
||||
|
||||
export async function retryTask(id: number): Promise<void> {
|
||||
const response = await fetch(`${API_BASE_URL}/tasks/${id}/retry`, {
|
||||
method: 'POST',
|
||||
});
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.detail || 'Failed to retry task');
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteTask(id: number): Promise<void> {
|
||||
const response = await fetch(`${API_BASE_URL}/tasks/${id}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
if (!response.ok) throw new Error('Failed to delete task');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user