feat: 优化项目目录结构
This commit is contained in:
20
apps/frontend/lib/api/admin/user/create.ts
Normal file
20
apps/frontend/lib/api/admin/user/create.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { User } from "@/lib/types/user";
|
||||
import fetcher from "../../fetcher";
|
||||
|
||||
interface createUserParams {
|
||||
username: string | null;
|
||||
nickname: string | null;
|
||||
email: string | null;
|
||||
phone: string | null;
|
||||
password: string | null;
|
||||
}
|
||||
|
||||
export async function create(data: createUserParams) {
|
||||
return fetcher<User>("/api/admin/user", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
}
|
||||
6
apps/frontend/lib/api/admin/user/get.ts
Normal file
6
apps/frontend/lib/api/admin/user/get.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { User } from "@/lib/types/user";
|
||||
import fetcher from "../../fetcher";
|
||||
|
||||
export function get(userId: string) {
|
||||
return fetcher<User>(`/api/admin/user/${userId}`);
|
||||
}
|
||||
6
apps/frontend/lib/api/admin/user/index.ts
Normal file
6
apps/frontend/lib/api/admin/user/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export * from './list';
|
||||
export * from './get';
|
||||
export * from './create';
|
||||
export * from './update';
|
||||
export * from './set-password';
|
||||
export * from './remove';
|
||||
22
apps/frontend/lib/api/admin/user/list.ts
Normal file
22
apps/frontend/lib/api/admin/user/list.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { User } from "@/lib/types/user"
|
||||
import fetcher from "../../fetcher"
|
||||
|
||||
export interface UserListParams {
|
||||
page?: number
|
||||
pageSize?: number
|
||||
}
|
||||
|
||||
export interface UserListResponse {
|
||||
items: User[],
|
||||
total: number
|
||||
page: number
|
||||
pageSize: number
|
||||
}
|
||||
|
||||
export function list(params?: UserListParams): Promise<UserListResponse> {
|
||||
const searchParams = new URLSearchParams()
|
||||
if (params?.page) searchParams.set('page', params.page.toString())
|
||||
if (params?.pageSize) searchParams.set('pageSize', params.pageSize.toString())
|
||||
|
||||
return fetcher<UserListResponse>('/api/admin/user')
|
||||
}
|
||||
7
apps/frontend/lib/api/admin/user/remove.ts
Normal file
7
apps/frontend/lib/api/admin/user/remove.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import fetcher from "../../fetcher";
|
||||
|
||||
export async function remove(userId: string, soft: boolean) {
|
||||
return fetcher(`/api/admin/user/${userId}?soft=${soft}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
}
|
||||
10
apps/frontend/lib/api/admin/user/set-password.ts
Normal file
10
apps/frontend/lib/api/admin/user/set-password.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import fetcher from "../../fetcher";
|
||||
|
||||
export async function setPassword(userId: string, password: string) {
|
||||
return fetcher(`/api/admin/user/${userId}/password`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
password,
|
||||
}),
|
||||
})
|
||||
}
|
||||
16
apps/frontend/lib/api/admin/user/update.ts
Normal file
16
apps/frontend/lib/api/admin/user/update.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { User } from "@/lib/types/user";
|
||||
import fetcher from "../../fetcher";
|
||||
|
||||
export type updateUser = {
|
||||
username: string ;
|
||||
nickname: string ;
|
||||
email: string | null;
|
||||
phone: string | null;
|
||||
}
|
||||
|
||||
export async function update(userId: string, user: updateUser) {
|
||||
return fetcher<User>(`/api/admin/user/${userId}`, {
|
||||
body: JSON.stringify(user),
|
||||
method: "PUT",
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user