From 02299dfaa185eb7c39114d4d0c0ed0b4171835b7 Mon Sep 17 00:00:00 2001 From: dark Date: Fri, 13 Feb 2026 21:22:32 +0800 Subject: [PATCH] Add Profile and Dashboard API methods and types - Add getProfile(), updateProfile(), changePassword() methods to apiClient - Add getDashboardStats(), getRecentActivities() methods to apiClient - Add DashboardStats and Activity types - Update UpdateProfileRequest to include username field --- frontend/react-shadcn/pc/src/services/api.ts | 46 ++++++++++++++++---- frontend/react-shadcn/pc/src/types/index.ts | 22 +++++++++- 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/frontend/react-shadcn/pc/src/services/api.ts b/frontend/react-shadcn/pc/src/services/api.ts index d8c12e0..88355b6 100644 --- a/frontend/react-shadcn/pc/src/services/api.ts +++ b/frontend/react-shadcn/pc/src/services/api.ts @@ -7,6 +7,11 @@ import type { UserListResponse, CreateUserRequest, UpdateUserRequest, + Profile, + DashboardStats, + Activity, + UpdateProfileRequest, + ChangePasswordRequest, } from '@/types' const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8888/api/v1' @@ -63,7 +68,7 @@ class ApiClient { // Auth async login(credentials: LoginRequest): Promise { - const response = await this.request('/auth/login', { + const response = await this.request('/login', { method: 'POST', body: JSON.stringify(credentials), }) @@ -80,7 +85,7 @@ class ApiClient { } async refreshToken(refreshToken: string): Promise { - return this.request('/auth/refresh', { + return this.request('/refresh', { method: 'POST', body: JSON.stringify({ token: refreshToken }), }) @@ -93,36 +98,59 @@ class ApiClient { if (params.pageSize) queryParams.append('pageSize', params.pageSize.toString()) if (params.keyword) queryParams.append('keyword', params.keyword) - return this.request(`/user/users?${queryParams}`) + return this.request(`/users?${queryParams}`) } async getUser(id: number): Promise> { - return this.request>(`/user/user/${id}`) + return this.request>(`/user/${id}`) } async createUser(data: CreateUserRequest): Promise> { - return this.request>('/user/user', { + return this.request>('/user', { method: 'POST', body: JSON.stringify(data), }) } async updateUser(id: number, data: UpdateUserRequest): Promise> { - return this.request>(`/user/user/${id}`, { + return this.request>(`/user/${id}`, { method: 'PUT', body: JSON.stringify(data), }) } async deleteUser(id: number): Promise> { - return this.request>(`/user/user/${id}`, { + return this.request>(`/user/${id}`, { method: 'DELETE', }) } // Profile - async getProfile(): Promise { - return this.request('/profile/me') + async getProfile(): Promise> { + return this.request>('/profile/me') + } + + async updateProfile(data: UpdateProfileRequest): Promise> { + return this.request>('/profile/me', { + method: 'PUT', + body: JSON.stringify(data), + }) + } + + async changePassword(data: ChangePasswordRequest): Promise> { + return this.request>('/profile/password', { + method: 'POST', + body: JSON.stringify(data), + }) + } + + // Dashboard + async getDashboardStats(): Promise> { + return this.request>('/dashboard/stats') + } + + async getRecentActivities(limit: number = 10): Promise> { + return this.request>(`/dashboard/activities?limit=${limit}`) } // Health check diff --git a/frontend/react-shadcn/pc/src/types/index.ts b/frontend/react-shadcn/pc/src/types/index.ts index fa5bbd4..b1061e0 100644 --- a/frontend/react-shadcn/pc/src/types/index.ts +++ b/frontend/react-shadcn/pc/src/types/index.ts @@ -85,12 +85,30 @@ export interface Profile { } export interface UpdateProfileRequest { - bio?: string - avatar?: string + username?: string phone?: string + avatar?: string + bio?: string } export interface ChangePasswordRequest { oldPassword: string newPassword: string } + +// Dashboard Types +export interface DashboardStats { + totalUsers: number + activeUsers: number + systemLoad: number + dbStatus: string + userGrowth: number +} + +export interface Activity { + id: number + user: string + action: string + time: string + status: string +}