Browse Source

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
master
dark 1 month ago
parent
commit
02299dfaa1
  1. 46
      frontend/react-shadcn/pc/src/services/api.ts
  2. 22
      frontend/react-shadcn/pc/src/types/index.ts

46
frontend/react-shadcn/pc/src/services/api.ts

@ -7,6 +7,11 @@ import type {
UserListResponse, UserListResponse,
CreateUserRequest, CreateUserRequest,
UpdateUserRequest, UpdateUserRequest,
Profile,
DashboardStats,
Activity,
UpdateProfileRequest,
ChangePasswordRequest,
} from '@/types' } from '@/types'
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8888/api/v1' const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8888/api/v1'
@ -63,7 +68,7 @@ class ApiClient {
// Auth // Auth
async login(credentials: LoginRequest): Promise<LoginResponse> { async login(credentials: LoginRequest): Promise<LoginResponse> {
const response = await this.request<LoginResponse>('/auth/login', { const response = await this.request<LoginResponse>('/login', {
method: 'POST', method: 'POST',
body: JSON.stringify(credentials), body: JSON.stringify(credentials),
}) })
@ -80,7 +85,7 @@ class ApiClient {
} }
async refreshToken(refreshToken: string): Promise<LoginResponse> { async refreshToken(refreshToken: string): Promise<LoginResponse> {
return this.request<LoginResponse>('/auth/refresh', { return this.request<LoginResponse>('/refresh', {
method: 'POST', method: 'POST',
body: JSON.stringify({ token: refreshToken }), body: JSON.stringify({ token: refreshToken }),
}) })
@ -93,36 +98,59 @@ class ApiClient {
if (params.pageSize) queryParams.append('pageSize', params.pageSize.toString()) if (params.pageSize) queryParams.append('pageSize', params.pageSize.toString())
if (params.keyword) queryParams.append('keyword', params.keyword) if (params.keyword) queryParams.append('keyword', params.keyword)
return this.request<UserListResponse>(`/user/users?${queryParams}`) return this.request<UserListResponse>(`/users?${queryParams}`)
} }
async getUser(id: number): Promise<ApiResponse<User>> { async getUser(id: number): Promise<ApiResponse<User>> {
return this.request<ApiResponse<User>>(`/user/user/${id}`) return this.request<ApiResponse<User>>(`/user/${id}`)
} }
async createUser(data: CreateUserRequest): Promise<ApiResponse<User>> { async createUser(data: CreateUserRequest): Promise<ApiResponse<User>> {
return this.request<ApiResponse<User>>('/user/user', { return this.request<ApiResponse<User>>('/user', {
method: 'POST', method: 'POST',
body: JSON.stringify(data), body: JSON.stringify(data),
}) })
} }
async updateUser(id: number, data: UpdateUserRequest): Promise<ApiResponse<User>> { async updateUser(id: number, data: UpdateUserRequest): Promise<ApiResponse<User>> {
return this.request<ApiResponse<User>>(`/user/user/${id}`, { return this.request<ApiResponse<User>>(`/user/${id}`, {
method: 'PUT', method: 'PUT',
body: JSON.stringify(data), body: JSON.stringify(data),
}) })
} }
async deleteUser(id: number): Promise<ApiResponse<void>> { async deleteUser(id: number): Promise<ApiResponse<void>> {
return this.request<ApiResponse<void>>(`/user/user/${id}`, { return this.request<ApiResponse<void>>(`/user/${id}`, {
method: 'DELETE', method: 'DELETE',
}) })
} }
// Profile // Profile
async getProfile(): Promise<ApiResponse> { async getProfile(): Promise<ApiResponse<Profile>> {
return this.request<ApiResponse>('/profile/me') return this.request<ApiResponse<Profile>>('/profile/me')
}
async updateProfile(data: UpdateProfileRequest): Promise<ApiResponse<Profile>> {
return this.request<ApiResponse<Profile>>('/profile/me', {
method: 'PUT',
body: JSON.stringify(data),
})
}
async changePassword(data: ChangePasswordRequest): Promise<ApiResponse<void>> {
return this.request<ApiResponse<void>>('/profile/password', {
method: 'POST',
body: JSON.stringify(data),
})
}
// Dashboard
async getDashboardStats(): Promise<ApiResponse<DashboardStats>> {
return this.request<ApiResponse<DashboardStats>>('/dashboard/stats')
}
async getRecentActivities(limit: number = 10): Promise<ApiResponse<Activity[]>> {
return this.request<ApiResponse<Activity[]>>(`/dashboard/activities?limit=${limit}`)
} }
// Health check // Health check

22
frontend/react-shadcn/pc/src/types/index.ts

@ -85,12 +85,30 @@ export interface Profile {
} }
export interface UpdateProfileRequest { export interface UpdateProfileRequest {
bio?: string username?: string
avatar?: string
phone?: string phone?: string
avatar?: string
bio?: string
} }
export interface ChangePasswordRequest { export interface ChangePasswordRequest {
oldPassword: string oldPassword: string
newPassword: 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
}

Loading…
Cancel
Save