chatApi.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import type { CreateChatRequest, ChatResponse, ApiResponse } from "../types/chat"
  2. export const chatApi = {
  3. async createChat(
  4. request: CreateChatRequest
  5. ): Promise<ApiResponse<ChatResponse>> {
  6. const response = await fetch("/api/v2/chats", {
  7. method: "POST",
  8. headers: { "Content-Type": "application/json" },
  9. body: JSON.stringify(request),
  10. });
  11. return response.json();
  12. },
  13. async getChat(chatId: string): Promise<ApiResponse<ChatResponse>> {
  14. const response = await fetch(`/api/v2/chats/${chatId}`);
  15. return response.json();
  16. },
  17. async updateChat(
  18. chatId: string,
  19. updates: Partial<CreateChatRequest>
  20. ): Promise<ApiResponse<ChatResponse>> {
  21. const response = await fetch(`/api/v2/chats/${chatId}`, {
  22. method: "PUT",
  23. headers: { "Content-Type": "application/json" },
  24. body: JSON.stringify(updates),
  25. });
  26. return response.json();
  27. },
  28. async deleteChat(chatId: string): Promise<ApiResponse<void>> {
  29. const response = await fetch(`/api/v2/chats/${chatId}`, {
  30. method: "DELETE",
  31. });
  32. return response.json();
  33. },
  34. };