| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import axios from 'axios';
- import type { UserMessage, Message } from '../../share/types.ts';
- interface MessagesResponse {
- data: UserMessage[];
- pagination: {
- total: number;
- current: number;
- pageSize: number;
- totalPages: number;
- };
- }
- interface MessageResponse {
- data: Message;
- message?: string;
- }
- interface MessageCountResponse {
- count: number;
- }
- export const MessageAPI = {
- getMessages: async (params?: {
- page?: number,
- pageSize?: number,
- type?: string,
- status?: string,
- search?: string
- }): Promise<MessagesResponse> => {
- try {
- const response = await axios.get('/messages', { params });
- return response.data;
- } catch (error) {
- throw error;
- }
- },
- sendMessage: async (data: {
- title: string,
- content: string,
- type: string,
- receiver_ids: number[]
- }): Promise<MessageResponse> => {
- try {
- const response = await axios.post('/messages', data);
- return response.data;
- } catch (error) {
- throw error;
- }
- },
- getUnreadCount: async (): Promise<MessageCountResponse> => {
- try {
- const response = await axios.get('/messages/count/unread');
- return response.data;
- } catch (error) {
- throw error;
- }
- },
- markAsRead: async (id: number): Promise<MessageResponse> => {
- try {
- const response = await axios.post(`/messages/${id}/read`);
- return response.data;
- } catch (error) {
- throw error;
- }
- },
- deleteMessage: async (id: number): Promise<MessageResponse> => {
- try {
- const response = await axios.delete(`/messages/${id}`);
- return response.data;
- } catch (error) {
- throw error;
- }
- }
- };
|