feat(api): add TypeScript types for API requests and responses
This commit is contained in:
parent
50d735ae5d
commit
ecc4e4da1c
1 changed files with 65 additions and 0 deletions
65
src/types/api.ts
Normal file
65
src/types/api.ts
Normal 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;
|
Loading…
Add table
Reference in a new issue