From ef2fa6fe5cd7c02a614e6934f7c3e586669f2f01 Mon Sep 17 00:00:00 2001 From: tone Date: Fri, 19 Dec 2025 19:04:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource/components/ResourceCard.tsx | 4 ++-- .../app/console/(with-menu)/user/list/page.tsx | 4 ++-- .../web/resource/components/AddResource.tsx | 4 ++-- .../web/resource/components/ResourceEdit.tsx | 8 ++++---- .../admin/web/resource/use-resource-list.ts | 4 ++-- .../lib/api/endpoints/resource.server.ts | 17 ++--------------- apps/frontend/lib/types/resource.ts | 11 +++++++++++ 7 files changed, 25 insertions(+), 27 deletions(-) diff --git a/apps/frontend/app/(with-header-footer)/resource/components/ResourceCard.tsx b/apps/frontend/app/(with-header-footer)/resource/components/ResourceCard.tsx index 7176cf9..79f382a 100644 --- a/apps/frontend/app/(with-header-footer)/resource/components/ResourceCard.tsx +++ b/apps/frontend/app/(with-header-footer)/resource/components/ResourceCard.tsx @@ -1,10 +1,10 @@ import { ResourceBadge } from "@/components/resource"; import { Card, CardContent } from "@/components/ui/card"; -import { Resource } from "@/lib/types/resource"; +import { PublicResource } from "@/lib/types/resource"; import ResourceCardImage from "./ResourceCardImage"; interface ResourceCardProps extends React.HTMLProps { - r: Resource; + r: PublicResource; } export function ResourceCard({ r, ...props }: ResourceCardProps) { diff --git a/apps/frontend/app/console/(with-menu)/user/list/page.tsx b/apps/frontend/app/console/(with-menu)/user/list/page.tsx index 93b8444..2afdc9c 100644 --- a/apps/frontend/app/console/(with-menu)/user/list/page.tsx +++ b/apps/frontend/app/console/(with-menu)/user/list/page.tsx @@ -9,9 +9,9 @@ import { UserInfoEditor } from "./components/user-info-editor"; import { User } from "@/lib/types/user"; import { CreateUserEditor } from "./components/create-user-editor"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog"; -import { AdminApi } from "@/lib/api"; import { toast } from "sonner"; import { ApiError } from "next/dist/server/api-utils"; +import { AdminAPI } from "@/lib/api/client"; export default function Page() { @@ -56,7 +56,7 @@ export default function Page() { const [deletedUserId, setDeletedUserId] = useState(''); const handleUserDelete = async (userId: string) => { try { - await AdminApi.user.remove(userId, false); + await AdminAPI.removeUser(userId, false); toast.success('删除成功'); handleUserDeleteLocal(userId, false); setDeletedUserId(''); diff --git a/apps/frontend/app/console/(with-menu)/web/resource/components/AddResource.tsx b/apps/frontend/app/console/(with-menu)/web/resource/components/AddResource.tsx index 381a191..047f9cd 100644 --- a/apps/frontend/app/console/(with-menu)/web/resource/components/AddResource.tsx +++ b/apps/frontend/app/console/(with-menu)/web/resource/components/AddResource.tsx @@ -13,13 +13,13 @@ import { import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Button } from "@/components/ui/button" -import { AdminApi } from "@/lib/api" import { toast } from "sonner" import { ApiError } from "next/dist/server/api-utils" import { ResourceBadge } from "@/components/resource" import AddResourceTag from "./AddResourceTag" import { Textarea } from "@/components/ui/textarea" import { Plus } from "lucide-react" +import { AdminAPI } from "@/lib/api/client" interface AddResourceProps { @@ -42,7 +42,7 @@ export default function AddResource({ children, refresh }: AddResourceProps) { const handleSubmit = async () => { try { setLoading(true); - await AdminApi.web.resource.create({ + await AdminAPI.createResource({ ...formData, }); toast.success("添加成功"); diff --git a/apps/frontend/app/console/(with-menu)/web/resource/components/ResourceEdit.tsx b/apps/frontend/app/console/(with-menu)/web/resource/components/ResourceEdit.tsx index 446199d..62233f5 100644 --- a/apps/frontend/app/console/(with-menu)/web/resource/components/ResourceEdit.tsx +++ b/apps/frontend/app/console/(with-menu)/web/resource/components/ResourceEdit.tsx @@ -18,7 +18,6 @@ import AddResourceTag from "./AddResourceTag" import { Textarea } from "@/components/ui/textarea" import { Plus } from "lucide-react" import { Resource } from "@/lib/types/resource" -import { AdminApi } from "@/lib/api" import useSWR from "swr" import { ApiError } from "next/dist/server/api-utils" import { Skeleton } from "@/components/ui/skeleton" @@ -33,6 +32,7 @@ import { AlertDialogTitle, AlertDialogTrigger, } from "@/components/ui/alert-dialog" +import { AdminAPI } from "@/lib/api/client" interface ResourceEditProps { children: React.ReactNode @@ -45,7 +45,7 @@ export default function ResourceEdit({ children, id, onRefresh }: ResourceEditPr const { data: resource, isLoading, mutate } = useSWR( open ? [`/api/admin/web/resource/${id}`] : null, - () => AdminApi.web.resource.get(id), + () => AdminAPI.getResource(id), { revalidateOnFocus: false, revalidateOnReconnect: false, @@ -57,7 +57,7 @@ export default function ResourceEdit({ children, id, onRefresh }: ResourceEditPr const handleSubmit = async () => { if (!resource) return; try { - await AdminApi.web.resource.update(id, { + await AdminAPI.updateResource(id, { title: resource.title, description: resource.description, imageUrl: resource.imageUrl, @@ -74,7 +74,7 @@ export default function ResourceEdit({ children, id, onRefresh }: ResourceEditPr const handleRemove = async (id: string) => { try { - await AdminApi.web.resource.remove(id); + await AdminAPI.removeResource(id); toast.success("资源删除成功"); onRefresh(); setOpen(false); diff --git a/apps/frontend/hooks/admin/web/resource/use-resource-list.ts b/apps/frontend/hooks/admin/web/resource/use-resource-list.ts index b61c42b..4202617 100644 --- a/apps/frontend/hooks/admin/web/resource/use-resource-list.ts +++ b/apps/frontend/hooks/admin/web/resource/use-resource-list.ts @@ -1,6 +1,6 @@ "use client" -import { AdminApi } from "@/lib/api"; +import { AdminAPI } from "@/lib/api/client"; import { useCallback } from "react"; import { toast } from "sonner"; import useSWR from "swr"; @@ -8,7 +8,7 @@ import useSWR from "swr"; export function useResourceList() { const { data, error, isLoading, mutate } = useSWR( ['/admin/web/resource'], - () => AdminApi.web.resource.list(), + () => AdminAPI.listResources(), { onError: (e) => { toast.error(`${e.message || e}`) diff --git a/apps/frontend/lib/api/endpoints/resource.server.ts b/apps/frontend/lib/api/endpoints/resource.server.ts index 776944b..5923139 100644 --- a/apps/frontend/lib/api/endpoints/resource.server.ts +++ b/apps/frontend/lib/api/endpoints/resource.server.ts @@ -1,19 +1,6 @@ +import { PublicResource } from "@/lib/types/resource"; import { serverFetch } from "../server"; -export type ResourceTagType = { - name: string; - type: string; -} - -export interface Resource { - id: string; - title: string; - description: string; - imageUrl: string; - link: string; - tags: ResourceTagType[]; -} - export async function list() { - return serverFetch('/api/resource') + return serverFetch('/api/resource') } \ No newline at end of file diff --git a/apps/frontend/lib/types/resource.ts b/apps/frontend/lib/types/resource.ts index 107ea44..e47a065 100644 --- a/apps/frontend/lib/types/resource.ts +++ b/apps/frontend/lib/types/resource.ts @@ -3,6 +3,15 @@ export type TagType = { type: string; } +export interface PublicResource { + id: string; + title: string; + description: string; + imageUrl: string; + link: string; + tags: TagType[]; +} + export interface Resource { id: string; title: string; @@ -10,4 +19,6 @@ export interface Resource { imageUrl: string; link: string; tags: TagType[]; + createdAt: Date; + updatedAt: Date; } \ No newline at end of file