feat(api): add TypeScript types for API requests and responses

This commit is contained in:
ryan 2025-06-19 14:44:02 +03:00
parent 50d735ae5d
commit ecc4e4da1c

65
src/types/api.ts Normal file
View file

@ -0,0 +1,65 @@
//TypeScript types for API requests/responses
import { Item } from './database';
// API Request Types (matching your Rust structs)
export interface ItemRequest {
url: string;
item: Item;
}
// API Response Types
export interface ApiResponse<T> {
data?: T;
error?: string;
details?: string;
message?: string;
}
export interface ItemsResponse {
items: Item[];
selectedProperties: string[];
}
export interface ErrorResponse {
error: string;
details?: string;
url?: string;
itemId?: string;
property?: string;
}
// API Success Responses
export interface ItemCreatedResponse {
message: string;
item: Item;
}
export interface ItemDeletedResponse {
message: string;
itemId: string;
}
export interface PropertyAddedResponse {
message: string;
property: string;
}
export interface PropertyDeletedResponse {
message: string;
property: string;
}
// HTTP Status Codes (for consistency)
export const HTTP_STATUS = {
OK: 200,
BAD_REQUEST: 400,
INTERNAL_SERVER_ERROR: 500,
} as const;
// API Endpoints (for consistency)
export const API_ENDPOINTS = {
ITEMS: (encodedUrl: string) => `/api/urls/${encodedUrl}/items`,
ITEM: (encodedUrl: string, itemId: string) => `/api/urls/${encodedUrl}/items/${itemId}`,
PROPERTIES: (encodedUrl: string) => `/api/urls/${encodedUrl}/properties`,
PROPERTY: (encodedUrl: string, property: string) => `/api/urls/${encodedUrl}/properties/${property}`,
} as const;