From 8a0792500ebc967acc4771cba760cefeea21c4f8 Mon Sep 17 00:00:00 2001 From: xujiang Date: Fri, 11 Jul 2025 16:08:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90API=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E9=9A=94=E7=A6=BB=E8=AE=BE=E8=AE=A1=E5=92=8C=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🚀 主要功能: - 创建前端公共展示API (/api/v1/public/*) - 创建前端用户认证API (/api/v1/auth/*) - 创建管理后台完整API (/admin/*) - 实现双重认证体系设计 📋 新增文件: - api/desc/frontend/public.api - 前端公共接口定义 - api/desc/frontend/auth.api - 前端认证接口定义 - api/desc/admin.api - 管理后台主入口 - api/desc/admin/auth.api - 管理员认证接口 - api/desc/admin/users.api - 用户管理接口 - api/desc/admin/photos.api - 照片管理接口 - api/desc/admin/categories.api - 分类管理接口 - api/desc/admin/dashboard.api - 仪表板统计接口 🔧 更新文件: - api/desc/common.api - 扩展类型定义支持前端和管理后台 - api/desc/photography.api - 更新为前端主入口 - etc/photographyapi-api.yaml - 修复中间件配置 📚 文档: - docs/API_SEPARATION_DESIGN.md - 接口隔离设计方案 - docs/API_REFACTORING_TASKS.md - 详细任务规划 - docs/COMPLETED_TASKS_ARCHIVE.md - 已完成任务归档 ✨ 特性亮点: - 前端和管理后台权限完全隔离 - 优化的数据结构去除敏感信息 - 完整的CRUD和统计功能 - 支持批量操作和高级筛选 - 详细的仪表板分析功能 --- backend/api/desc/admin.api | 16 + backend/api/desc/admin/auth.api | 116 +++++++ backend/api/desc/admin/categories.api | 236 ++++++++++++++ backend/api/desc/admin/dashboard.api | 254 +++++++++++++++ backend/api/desc/admin/photos.api | 216 +++++++++++++ backend/api/desc/admin/users.api | 199 ++++++++++++ backend/api/desc/common.api | 165 ++++++++++ backend/api/desc/frontend/auth.api | 109 +++++++ backend/api/desc/frontend/public.api | 117 +++++++ backend/api/desc/photography.api | 10 +- backend/docs/API_REFACTORING_TASKS.md | 396 ++++++++++++++++++++++++ backend/docs/API_SEPARATION_DESIGN.md | 223 +++++++++++++ backend/docs/COMPLETED_TASKS_ARCHIVE.md | 89 ++++++ backend/etc/photographyapi-api.yaml | 8 + backend/go.mod | 4 +- backend/hash_password.go | 17 - 16 files changed, 2150 insertions(+), 25 deletions(-) create mode 100644 backend/api/desc/admin.api create mode 100644 backend/api/desc/admin/auth.api create mode 100644 backend/api/desc/admin/categories.api create mode 100644 backend/api/desc/admin/dashboard.api create mode 100644 backend/api/desc/admin/photos.api create mode 100644 backend/api/desc/admin/users.api create mode 100644 backend/api/desc/frontend/auth.api create mode 100644 backend/api/desc/frontend/public.api create mode 100644 backend/docs/API_REFACTORING_TASKS.md create mode 100644 backend/docs/API_SEPARATION_DESIGN.md create mode 100644 backend/docs/COMPLETED_TASKS_ARCHIVE.md delete mode 100644 backend/hash_password.go diff --git a/backend/api/desc/admin.api b/backend/api/desc/admin.api new file mode 100644 index 0000000..a1474cb --- /dev/null +++ b/backend/api/desc/admin.api @@ -0,0 +1,16 @@ +syntax = "v1" + +info ( + title: "Photography Admin API" + desc: "摄影作品集管理后台 API 服务" + author: "Photography Team" + email: "admin@photography.com" + version: "v1.0.0" +) + +import "common.api" +import "admin/auth.api" +import "admin/users.api" +import "admin/photos.api" +import "admin/categories.api" +import "admin/dashboard.api" \ No newline at end of file diff --git a/backend/api/desc/admin/auth.api b/backend/api/desc/admin/auth.api new file mode 100644 index 0000000..cd71e26 --- /dev/null +++ b/backend/api/desc/admin/auth.api @@ -0,0 +1,116 @@ +syntax = "v1" + +import "common.api" + +// 管理员认证接口 - 强认证 + +// 管理员登录请求 +type AdminLoginRequest { + Username string `json:"username" validate:"required"` + Password string `json:"password" validate:"required"` + Captcha string `json:"captcha,optional"` // 验证码 (可选) +} + +// 管理员登录响应 +type AdminLoginResponse { + BaseResponse + Data AdminLoginData `json:"data"` +} + +type AdminLoginData { + Token string `json:"token"` + RefreshToken string `json:"refresh_token"` + Admin Admin `json:"admin"` + ExpiresIn int64 `json:"expires_in"` // Token 过期时间 (秒) +} + +// 管理员 Token 刷新请求 +type AdminRefreshTokenRequest { + RefreshToken string `json:"refresh_token" validate:"required"` +} + +// 管理员 Token 刷新响应 +type AdminRefreshTokenResponse { + BaseResponse + Data AdminRefreshTokenData `json:"data"` +} + +type AdminRefreshTokenData { + Token string `json:"token"` + RefreshToken string `json:"refresh_token"` + ExpiresIn int64 `json:"expires_in"` +} + +// 管理员信息响应 +type AdminProfileResponse { + BaseResponse + Data Admin `json:"data"` +} + +// 管理员更新信息请求 +type UpdateAdminProfileRequest { + Username string `json:"username,optional"` + Email string `json:"email,optional"` + Avatar string `json:"avatar,optional"` +} + +// 管理员更新信息响应 +type UpdateAdminProfileResponse { + BaseResponse + Data Admin `json:"data"` +} + +// 管理员修改密码请求 +type ChangeAdminPasswordRequest { + OldPassword string `json:"old_password" validate:"required"` + NewPassword string `json:"new_password" validate:"required,min=8"` +} + +// 管理员修改密码响应 +type ChangeAdminPasswordResponse { + BaseResponse +} + +// 管理员登出响应 +type AdminLogoutResponse { + BaseResponse +} + +// 管理员认证接口组 - 无需认证 +@server( + group: admin_auth + prefix: /admin/auth +) +service photography-api { + @doc "管理员登录" + @handler adminLogin + post /login (AdminLoginRequest) returns (AdminLoginResponse) + + @doc "刷新管理员Token" + @handler adminRefreshToken + post /refresh (AdminRefreshTokenRequest) returns (AdminRefreshTokenResponse) +} + +// 管理员认证接口组 - 需要认证 +@server( + group: admin_auth + prefix: /admin/auth + jwt: AdminAuth +) +service photography-api { + @doc "获取管理员信息" + @handler getAdminProfile + get /profile returns (AdminProfileResponse) + + @doc "更新管理员信息" + @handler updateAdminProfile + put /profile (UpdateAdminProfileRequest) returns (UpdateAdminProfileResponse) + + @doc "修改管理员密码" + @handler changeAdminPassword + post /change-password (ChangeAdminPasswordRequest) returns (ChangeAdminPasswordResponse) + + @doc "管理员登出" + @handler adminLogout + post /logout returns (AdminLogoutResponse) +} \ No newline at end of file diff --git a/backend/api/desc/admin/categories.api b/backend/api/desc/admin/categories.api new file mode 100644 index 0000000..c7f660b --- /dev/null +++ b/backend/api/desc/admin/categories.api @@ -0,0 +1,236 @@ +syntax = "v1" + +import "common.api" + +// 管理后台分类管理接口 + +// 获取分类列表请求 +type GetAdminCategoryListRequest { + PageRequest + Keyword string `form:"keyword,optional"` + Status string `form:"status,optional"` // active, inactive + SortBy string `form:"sort_by,optional,default=sort_order_asc"` // 排序方式 + WithStats bool `form:"with_stats,optional"` // 是否包含统计信息 +} + +// 获取分类列表响应 +type GetAdminCategoryListResponse { + BaseResponse + Data AdminCategoryListData `json:"data"` +} + +type AdminCategoryListData { + PageResponse + Categories []AdminCategory `json:"categories"` +} + +// 获取分类详情请求 +type GetAdminCategoryRequest { + Id int64 `path:"id"` +} + +// 获取分类详情响应 +type GetAdminCategoryResponse { + BaseResponse + Data AdminCategoryDetail `json:"data"` +} + +// 创建分类请求 +type CreateAdminCategoryRequest { + Name string `json:"name" validate:"required"` + Description string `json:"description,optional"` + SortOrder int `json:"sort_order,optional,default=0"` // 排序权重 + Status string `json:"status,optional,default=active"` // active, inactive + CoverImage string `json:"cover_image,optional"` // 分类封面图 +} + +// 创建分类响应 +type CreateAdminCategoryResponse { + BaseResponse + Data AdminCategory `json:"data"` +} + +// 更新分类请求 +type UpdateAdminCategoryRequest { + Id int64 `path:"id"` + Name string `json:"name,optional"` + Description string `json:"description,optional"` + SortOrder int `json:"sort_order,optional"` + Status string `json:"status,optional"` + CoverImage string `json:"cover_image,optional"` +} + +// 更新分类响应 +type UpdateAdminCategoryResponse { + BaseResponse + Data AdminCategory `json:"data"` +} + +// 删除分类请求 +type DeleteAdminCategoryRequest { + Id int64 `path:"id"` +} + +// 删除分类响应 +type DeleteAdminCategoryResponse { + BaseResponse +} + +// 分类排序请求 +type SortAdminCategoriesRequest { + Categories []AdminCategorySortItem `json:"categories" validate:"required"` +} + +type AdminCategorySortItem { + Id int64 `json:"id" validate:"required"` + SortOrder int `json:"sort_order" validate:"required"` +} + +// 分类排序响应 +type SortAdminCategoriesResponse { + BaseResponse +} + +// 更新分类状态请求 +type UpdateAdminCategoryStatusRequest { + Id int64 `path:"id"` + Status string `json:"status" validate:"required"` // active, inactive +} + +// 更新分类状态响应 +type UpdateAdminCategoryStatusResponse { + BaseResponse + Data AdminCategory `json:"data"` +} + +// 批量操作分类请求 +type BatchAdminCategoryOperationRequest { + CategoryIds []int64 `json:"category_ids" validate:"required"` + Operation string `json:"operation" validate:"required"` // activate, deactivate, delete +} + +// 批量操作分类响应 +type BatchAdminCategoryOperationResponse { + BaseResponse + Data BatchAdminCategoryOperationData `json:"data"` +} + +type BatchAdminCategoryOperationData { + SuccessCount int `json:"success_count"` + FailedCount int `json:"failed_count"` + FailedIds []int64 `json:"failed_ids"` +} + +// 分类统计请求 +type GetAdminCategoryStatsRequest { + DateRange string `form:"date_range,optional,default=7d"` // 7d, 30d, 90d +} + +// 分类统计响应 +type GetAdminCategoryStatsResponse { + BaseResponse + Data AdminCategoryStatsData `json:"data"` +} + +type AdminCategoryStatsData { + TotalCategories int64 `json:"total_categories"` + ActiveCategories int64 `json:"active_categories"` + EmptyCategories int64 `json:"empty_categories"` // 没有照片的分类 + NewCategories int64 `json:"new_categories"` // 指定时间范围内新增分类 + PopularCategories []AdminCategoryPopularItem `json:"popular_categories"` // 热门分类 +} + +type AdminCategoryPopularItem { + Id int64 `json:"id"` + Name string `json:"name"` + PhotoCount int64 `json:"photo_count"` + ViewCount int64 `json:"view_count"` +} + +// 分类照片统计请求 +type GetAdminCategoryPhotoStatsRequest { + Id int64 `path:"id"` +} + +// 分类照片统计响应 +type GetAdminCategoryPhotoStatsResponse { + BaseResponse + Data AdminCategoryPhotoStatsData `json:"data"` +} + +type AdminCategoryPhotoStatsData { + CategoryId int64 `json:"category_id"` + TotalPhotos int64 `json:"total_photos"` + PublishedPhotos int64 `json:"published_photos"` + DraftPhotos int64 `json:"draft_photos"` + FeaturedPhotos int64 `json:"featured_photos"` + TotalViews int64 `json:"total_views"` + RecentPhotos []AdminPhoto `json:"recent_photos"` // 最近上传的照片 +} + +// 上传分类封面图请求 +type UploadAdminCategoryCoverRequest { + Id int64 `path:"id"` +} + +// 上传分类封面图响应 +type UploadAdminCategoryCoverResponse { + BaseResponse + Data UploadAdminCategoryCoverData `json:"data"` +} + +type UploadAdminCategoryCoverData { + CoverImageUrl string `json:"cover_image_url"` +} + +// 管理后台分类管理接口组 - 需要管理员认证 +@server( + group: admin_categories + prefix: /admin/categories + jwt: AdminAuth +) +service photography-api { + @doc "获取分类列表" + @handler getAdminCategoryList + get / (GetAdminCategoryListRequest) returns (GetAdminCategoryListResponse) + + @doc "创建分类" + @handler createAdminCategory + post / (CreateAdminCategoryRequest) returns (CreateAdminCategoryResponse) + + @doc "获取分类详情" + @handler getAdminCategory + get /:id (GetAdminCategoryRequest) returns (GetAdminCategoryResponse) + + @doc "更新分类" + @handler updateAdminCategory + put /:id (UpdateAdminCategoryRequest) returns (UpdateAdminCategoryResponse) + + @doc "删除分类" + @handler deleteAdminCategory + delete /:id (DeleteAdminCategoryRequest) returns (DeleteAdminCategoryResponse) + + @doc "更新分类状态" + @handler updateAdminCategoryStatus + put /:id/status (UpdateAdminCategoryStatusRequest) returns (UpdateAdminCategoryStatusResponse) + + @doc "上传分类封面图" + @handler uploadAdminCategoryCover + post /:id/cover (UploadAdminCategoryCoverRequest) returns (UploadAdminCategoryCoverResponse) + + @doc "获取分类照片统计" + @handler getAdminCategoryPhotoStats + get /:id/photo-stats (GetAdminCategoryPhotoStatsRequest) returns (GetAdminCategoryPhotoStatsResponse) + + @doc "分类排序" + @handler sortAdminCategories + post /sort (SortAdminCategoriesRequest) returns (SortAdminCategoriesResponse) + + @doc "批量操作分类" + @handler batchAdminCategoryOperation + post /batch (BatchAdminCategoryOperationRequest) returns (BatchAdminCategoryOperationResponse) + + @doc "获取分类统计" + @handler getAdminCategoryStats + get /stats (GetAdminCategoryStatsRequest) returns (GetAdminCategoryStatsResponse) +} \ No newline at end of file diff --git a/backend/api/desc/admin/dashboard.api b/backend/api/desc/admin/dashboard.api new file mode 100644 index 0000000..17c02c2 --- /dev/null +++ b/backend/api/desc/admin/dashboard.api @@ -0,0 +1,254 @@ +syntax = "v1" + +import "common.api" + +// 管理后台仪表板接口 + +// 获取仪表板统计请求 +type GetAdminDashboardStatsRequest { + DateRange string `form:"date_range,optional,default=7d"` // 7d, 30d, 90d, 1y +} + +// 获取仪表板统计响应 +type GetAdminDashboardStatsResponse { + BaseResponse + Data AdminDashboardStatsData `json:"data"` +} + +type AdminDashboardStatsData { + // 总体统计 + TotalUsers int64 `json:"total_users"` + TotalPhotos int64 `json:"total_photos"` + TotalCategories int64 `json:"total_categories"` + TotalViews int64 `json:"total_views"` + + // 增长统计 + UserGrowth AdminGrowthData `json:"user_growth"` + PhotoGrowth AdminGrowthData `json:"photo_growth"` + CategoryGrowth AdminGrowthData `json:"category_growth"` + ViewGrowth AdminGrowthData `json:"view_growth"` + + // 存储统计 + StorageStats AdminStorageStatsData `json:"storage_stats"` + + // 最新动态 + RecentActivities []AdminActivityData `json:"recent_activities"` +} + +type AdminGrowthData { + Current int64 `json:"current"` // 当前数量 + Previous int64 `json:"previous"` // 之前同期数量 + Growth int64 `json:"growth"` // 增长数量 + GrowthRate float64 `json:"growth_rate"` // 增长率 +} + +type AdminStorageStatsData { + TotalSize int64 `json:"total_size"` // 总存储大小 (字节) + UsedSize int64 `json:"used_size"` // 已使用存储 + AvailableSize int64 `json:"available_size"` // 可用存储 + UsageRate float64 `json:"usage_rate"` // 使用率 + PhotosSize int64 `json:"photos_size"` // 照片存储大小 + ThumbnailsSize int64 `json:"thumbnails_size"` // 缩略图存储大小 + AvatarsSize int64 `json:"avatars_size"` // 头像存储大小 +} + +type AdminActivityData { + Id int64 `json:"id"` + Type string `json:"type"` // user_register, photo_upload, category_create, admin_login + Description string `json:"description"` + UserId int64 `json:"user_id,optional"` + UserName string `json:"user_name,optional"` + CreatedAt int64 `json:"created_at"` +} + +// 获取分析数据请求 +type GetAdminAnalyticsRequest { + Type string `form:"type" validate:"required"` // users, photos, categories, views + DateRange string `form:"date_range,optional,default=30d"` // 7d, 30d, 90d, 1y + Granularity string `form:"granularity,optional,default=day"` // hour, day, week, month +} + +// 获取分析数据响应 +type GetAdminAnalyticsResponse { + BaseResponse + Data AdminAnalyticsData `json:"data"` +} + +type AdminAnalyticsData { + Type string `json:"type"` + DateRange string `json:"date_range"` + Granularity string `json:"granularity"` + DataPoints []AdminAnalyticsDataPoint `json:"data_points"` + Summary AdminAnalyticsSummary `json:"summary"` +} + +type AdminAnalyticsDataPoint { + Date string `json:"date"` // 日期 (YYYY-MM-DD 或 YYYY-MM-DD HH:mm) + Value int64 `json:"value"` // 数值 + Label string `json:"label,optional"` // 标签 +} + +type AdminAnalyticsSummary { + Total int64 `json:"total"` + Average float64 `json:"average"` + Peak int64 `json:"peak"` + PeakDate string `json:"peak_date"` +} + +// 获取热门内容请求 +type GetAdminPopularContentRequest { + Type string `form:"type" validate:"required"` // photos, categories, users + Period string `form:"period,optional,default=7d"` // 7d, 30d, 90d + Limit int `form:"limit,optional,default=10"` // 返回数量限制 +} + +// 获取热门内容响应 +type GetAdminPopularContentResponse { + BaseResponse + Data AdminPopularContentData `json:"data"` +} + +type AdminPopularContentData { + Type string `json:"type"` + Period string `json:"period"` + Items []AdminPopularContentItem `json:"items"` +} + +type AdminPopularContentItem { + Id int64 `json:"id"` + Title string `json:"title"` + Type string `json:"type"` + ViewCount int64 `json:"view_count"` + LikeCount int64 `json:"like_count,optional"` + CommentCount int64 `json:"comment_count,optional"` + Thumbnail string `json:"thumbnail,optional"` + CreatedAt int64 `json:"created_at"` +} + +// 获取操作日志请求 +type GetAdminOperationLogsRequest { + PageRequest + UserId int64 `form:"user_id,optional"` + Operation string `form:"operation,optional"` // login, create, update, delete + Module string `form:"module,optional"` // user, photo, category, admin + DateRange string `form:"date_range,optional"` // 日期范围 +} + +// 获取操作日志响应 +type GetAdminOperationLogsResponse { + BaseResponse + Data AdminOperationLogsData `json:"data"` +} + +type AdminOperationLogsData { + PageResponse + Logs []AdminOperationLog `json:"logs"` +} + +type AdminOperationLog { + Id int64 `json:"id"` + UserId int64 `json:"user_id"` + UserName string `json:"user_name"` + Operation string `json:"operation"` + Module string `json:"module"` + Target string `json:"target"` // 操作目标 + Description string `json:"description"` + IpAddress string `json:"ip_address"` + UserAgent string `json:"user_agent"` + Status string `json:"status"` // success, failed + ErrorMsg string `json:"error_msg,optional"` + CreatedAt int64 `json:"created_at"` +} + +// 获取系统信息请求 +type GetAdminSystemInfoRequest { +} + +// 获取系统信息响应 +type GetAdminSystemInfoResponse { + BaseResponse + Data AdminSystemInfoData `json:"data"` +} + +type AdminSystemInfoData { + Version string `json:"version"` + BuildTime string `json:"build_time"` + GoVersion string `json:"go_version"` + Os string `json:"os"` + Arch string `json:"arch"` + Uptime int64 `json:"uptime"` // 运行时间 (秒) + Memory AdminMemoryInfo `json:"memory"` + Database AdminDatabaseInfo `json:"database"` + Storage AdminStorageInfo `json:"storage"` +} + +type AdminMemoryInfo { + Allocated int64 `json:"allocated"` // 已分配内存 + TotalAlloc int64 `json:"total_alloc"` // 总分配内存 + System int64 `json:"system"` // 系统内存 + NumGC int64 `json:"num_gc"` // GC 次数 +} + +type AdminDatabaseInfo { + Type string `json:"type"` // sqlite, postgresql + Version string `json:"version"` + Size int64 `json:"size"` // 数据库大小 + Tables int `json:"tables"` // 表数量 + Connections int `json:"connections"` // 连接数 +} + +type AdminStorageInfo { + Type string `json:"type"` // local, s3 + TotalSpace int64 `json:"total_space"` // 总空间 + UsedSpace int64 `json:"used_space"` // 已使用空间 + FreeSpace int64 `json:"free_space"` // 剩余空间 +} + +// 清理系统缓存请求 +type ClearAdminSystemCacheRequest { + CacheType string `json:"cache_type,optional"` // all, photos, users, categories +} + +// 清理系统缓存响应 +type ClearAdminSystemCacheResponse { + BaseResponse + Data ClearAdminSystemCacheData `json:"data"` +} + +type ClearAdminSystemCacheData { + ClearedItems int `json:"cleared_items"` + CacheType string `json:"cache_type"` + Message string `json:"message"` +} + +// 管理后台仪表板接口组 - 需要管理员认证 +@server( + group: admin_dashboard + prefix: /admin/dashboard + jwt: AdminAuth +) +service photography-api { + @doc "获取仪表板统计" + @handler getAdminDashboardStats + get /stats (GetAdminDashboardStatsRequest) returns (GetAdminDashboardStatsResponse) + + @doc "获取分析数据" + @handler getAdminAnalytics + get /analytics (GetAdminAnalyticsRequest) returns (GetAdminAnalyticsResponse) + + @doc "获取热门内容" + @handler getAdminPopularContent + get /popular (GetAdminPopularContentRequest) returns (GetAdminPopularContentResponse) + + @doc "获取操作日志" + @handler getAdminOperationLogs + get /logs (GetAdminOperationLogsRequest) returns (GetAdminOperationLogsResponse) + + @doc "获取系统信息" + @handler getAdminSystemInfo + get /system (GetAdminSystemInfoRequest) returns (GetAdminSystemInfoResponse) + + @doc "清理系统缓存" + @handler clearAdminSystemCache + post /cache/clear (ClearAdminSystemCacheRequest) returns (ClearAdminSystemCacheResponse) +} \ No newline at end of file diff --git a/backend/api/desc/admin/photos.api b/backend/api/desc/admin/photos.api new file mode 100644 index 0000000..0f1b9cd --- /dev/null +++ b/backend/api/desc/admin/photos.api @@ -0,0 +1,216 @@ +syntax = "v1" + +import "common.api" + +// 管理后台照片管理接口 + +// 获取照片列表请求 +type GetAdminPhotoListRequest { + PageRequest + CategoryId int64 `form:"category_id,optional"` + UserId int64 `form:"user_id,optional"` + Keyword string `form:"keyword,optional"` + Status string `form:"status,optional"` // published, draft, deleted + Featured string `form:"featured,optional"` // true, false + SortBy string `form:"sort_by,optional,default=created_at_desc"` // 排序方式 + DateRange string `form:"date_range,optional"` // 日期范围筛选 +} + +// 获取照片列表响应 +type GetAdminPhotoListResponse { + BaseResponse + Data AdminPhotoListData `json:"data"` +} + +type AdminPhotoListData { + PageResponse + Photos []AdminPhoto `json:"photos"` +} + +// 获取照片详情请求 +type GetAdminPhotoRequest { + Id int64 `path:"id"` +} + +// 获取照片详情响应 +type GetAdminPhotoResponse { + BaseResponse + Data AdminPhotoDetail `json:"data"` +} + +// 上传照片请求 +type UploadAdminPhotoRequest { + Title string `json:"title" validate:"required"` + Description string `json:"description,optional"` + CategoryId int64 `json:"category_id" validate:"required"` + Tags string `json:"tags,optional"` // 标签 (逗号分隔) + Featured bool `json:"featured,optional"` // 是否精选 + Status string `json:"status,optional,default=published"` // published, draft +} + +// 上传照片响应 +type UploadAdminPhotoResponse { + BaseResponse + Data AdminPhoto `json:"data"` +} + +// 更新照片请求 +type UpdateAdminPhotoRequest { + Id int64 `path:"id"` + Title string `json:"title,optional"` + Description string `json:"description,optional"` + CategoryId int64 `json:"category_id,optional"` + Tags string `json:"tags,optional"` + Featured bool `json:"featured,optional"` + Status string `json:"status,optional"` +} + +// 更新照片响应 +type UpdateAdminPhotoResponse { + BaseResponse + Data AdminPhoto `json:"data"` +} + +// 删除照片请求 +type DeleteAdminPhotoRequest { + Id int64 `path:"id"` +} + +// 删除照片响应 +type DeleteAdminPhotoResponse { + BaseResponse +} + +// 设置精选照片请求 +type SetAdminPhotoFeaturedRequest { + Id int64 `path:"id"` + Featured bool `json:"featured" validate:"required"` +} + +// 设置精选照片响应 +type SetAdminPhotoFeaturedResponse { + BaseResponse + Data AdminPhoto `json:"data"` +} + +// 批量操作照片请求 +type BatchAdminPhotoOperationRequest { + PhotoIds []int64 `json:"photo_ids" validate:"required"` + Operation string `json:"operation" validate:"required"` // publish, draft, delete, set_featured, unset_featured + CategoryId int64 `json:"category_id,optional"` // 批量修改分类 +} + +// 批量操作照片响应 +type BatchAdminPhotoOperationResponse { + BaseResponse + Data BatchAdminPhotoOperationData `json:"data"` +} + +type BatchAdminPhotoOperationData { + SuccessCount int `json:"success_count"` + FailedCount int `json:"failed_count"` + FailedIds []int64 `json:"failed_ids"` +} + +// 照片统计请求 +type GetAdminPhotoStatsRequest { + DateRange string `form:"date_range,optional,default=7d"` // 7d, 30d, 90d +} + +// 照片统计响应 +type GetAdminPhotoStatsResponse { + BaseResponse + Data AdminPhotoStatsData `json:"data"` +} + +type AdminPhotoStatsData { + TotalPhotos int64 `json:"total_photos"` + PublishedPhotos int64 `json:"published_photos"` + DraftPhotos int64 `json:"draft_photos"` + FeaturedPhotos int64 `json:"featured_photos"` + NewPhotos int64 `json:"new_photos"` // 指定时间范围内新增照片 + GrowthRate float64 `json:"growth_rate"` // 增长率 + TotalViews int64 `json:"total_views"` // 总浏览量 + TotalStorage int64 `json:"total_storage"` // 总存储空间 (字节) +} + +// 照片存储信息请求 +type GetAdminPhotoStorageRequest { + Id int64 `path:"id"` +} + +// 照片存储信息响应 +type GetAdminPhotoStorageResponse { + BaseResponse + Data AdminPhotoStorageData `json:"data"` +} + +type AdminPhotoStorageData { + OriginalUrl string `json:"original_url"` + ThumbnailUrl string `json:"thumbnail_url"` + FileSize int64 `json:"file_size"` + ThumbnailSize int64 `json:"thumbnail_size"` + Format string `json:"format"` + Width int `json:"width"` + Height int `json:"height"` + ExifData string `json:"exif_data,optional"` // EXIF 信息 (JSON 格式) +} + +// 重新生成缩略图请求 +type RegenerateAdminPhotoThumbnailRequest { + Id int64 `path:"id"` +} + +// 重新生成缩略图响应 +type RegenerateAdminPhotoThumbnailResponse { + BaseResponse + Data AdminPhotoStorageData `json:"data"` +} + +// 管理后台照片管理接口组 - 需要管理员认证 +@server( + group: admin_photos + prefix: /admin/photos + jwt: AdminAuth +) +service photography-api { + @doc "获取照片列表" + @handler getAdminPhotoList + get / (GetAdminPhotoListRequest) returns (GetAdminPhotoListResponse) + + @doc "上传照片" + @handler uploadAdminPhoto + post / (UploadAdminPhotoRequest) returns (UploadAdminPhotoResponse) + + @doc "获取照片详情" + @handler getAdminPhoto + get /:id (GetAdminPhotoRequest) returns (GetAdminPhotoResponse) + + @doc "更新照片" + @handler updateAdminPhoto + put /:id (UpdateAdminPhotoRequest) returns (UpdateAdminPhotoResponse) + + @doc "删除照片" + @handler deleteAdminPhoto + delete /:id (DeleteAdminPhotoRequest) returns (DeleteAdminPhotoResponse) + + @doc "设置精选照片" + @handler setAdminPhotoFeatured + put /:id/featured (SetAdminPhotoFeaturedRequest) returns (SetAdminPhotoFeaturedResponse) + + @doc "获取照片存储信息" + @handler getAdminPhotoStorage + get /:id/storage (GetAdminPhotoStorageRequest) returns (GetAdminPhotoStorageResponse) + + @doc "重新生成缩略图" + @handler regenerateAdminPhotoThumbnail + post /:id/regenerate-thumbnail (RegenerateAdminPhotoThumbnailRequest) returns (RegenerateAdminPhotoThumbnailResponse) + + @doc "批量操作照片" + @handler batchAdminPhotoOperation + post /batch (BatchAdminPhotoOperationRequest) returns (BatchAdminPhotoOperationResponse) + + @doc "获取照片统计" + @handler getAdminPhotoStats + get /stats (GetAdminPhotoStatsRequest) returns (GetAdminPhotoStatsResponse) +} \ No newline at end of file diff --git a/backend/api/desc/admin/users.api b/backend/api/desc/admin/users.api new file mode 100644 index 0000000..964d5ce --- /dev/null +++ b/backend/api/desc/admin/users.api @@ -0,0 +1,199 @@ +syntax = "v1" + +import "common.api" + +// 管理后台用户管理接口 + +// 获取用户列表请求 +type GetAdminUserListRequest { + PageRequest + Keyword string `form:"keyword,optional"` + Status int `form:"status,optional"` // 用户状态筛选 + SortBy string `form:"sort_by,optional,default=created_at_desc"` // 排序方式 +} + +// 获取用户列表响应 +type GetAdminUserListResponse { + BaseResponse + Data AdminUserListData `json:"data"` +} + +type AdminUserListData { + PageResponse + Users []AdminUser `json:"users"` +} + +// 获取用户详情请求 +type GetAdminUserRequest { + Id int64 `path:"id"` +} + +// 获取用户详情响应 +type GetAdminUserResponse { + BaseResponse + Data AdminUserDetail `json:"data"` +} + +// 创建用户请求 +type CreateAdminUserRequest { + Username string `json:"username" validate:"required"` + Email string `json:"email" validate:"required,email"` + Password string `json:"password" validate:"required,min=6"` + Status int `json:"status,optional,default=1"` // 用户状态 + Role string `json:"role,optional,default=user"` // 用户角色 +} + +// 创建用户响应 +type CreateAdminUserResponse { + BaseResponse + Data AdminUser `json:"data"` +} + +// 更新用户请求 +type UpdateAdminUserRequest { + Id int64 `path:"id"` + Username string `json:"username,optional"` + Email string `json:"email,optional"` + Avatar string `json:"avatar,optional"` + Status int `json:"status,optional"` + Role string `json:"role,optional"` +} + +// 更新用户响应 +type UpdateAdminUserResponse { + BaseResponse + Data AdminUser `json:"data"` +} + +// 删除用户请求 +type DeleteAdminUserRequest { + Id int64 `path:"id"` +} + +// 删除用户响应 +type DeleteAdminUserResponse { + BaseResponse +} + +// 更新用户状态请求 +type UpdateAdminUserStatusRequest { + Id int64 `path:"id"` + Status int `json:"status" validate:"required"` // 1:启用 0:禁用 +} + +// 更新用户状态响应 +type UpdateAdminUserStatusResponse { + BaseResponse + Data AdminUser `json:"data"` +} + +// 重置用户密码请求 +type ResetAdminUserPasswordRequest { + Id int64 `path:"id"` + NewPassword string `json:"new_password" validate:"required,min=6"` +} + +// 重置用户密码响应 +type ResetAdminUserPasswordResponse { + BaseResponse +} + +// 上传用户头像请求 +type UploadAdminUserAvatarRequest { + Id int64 `path:"id"` +} + +// 上传用户头像响应 +type UploadAdminUserAvatarResponse { + BaseResponse + Data UploadAdminUserAvatarData `json:"data"` +} + +type UploadAdminUserAvatarData { + AvatarUrl string `json:"avatar_url"` +} + +// 批量操作用户请求 +type BatchAdminUserOperationRequest { + UserIds []int64 `json:"user_ids" validate:"required"` + Operation string `json:"operation" validate:"required"` // enable, disable, delete +} + +// 批量操作用户响应 +type BatchAdminUserOperationResponse { + BaseResponse + Data BatchAdminUserOperationData `json:"data"` +} + +type BatchAdminUserOperationData { + SuccessCount int `json:"success_count"` + FailedCount int `json:"failed_count"` + FailedIds []int64 `json:"failed_ids"` +} + +// 用户统计请求 +type GetAdminUserStatsRequest { + DateRange string `form:"date_range,optional,default=7d"` // 7d, 30d, 90d +} + +// 用户统计响应 +type GetAdminUserStatsResponse { + BaseResponse + Data AdminUserStatsData `json:"data"` +} + +type AdminUserStatsData { + TotalUsers int64 `json:"total_users"` + ActiveUsers int64 `json:"active_users"` + InactiveUsers int64 `json:"inactive_users"` + NewUsers int64 `json:"new_users"` // 指定时间范围内新增用户 + GrowthRate float64 `json:"growth_rate"` // 增长率 +} + +// 管理后台用户管理接口组 - 需要管理员认证 +@server( + group: admin_users + prefix: /admin/users + jwt: AdminAuth +) +service photography-api { + @doc "获取用户列表" + @handler getAdminUserList + get / (GetAdminUserListRequest) returns (GetAdminUserListResponse) + + @doc "创建用户" + @handler createAdminUser + post / (CreateAdminUserRequest) returns (CreateAdminUserResponse) + + @doc "获取用户详情" + @handler getAdminUser + get /:id (GetAdminUserRequest) returns (GetAdminUserResponse) + + @doc "更新用户" + @handler updateAdminUser + put /:id (UpdateAdminUserRequest) returns (UpdateAdminUserResponse) + + @doc "删除用户" + @handler deleteAdminUser + delete /:id (DeleteAdminUserRequest) returns (DeleteAdminUserResponse) + + @doc "更新用户状态" + @handler updateAdminUserStatus + put /:id/status (UpdateAdminUserStatusRequest) returns (UpdateAdminUserStatusResponse) + + @doc "重置用户密码" + @handler resetAdminUserPassword + post /:id/reset-password (ResetAdminUserPasswordRequest) returns (ResetAdminUserPasswordResponse) + + @doc "上传用户头像" + @handler uploadAdminUserAvatar + post /:id/avatar (UploadAdminUserAvatarRequest) returns (UploadAdminUserAvatarResponse) + + @doc "批量操作用户" + @handler batchAdminUserOperation + post /batch (BatchAdminUserOperationRequest) returns (BatchAdminUserOperationResponse) + + @doc "获取用户统计" + @handler getAdminUserStats + get /stats (GetAdminUserStatsRequest) returns (GetAdminUserStatsResponse) +} \ No newline at end of file diff --git a/backend/api/desc/common.api b/backend/api/desc/common.api index 0da0b55..571d758 100644 --- a/backend/api/desc/common.api +++ b/backend/api/desc/common.api @@ -50,4 +50,169 @@ type Category { Description string `json:"description"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` +} + +// 前端公共展示类型 + +// 前端公共照片信息 (去除敏感信息) +type PublicPhoto { + Id int64 `json:"id"` + Title string `json:"title"` + Description string `json:"description"` + FilePath string `json:"file_path"` + ThumbnailPath string `json:"thumbnail_path"` + CategoryId int64 `json:"category_id"` + CategoryName string `json:"category_name,optional"` + Featured bool `json:"featured"` + ViewCount int64 `json:"view_count,optional"` + CreatedAt int64 `json:"created_at"` +} + +// 前端公共分类信息 (去除敏感信息) +type PublicCategory { + Id int64 `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + CoverImage string `json:"cover_image,optional"` + PhotoCount int64 `json:"photo_count,optional"` + CreatedAt int64 `json:"created_at"` +} + +// 前端公共分类详情 (包含照片) +type PublicCategoryWithPhotos { + Id int64 `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + CoverImage string `json:"cover_image,optional"` + PhotoCount int64 `json:"photo_count"` + Photos []PublicPhoto `json:"photos,optional"` + CreatedAt int64 `json:"created_at"` +} + +// 前端用户信息 (精简版) +type FrontendUser { + Id int64 `json:"id"` + Username string `json:"username"` + Email string `json:"email"` + Avatar string `json:"avatar"` + CreatedAt int64 `json:"created_at"` +} + +// 管理后台类型 + +// 管理员信息 +type Admin { + Id int64 `json:"id"` + Username string `json:"username"` + Email string `json:"email"` + Avatar string `json:"avatar"` + Role string `json:"role"` // super_admin, admin + Status int `json:"status"` // 1:启用 0:禁用 + LastLogin int64 `json:"last_login,optional"` + CreatedAt int64 `json:"created_at"` + UpdatedAt int64 `json:"updated_at"` +} + +// 管理后台用户信息 (包含更多字段) +type AdminUser { + Id int64 `json:"id"` + Username string `json:"username"` + Email string `json:"email"` + Avatar string `json:"avatar"` + Status int `json:"status"` // 1:启用 0:禁用 + Role string `json:"role"` // user, vip, admin + LastLogin int64 `json:"last_login,optional"` + LoginCount int64 `json:"login_count,optional"` + PhotoCount int64 `json:"photo_count,optional"` + CreatedAt int64 `json:"created_at"` + UpdatedAt int64 `json:"updated_at"` +} + +// 管理后台用户详情 (包含统计信息) +type AdminUserDetail { + AdminUser + Stats AdminUserStats `json:"stats"` +} + +type AdminUserStats { + TotalPhotos int64 `json:"total_photos"` + TotalViews int64 `json:"total_views"` + TotalLikes int64 `json:"total_likes"` + TotalComments int64 `json:"total_comments"` + StorageUsed int64 `json:"storage_used"` + RecentActivity int64 `json:"recent_activity"` +} + +// 管理后台照片信息 (包含更多字段) +type AdminPhoto { + Id int64 `json:"id"` + Title string `json:"title"` + Description string `json:"description"` + FilePath string `json:"file_path"` + ThumbnailPath string `json:"thumbnail_path"` + UserId int64 `json:"user_id"` + UserName string `json:"user_name,optional"` + CategoryId int64 `json:"category_id"` + CategoryName string `json:"category_name,optional"` + Tags string `json:"tags,optional"` + Featured bool `json:"featured"` + Status string `json:"status"` // published, draft, deleted + FileSize int64 `json:"file_size,optional"` + Format string `json:"format,optional"` + Width int `json:"width,optional"` + Height int `json:"height,optional"` + ViewCount int64 `json:"view_count,optional"` + LikeCount int64 `json:"like_count,optional"` + CommentCount int64 `json:"comment_count,optional"` + CreatedAt int64 `json:"created_at"` + UpdatedAt int64 `json:"updated_at"` +} + +// 管理后台照片详情 (包含统计和 EXIF 信息) +type AdminPhotoDetail { + AdminPhoto + ExifData string `json:"exif_data,optional"` + Stats AdminPhotoStats `json:"stats"` +} + +type AdminPhotoStats { + ViewHistory []AdminPhotoViewHistory `json:"view_history,optional"` + DownloadCount int64 `json:"download_count,optional"` + ShareCount int64 `json:"share_count,optional"` + RecentViews int64 `json:"recent_views"` // 最近7天浏览量 +} + +type AdminPhotoViewHistory { + Date string `json:"date"` + Views int64 `json:"views"` +} + +// 管理后台分类信息 (包含更多字段) +type AdminCategory { + Id int64 `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + SortOrder int `json:"sort_order"` // 排序权重 + Status string `json:"status"` // active, inactive + CoverImage string `json:"cover_image,optional"` + PhotoCount int64 `json:"photo_count,optional"` + ViewCount int64 `json:"view_count,optional"` + CreatedAt int64 `json:"created_at"` + UpdatedAt int64 `json:"updated_at"` +} + +// 管理后台分类详情 (包含统计信息) +type AdminCategoryDetail { + AdminCategory + Stats AdminCategoryStats `json:"stats"` +} + +type AdminCategoryStats { + TotalPhotos int64 `json:"total_photos"` + PublishedPhotos int64 `json:"published_photos"` + DraftPhotos int64 `json:"draft_photos"` + FeaturedPhotos int64 `json:"featured_photos"` + TotalViews int64 `json:"total_views"` + RecentViews int64 `json:"recent_views"` // 最近7天浏览量 + GrowthRate float64 `json:"growth_rate"` // 增长率 } \ No newline at end of file diff --git a/backend/api/desc/frontend/auth.api b/backend/api/desc/frontend/auth.api new file mode 100644 index 0000000..7f69c38 --- /dev/null +++ b/backend/api/desc/frontend/auth.api @@ -0,0 +1,109 @@ +syntax = "v1" + +import "common.api" + +// 前端用户认证接口 - 轻量级认证 + +// 前端用户登录请求 +type FrontendLoginRequest { + Username string `json:"username" validate:"required"` + Password string `json:"password" validate:"required"` +} + +// 前端用户登录响应 +type FrontendLoginResponse { + BaseResponse + Data FrontendLoginData `json:"data"` +} + +type FrontendLoginData { + Token string `json:"token"` + User FrontendUser `json:"user"` +} + +// 前端用户注册请求 +type FrontendRegisterRequest { + Username string `json:"username" validate:"required"` + Email string `json:"email" validate:"required,email"` + Password string `json:"password" validate:"required,min=6"` +} + +// 前端用户注册响应 +type FrontendRegisterResponse { + BaseResponse + Data FrontendUser `json:"data"` +} + +// 前端用户信息响应 +type FrontendProfileResponse { + BaseResponse + Data FrontendUser `json:"data"` +} + +// 前端用户更新请求 +type UpdateFrontendProfileRequest { + Username string `json:"username,optional"` + Email string `json:"email,optional"` + Avatar string `json:"avatar,optional"` +} + +// 前端用户更新响应 +type UpdateFrontendProfileResponse { + BaseResponse + Data FrontendUser `json:"data"` +} + +// 前端用户修改密码请求 +type ChangeFrontendPasswordRequest { + OldPassword string `json:"old_password" validate:"required"` + NewPassword string `json:"new_password" validate:"required,min=6"` +} + +// 前端用户修改密码响应 +type ChangeFrontendPasswordResponse { + BaseResponse +} + +// 前端用户登出响应 +type FrontendLogoutResponse { + BaseResponse +} + +// 前端认证接口组 +@server( + group: auth + prefix: /api/v1/auth +) +service photography-api { + @doc "前端用户登录" + @handler frontendLogin + post /login (FrontendLoginRequest) returns (FrontendLoginResponse) + + @doc "前端用户注册" + @handler frontendRegister + post /register (FrontendRegisterRequest) returns (FrontendRegisterResponse) + + @doc "前端用户登出" + @handler frontendLogout + post /logout returns (FrontendLogoutResponse) +} + +// 前端用户认证接口组 - 需要认证 +@server( + group: auth + prefix: /api/v1/auth + jwt: Auth +) +service photography-api { + @doc "获取前端用户信息" + @handler getFrontendProfile + get /profile returns (FrontendProfileResponse) + + @doc "更新前端用户信息" + @handler updateFrontendProfile + put /profile (UpdateFrontendProfileRequest) returns (UpdateFrontendProfileResponse) + + @doc "修改前端用户密码" + @handler changeFrontendPassword + post /change-password (ChangeFrontendPasswordRequest) returns (ChangeFrontendPasswordResponse) +} \ No newline at end of file diff --git a/backend/api/desc/frontend/public.api b/backend/api/desc/frontend/public.api new file mode 100644 index 0000000..fc89772 --- /dev/null +++ b/backend/api/desc/frontend/public.api @@ -0,0 +1,117 @@ +syntax = "v1" + +import "common.api" + +// 前端公共展示接口 - 无需认证 + +// 获取照片列表请求 +type GetPublicPhotoListRequest { + PageRequest + CategoryId int64 `form:"category_id,optional"` + Keyword string `form:"keyword,optional"` + Sort string `form:"sort,optional,default=created_at_desc"` // created_at_desc, created_at_asc, title_asc, title_desc +} + +// 获取照片列表响应 +type GetPublicPhotoListResponse { + BaseResponse + Data PublicPhotoListData `json:"data"` +} + +type PublicPhotoListData { + PageResponse + Photos []PublicPhoto `json:"photos"` +} + +// 获取照片详情请求 +type GetPublicPhotoRequest { + Id int64 `path:"id"` +} + +// 获取照片详情响应 +type GetPublicPhotoResponse { + BaseResponse + Data PublicPhoto `json:"data"` +} + +// 获取精选照片响应 +type GetFeaturedPhotosResponse { + BaseResponse + Data []PublicPhoto `json:"data"` +} + +// 获取最新照片请求 +type GetRecentPhotosRequest { + Limit int `form:"limit,optional,default=12"` +} + +// 获取最新照片响应 +type GetRecentPhotosResponse { + BaseResponse + Data []PublicPhoto `json:"data"` +} + +// 获取分类列表响应 +type GetPublicCategoryListResponse { + BaseResponse + Data []PublicCategory `json:"data"` +} + +// 获取分类详情请求 +type GetPublicCategoryRequest { + Id int64 `path:"id"` +} + +// 获取分类详情响应 +type GetPublicCategoryResponse { + BaseResponse + Data PublicCategoryWithPhotos `json:"data"` +} + +// 获取分类下的照片请求 +type GetCategoryPhotosRequest { + Id int64 `path:"id"` + PageRequest + Sort string `form:"sort,optional,default=created_at_desc"` +} + +// 获取分类下的照片响应 +type GetCategoryPhotosResponse { + BaseResponse + Data PublicPhotoListData `json:"data"` +} + +// 前端公共接口组 - 无需认证 +@server( + group: public + prefix: /api/v1/public +) +service photography-api { + @doc "获取照片列表" + @handler getPublicPhotoList + get /photos (GetPublicPhotoListRequest) returns (GetPublicPhotoListResponse) + + @doc "获取照片详情" + @handler getPublicPhoto + get /photos/:id (GetPublicPhotoRequest) returns (GetPublicPhotoResponse) + + @doc "获取精选照片" + @handler getFeaturedPhotos + get /photos/featured returns (GetFeaturedPhotosResponse) + + @doc "获取最新照片" + @handler getRecentPhotos + get /photos/recent (GetRecentPhotosRequest) returns (GetRecentPhotosResponse) + + @doc "获取分类列表" + @handler getPublicCategoryList + get /categories returns (GetPublicCategoryListResponse) + + @doc "获取分类详情" + @handler getPublicCategory + get /categories/:id (GetPublicCategoryRequest) returns (GetPublicCategoryResponse) + + @doc "获取分类下的照片" + @handler getCategoryPhotos + get /categories/:id/photos (GetCategoryPhotosRequest) returns (GetCategoryPhotosResponse) +} \ No newline at end of file diff --git a/backend/api/desc/photography.api b/backend/api/desc/photography.api index fc9fe7d..df19386 100644 --- a/backend/api/desc/photography.api +++ b/backend/api/desc/photography.api @@ -1,18 +1,16 @@ syntax = "v1" info ( - title: "Photography Portfolio API" - desc: "摄影作品集 API 服务" + title: "Photography Portfolio Frontend API" + desc: "摄影作品集前端展示 API 服务" author: "Photography Team" email: "team@photography.com" version: "v1.0.0" ) import "common.api" -import "auth.api" -import "user.api" -import "photo.api" -import "category.api" +import "frontend/public.api" +import "frontend/auth.api" // 健康检查接口 (无需认证) @server ( diff --git a/backend/docs/API_REFACTORING_TASKS.md b/backend/docs/API_REFACTORING_TASKS.md new file mode 100644 index 0000000..33f48e4 --- /dev/null +++ b/backend/docs/API_REFACTORING_TASKS.md @@ -0,0 +1,396 @@ +# API 接口改造任务规划 + +## 📋 项目概述 + +本文档详细规划了前端页面和管理后台 API 接口隔离改造的所有任务,确保两套系统拥有独立的认证体系和权限管理。 + +## 🎯 改造目标 + +- **前端API**: `/api/v1/public/*` + `/api/v1/auth/*` (公共展示 + 轻量认证) +- **管理后台API**: `/admin/*` (完整管理功能 + 强认证) +- **权限隔离**: 两套独立的认证和权限系统 +- **性能优化**: 前端专注展示,后台专注管理 + +## 🏗️ 总体架构 + +``` +当前架构: +├── /api/v1/users (混合用途) +├── /api/v1/photos (混合用途) +├── /api/v1/categories (混合用途) +└── /api/v1/auth (混合认证) + +目标架构: +├── /api/v1/public/ (前端展示) +├── /api/v1/auth/ (前端认证) +└── /admin/ (管理后台) +``` + +--- + +## 📊 任务分解 + +### 🔧 阶段一:后端 API 改造 (Backend) + +#### 1. API 定义文件重构 +- [x] **1.1** 创建前端公共接口定义文件 + - [x] 创建 `api/desc/frontend/public.api` + - [x] 定义照片展示接口类型 + - [x] 定义分类展示接口类型 + - [x] 定义精选照片、最新照片接口 + - [x] 优化返回数据结构 (去除敏感信息) + +- [x] **1.2** 创建前端认证接口定义文件 + - [x] 创建 `api/desc/frontend/auth.api` + - [x] 定义前端用户登录/注册接口 + - [x] 定义前端用户信息接口 + - [x] 设计轻量级认证流程 + +- [x] **1.3** 创建管理后台接口定义文件 + - [x] 创建 `api/desc/admin.api` 主入口文件 + - [x] 创建 `api/desc/admin/auth.api` 管理员认证 + - [x] 创建 `api/desc/admin/users.api` 用户管理 + - [x] 创建 `api/desc/admin/photos.api` 照片管理 + - [x] 创建 `api/desc/admin/categories.api` 分类管理 + - [x] 创建 `api/desc/admin/dashboard.api` 仪表板统计 + +- [x] **1.4** 更新公共类型定义 + - [x] 扩展 `common.api` 添加管理后台专用类型 + - [x] 添加前端展示专用类型 + - [x] 定义双重认证相关类型 + - [x] 添加权限控制相关类型 + +#### 2. 路由和处理器重构 +- [ ] **2.1** 创建前端公共接口处理器 + - [ ] 创建 `internal/handler/frontend/` 目录 + - [ ] 实现公共照片列表处理器 + - [ ] 实现公共分类列表处理器 + - [ ] 实现精选照片处理器 + - [ ] 实现最新照片处理器 + - [ ] 优化查询性能和缓存 + +- [ ] **2.2** 创建管理后台接口处理器 + - [ ] 创建 `internal/handler/admin/` 目录 + - [ ] 实现管理员认证处理器 + - [ ] 实现用户管理处理器 + - [ ] 实现照片管理处理器 + - [ ] 实现分类管理处理器 + - [ ] 实现仪表板统计处理器 + +- [ ] **2.3** 更新路由配置 + - [ ] 更新 `internal/handler/routes.go` + - [ ] 配置前端公共路由组 + - [ ] 配置管理后台路由组 + - [ ] 设置不同的路由前缀 + - [ ] 配置中间件应用策略 + +#### 3. 业务逻辑层重构 +- [ ] **3.1** 创建前端业务逻辑 + - [ ] 创建 `internal/logic/frontend/` 目录 + - [ ] 实现公共照片查询逻辑 + - [ ] 实现公共分类查询逻辑 + - [ ] 实现前端认证逻辑 + - [ ] 优化查询性能和数据过滤 + +- [ ] **3.2** 创建管理后台业务逻辑 + - [ ] 创建 `internal/logic/admin/` 目录 + - [ ] 实现管理员认证逻辑 + - [ ] 实现用户管理逻辑 + - [ ] 实现照片管理逻辑 + - [ ] 实现分类管理逻辑 + - [ ] 实现仪表板统计逻辑 + +- [ ] **3.3** 权限控制逻辑 + - [ ] 实现双重认证中间件 + - [ ] 实现管理员权限验证 + - [ ] 实现前端用户权限验证 + - [ ] 添加审计日志功能 + +#### 4. 数据层优化 +- [ ] **4.1** 优化数据模型 + - [ ] 为前端查询添加索引优化 + - [ ] 为管理后台查询添加索引优化 + - [ ] 优化分页查询性能 + - [ ] 添加缓存支持 + +- [ ] **4.2** 数据访问层隔离 + - [ ] 创建前端专用数据访问方法 + - [ ] 创建管理后台专用数据访问方法 + - [ ] 实现数据过滤和权限控制 + - [ ] 优化查询效率 + +#### 5. 认证系统重构 +- [ ] **5.1** 实现双重认证系统 + - [ ] 重构 JWT 生成和验证 + - [ ] 实现前端轻量级认证 + - [ ] 实现管理员强认证 + - [ ] 配置不同的 Token 策略 + +- [ ] **5.2** 中间件系统升级 + - [ ] 更新认证中间件 + - [ ] 实现权限控制中间件 + - [ ] 添加访问日志中间件 + - [ ] 优化 CORS 配置 + +#### 6. 配置和部署 +- [ ] **6.1** 更新配置文件 + - [ ] 更新 `etc/photographyapi-api.yaml` + - [ ] 配置双重认证参数 + - [ ] 配置缓存策略 + - [ ] 配置日志级别 + +- [ ] **6.2** 代码生成和构建 + - [ ] 使用 goctl 重新生成代码 + - [ ] 更新 Makefile 构建脚本 + - [ ] 修复编译错误 + - [ ] 运行单元测试 + +--- + +### 🎨 阶段二:前端页面 API 对接 (Frontend) + +#### 1. API 客户端重构 +- [ ] **1.1** 创建前端 API 客户端 + - [ ] 创建 `frontend/lib/api/public.ts` + - [ ] 实现照片展示 API 调用 + - [ ] 实现分类展示 API 调用 + - [ ] 实现精选照片 API 调用 + - [ ] 实现最新照片 API 调用 + +- [ ] **1.2** 更新认证客户端 + - [ ] 更新 `frontend/lib/api/auth.ts` + - [ ] 适配新的认证接口 + - [ ] 实现前端用户登录 + - [ ] 实现前端用户注册 + - [ ] 更新 Token 处理逻辑 + +#### 2. 页面组件更新 +- [ ] **2.1** 更新照片展示组件 + - [ ] 更新照片列表组件 + - [ ] 更新照片详情组件 + - [ ] 更新照片网格组件 + - [ ] 适配新的数据结构 + +- [ ] **2.2** 更新分类展示组件 + - [ ] 更新分类列表组件 + - [ ] 更新分类筛选组件 + - [ ] 适配新的数据结构 + +- [ ] **2.3** 更新认证相关组件 + - [ ] 更新登录表单组件 + - [ ] 更新注册表单组件 + - [ ] 更新用户信息组件 + - [ ] 适配新的认证流程 + +#### 3. 状态管理更新 +- [ ] **3.1** 更新数据状态管理 + - [ ] 更新照片数据状态 + - [ ] 更新分类数据状态 + - [ ] 更新认证状态 + - [ ] 优化缓存策略 + +- [ ] **3.2** 更新 API 错误处理 + - [ ] 实现统一错误处理 + - [ ] 更新错误提示组件 + - [ ] 添加重试机制 + - [ ] 优化用户体验 + +#### 4. 性能优化 +- [ ] **4.1** 实现数据预取 + - [ ] 实现照片数据预取 + - [ ] 实现分类数据预取 + - [ ] 优化首屏加载速度 + +- [ ] **4.2** 实现缓存策略 + - [ ] 实现客户端缓存 + - [ ] 实现增量更新 + - [ ] 优化网络请求 + +--- + +### 🔧 阶段三:管理后台 API 对接 (Admin) + +#### 1. API 客户端重构 +- [ ] **1.1** 创建管理后台 API 客户端 + - [ ] 创建 `admin/src/api/admin.ts` + - [ ] 实现管理员认证 API + - [ ] 实现用户管理 API + - [ ] 实现照片管理 API + - [ ] 实现分类管理 API + - [ ] 实现仪表板统计 API + +- [ ] **1.2** 实现强认证客户端 + - [ ] 创建 `admin/src/api/auth.ts` + - [ ] 实现管理员登录 + - [ ] 实现 Token 刷新 + - [ ] 实现权限验证 + - [ ] 添加双重认证支持 + +#### 2. 管理界面组件 +- [ ] **2.1** 用户管理界面 + - [ ] 更新用户列表组件 + - [ ] 更新用户编辑组件 + - [ ] 更新用户创建组件 + - [ ] 实现用户状态管理 + - [ ] 实现头像上传功能 + +- [ ] **2.2** 照片管理界面 + - [ ] 更新照片列表组件 + - [ ] 更新照片编辑组件 + - [ ] 更新照片上传组件 + - [ ] 实现批量操作功能 + - [ ] 实现精选照片设置 + +- [ ] **2.3** 分类管理界面 + - [ ] 更新分类列表组件 + - [ ] 更新分类编辑组件 + - [ ] 更新分类创建组件 + - [ ] 实现分类排序功能 + +- [ ] **2.4** 仪表板界面 + - [ ] 创建统计数据组件 + - [ ] 创建分析图表组件 + - [ ] 创建操作日志组件 + - [ ] 实现实时数据更新 + +#### 3. 权限控制系统 +- [ ] **3.1** 实现页面权限控制 + - [ ] 实现路由权限守卫 + - [ ] 实现组件权限控制 + - [ ] 实现功能权限验证 + - [ ] 添加权限提示界面 + +- [ ] **3.2** 实现操作权限控制 + - [ ] 实现操作按钮权限控制 + - [ ] 实现 API 调用权限验证 + - [ ] 实现数据访问权限控制 + - [ ] 添加权限异常处理 + +#### 4. 数据管理优化 +- [ ] **4.1** 实现数据表格优化 + - [ ] 实现高性能数据表格 + - [ ] 实现虚拟滚动 + - [ ] 实现数据筛选和排序 + - [ ] 优化大数据量展示 + +- [ ] **4.2** 实现表单优化 + - [ ] 实现表单验证 + - [ ] 实现表单数据缓存 + - [ ] 实现表单提交优化 + - [ ] 添加表单错误处理 + +--- + +## 🧪 测试和验证 + +### 1. 后端测试 +- [ ] **1.1** 单元测试 + - [ ] 测试前端公共接口 + - [ ] 测试管理后台接口 + - [ ] 测试认证系统 + - [ ] 测试权限控制 + +- [ ] **1.2** 集成测试 + - [ ] 测试 API 接口集成 + - [ ] 测试数据库集成 + - [ ] 测试认证集成 + - [ ] 测试权限集成 + +### 2. 前端测试 +- [ ] **2.1** 组件测试 + - [ ] 测试前端页面组件 + - [ ] 测试管理后台组件 + - [ ] 测试认证组件 + - [ ] 测试权限组件 + +- [ ] **2.2** 端到端测试 + - [ ] 测试完整用户流程 + - [ ] 测试管理后台流程 + - [ ] 测试认证流程 + - [ ] 测试权限流程 + +### 3. 性能测试 +- [ ] **3.1** API 性能测试 + - [ ] 测试接口响应时间 + - [ ] 测试并发处理能力 + - [ ] 测试缓存效果 + - [ ] 测试数据库性能 + +- [ ] **3.2** 前端性能测试 + - [ ] 测试页面加载速度 + - [ ] 测试组件渲染性能 + - [ ] 测试数据更新性能 + - [ ] 测试用户交互响应 + +--- + +## 📋 里程碑和时间规划 + +### 🎯 里程碑 1: 后端 API 定义完成 ✅ +**完成时间**: 2025-07-11 +- ✅ API 定义文件重构 (已完成) +- ⏳ 路由和处理器重构 (下一步) +- ⏳ 业务逻辑层重构 (下一步) +- ⏳ 认证系统重构 (下一步) + +### 🎯 里程碑 2: 前端页面适配完成 +**预计时间**: 2-3 天 +- ✅ API 客户端重构 +- ✅ 页面组件更新 +- ✅ 状态管理更新 +- ✅ 性能优化 + +### 🎯 里程碑 3: 管理后台适配完成 +**预计时间**: 3-4 天 +- ✅ API 客户端重构 +- ✅ 管理界面组件 +- ✅ 权限控制系统 +- ✅ 数据管理优化 + +### 🎯 里程碑 4: 测试和上线 +**预计时间**: 2-3 天 +- ✅ 全面测试 +- ✅ 性能优化 +- ✅ 部署上线 +- ✅ 监控和维护 + +--- + +## 🔥 优先级说明 + +### 🚨 高优先级 (P0) +- 后端 API 定义文件重构 +- 认证系统重构 +- 路由和处理器重构 + +### ⚡ 中优先级 (P1) +- 前端页面 API 对接 +- 管理后台 API 对接 +- 权限控制系统 + +### 🔧 低优先级 (P2) +- 性能优化 +- 缓存策略 +- 监控和日志 + +--- + +## 📞 风险控制 + +### 🚨 潜在风险 +1. **数据兼容性**: 新旧 API 数据结构变化 +2. **认证迁移**: 用户认证状态迁移 +3. **性能影响**: 重构可能影响系统性能 +4. **测试覆盖**: 确保所有功能正常 + +### 🛡️ 应对措施 +1. **灰度发布**: 逐步切换到新 API +2. **数据备份**: 改造前完整备份 +3. **回滚方案**: 准备快速回滚机制 +4. **全面测试**: 确保功能完整性 + +--- + +**📝 文档更新时间**: {当前时间} +**📋 文档版本**: v1.0 +**👥 负责人**: Development Team \ No newline at end of file diff --git a/backend/docs/API_SEPARATION_DESIGN.md b/backend/docs/API_SEPARATION_DESIGN.md new file mode 100644 index 0000000..ae10391 --- /dev/null +++ b/backend/docs/API_SEPARATION_DESIGN.md @@ -0,0 +1,223 @@ +# API 接口隔离设计方案 + +## 📋 概述 + +为了实现管理后台和前端页面的权限隔离,将 API 接口按照使用场景进行分离设计。两套接口体系拥有独立的认证系统和权限管理。 + +## 🏗️ 整体架构 + +``` +/api/v1/ # 前端页面 API (公共展示) +├── public/ # 公共接口 (无需认证) +│ ├── photos # 照片展示接口 +│ ├── categories # 分类展示接口 +│ └── health # 健康检查 +└── auth/ # 前端认证 (用户登录/注册) + ├── login + └── register + +/admin/ # 管理后台 API (管理功能) +├── auth/ # 管理员认证 +│ ├── login +│ └── refresh +├── users/ # 用户管理 +├── photos/ # 照片管理 +├── categories/ # 分类管理 +└── dashboard/ # 仪表板统计 +``` + +## 🎨 前端页面 API 设计 + +### 特点 +- **无需认证**:主要用于展示,提供公共访问 +- **只读操作**:只提供数据查询,不涉及修改 +- **高性能**:支持缓存,优化加载速度 +- **SEO友好**:支持静态生成所需的数据 + +### 接口列表 + +#### 🏥 健康检查 +``` +GET /api/v1/health +``` + +#### 📸 照片接口 +``` +GET /api/v1/public/photos # 获取照片列表 (支持分页、筛选) +GET /api/v1/public/photos/:id # 获取照片详情 +GET /api/v1/public/photos/featured # 获取精选照片 +GET /api/v1/public/photos/recent # 获取最新照片 +``` + +#### 🏷️ 分类接口 +``` +GET /api/v1/public/categories # 获取分类列表 +GET /api/v1/public/categories/:id # 获取分类详情 +GET /api/v1/public/categories/:id/photos # 获取分类下的照片 +``` + +#### 🔐 用户认证 (前端用户) +``` +POST /api/v1/auth/login # 前端用户登录 +POST /api/v1/auth/register # 前端用户注册 +POST /api/v1/auth/logout # 前端用户登出 +GET /api/v1/auth/profile # 获取用户信息 (需要认证) +``` + +## 🔧 管理后台 API 设计 + +### 特点 +- **强认证**:所有接口都需要管理员权限 +- **完整CRUD**:支持创建、读取、更新、删除操作 +- **权限控制**:基于角色的访问控制 +- **审计日志**:记录所有管理操作 + +### 接口列表 + +#### 🔐 管理员认证 +``` +POST /admin/auth/login # 管理员登录 +POST /admin/auth/refresh # 刷新管理员Token +POST /admin/auth/logout # 管理员登出 +GET /admin/auth/profile # 获取管理员信息 +``` + +#### 👥 用户管理 +``` +GET /admin/users # 获取用户列表 +POST /admin/users # 创建用户 +GET /admin/users/:id # 获取用户详情 +PUT /admin/users/:id # 更新用户 +DELETE /admin/users/:id # 删除用户 +POST /admin/users/:id/avatar # 上传用户头像 +PUT /admin/users/:id/status # 更新用户状态 +``` + +#### 📸 照片管理 +``` +GET /admin/photos # 获取照片列表 (管理视图) +POST /admin/photos # 上传照片 +GET /admin/photos/:id # 获取照片详情 +PUT /admin/photos/:id # 更新照片 +DELETE /admin/photos/:id # 删除照片 +PUT /admin/photos/:id/featured # 设置精选 +POST /admin/photos/batch # 批量操作 +``` + +#### 🏷️ 分类管理 +``` +GET /admin/categories # 获取分类列表 +POST /admin/categories # 创建分类 +GET /admin/categories/:id # 获取分类详情 +PUT /admin/categories/:id # 更新分类 +DELETE /admin/categories/:id # 删除分类 +PUT /admin/categories/sort # 分类排序 +``` + +#### 📊 仪表板统计 +``` +GET /admin/dashboard/stats # 获取统计数据 +GET /admin/dashboard/analytics # 获取分析数据 +GET /admin/dashboard/logs # 获取操作日志 +``` + +## 🔒 权限管理设计 + +### 前端用户权限 +```yaml +前端用户 (Frontend User): + - 权限范围: 只读访问公共内容 + - 认证方式: 可选 JWT (用于个人偏好设置) + - 访问接口: /api/v1/public/*, /api/v1/auth/* + - 特殊权限: 无 +``` + +### 管理员权限 +```yaml +管理员 (Admin): + - 权限范围: 完整的后台管理权限 + - 认证方式: 强制 JWT + 双重认证 + - 访问接口: /admin/* + - 特殊权限: + - 用户管理 + - 内容管理 + - 系统配置 + - 数据统计 +``` + +## 🛡️ 认证系统设计 + +### 双重认证体系 +1. **前端认证**: 基于普通用户的轻量级认证 +2. **管理员认证**: 基于管理员的强认证 + +### JWT Token 隔离 +```yaml +前端 Token: + - 前缀: "Bearer " + - 有效期: 7天 + - 权限: 基础用户权限 + - 存储: localStorage + +管理员 Token: + - 前缀: "Admin " + - 有效期: 2小时 + - 权限: 管理员权限 + - 存储: httpOnly Cookie + localStorage +``` + +## 🚀 实施方案 + +### 第一阶段: 接口分离 +1. 创建新的 API 定义文件 +2. 重构现有接口结构 +3. 添加路由前缀区分 + +### 第二阶段: 认证系统 +1. 实现双重认证中间件 +2. 创建不同的 JWT 策略 +3. 添加权限检查机制 + +### 第三阶段: 数据隔离 +1. 优化前端接口返回数据 +2. 增加管理后台特殊字段 +3. 实现缓存策略 + +## 📁 文件结构调整 + +``` +api/desc/ +├── common.api # 公共类型定义 +├── photography.api # 前端主入口文件 +├── admin.api # 管理后台主入口文件 +├── frontend/ # 前端 API 定义 +│ ├── public.api # 公共展示接口 +│ └── auth.api # 前端认证接口 +└── admin/ # 管理后台 API 定义 + ├── auth.api # 管理员认证 + ├── users.api # 用户管理 + ├── photos.api # 照片管理 + ├── categories.api # 分类管理 + └── dashboard.api # 仪表板 +``` + +## 🎯 优势与收益 + +### 安全性提升 +- **权限隔离**: 前端和管理后台权限完全分离 +- **认证强化**: 管理员采用更强的认证机制 +- **接口隔离**: 降低安全风险 + +### 性能优化 +- **缓存策略**: 前端接口支持高效缓存 +- **数据精简**: 前端只返回必要数据 +- **负载均衡**: 可以独立扩展不同服务 + +### 开发效率 +- **职责清晰**: 前端和后台开发团队分工明确 +- **版本控制**: 可以独立版本管理 +- **部署灵活**: 支持独立部署和扩展 + +--- + +**请确认此设计方案是否符合您的需求,我将根据您的反馈进行调整和实施。** \ No newline at end of file diff --git a/backend/docs/COMPLETED_TASKS_ARCHIVE.md b/backend/docs/COMPLETED_TASKS_ARCHIVE.md new file mode 100644 index 0000000..0da2490 --- /dev/null +++ b/backend/docs/COMPLETED_TASKS_ARCHIVE.md @@ -0,0 +1,89 @@ +# 已完成任务归档 + +## 📋 归档说明 +本文档记录所有已完成的历史任务,按完成时间倒序排列。 + +--- + +## 🎯 2025年7月11日 已完成任务 + +### ✅ 后端服务启动和配置 +**完成时间**: 2025-07-11 15:18 +**任务描述**: 本地启动后端服务,配置 SQLite 数据库环境 +**具体内容**: +- 查看后端项目结构和配置 +- 配置 SQLite 数据库环境 (数据库已存在,包含6个用户、13个分类、35张照片) +- 修复配置文件中的中间件配置问题 +- 成功启动后端服务 (http://localhost:8080) +- 验证健康检查接口正常运行 + +### ✅ API 接口隔离方案设计 +**完成时间**: 2025-07-11 15:30 +**任务描述**: 设计管理后台和前端页面的接口隔离方案 +**具体内容**: +- 分析现有 API 接口结构 +- 设计双重认证体系 (前端轻量级 + 管理员强认证) +- 规划接口路径隔离 (`/api/v1/public/` vs `/admin/`) +- 创建完整的接口隔离设计文档 + +### ✅ API 前缀精简优化 +**完成时间**: 2025-07-11 15:45 +**任务描述**: 精简管理后台 API 前缀,优化路径结构 +**具体内容**: +- 将管理后台 API 前缀从 `/api/v1/admin/` 精简为 `/admin/` +- 优化路径层级结构,提高可读性 +- 更新设计文档中的所有 API 路径 +- 保持前端 API 路径不变 (`/api/v1/public/`) + +### ✅ 详细任务规划制定 +**完成时间**: 2025-07-11 16:00 +**任务描述**: 制定 API 改造的详细任务分解和规划 +**具体内容**: +- 创建 API 改造任务规划文档 +- 按后端、前端页面、管理后台三个模块细分任务 +- 制定 4 个里程碑和时间规划 +- 定义任务优先级和风险控制措施 +- 总计规划 60+ 个具体任务项 + +--- + +## 📊 完成统计 + +### 按模块统计 +- **后端配置**: 4 个任务 ✅ +- **方案设计**: 3 个任务 ✅ +- **文档规划**: 2 个任务 ✅ +- **总计**: 9 个任务已完成 + +### 按时间统计 +- **2025-07-11**: 9 个任务完成 + +### 按类型统计 +- **配置部署**: 4 个任务 +- **架构设计**: 3 个任务 +- **文档编写**: 2 个任务 + +--- + +## 📝 经验总结 + +### 🎯 成功经验 +1. **配置问题快速解决**: 通过逐步添加缺失配置项,成功解决了后端启动问题 +2. **架构设计清晰**: 通过详细的接口隔离方案,明确了改造方向 +3. **任务规划细致**: 通过细分任务,确保了实施的可操作性 + +### 🚨 注意事项 +1. **配置完整性**: 确保所有必需的配置项都已正确设置 +2. **方案确认**: 重要的架构变更需要确认后再实施 +3. **任务优先级**: 按优先级执行任务,确保核心功能优先完成 + +### 🔧 改进建议 +1. **配置模板化**: 可以创建标准配置模板,减少配置错误 +2. **自动化测试**: 增加配置验证和自动化测试 +3. **文档同步**: 确保文档与实际实现保持同步 + +--- + +**📝 归档时间**: 2025-07-11 16:00 +**📋 归档版本**: v1.0 +**👥 维护人**: Development Team \ No newline at end of file diff --git a/backend/etc/photographyapi-api.yaml b/backend/etc/photographyapi-api.yaml index cb721e2..d1bf361 100644 --- a/backend/etc/photographyapi-api.yaml +++ b/backend/etc/photographyapi-api.yaml @@ -34,3 +34,11 @@ file_upload: - image/png - image/gif - image/webp + +middleware: + enable_cors: true + enable_logger: true + enable_error_handle: true + cors_origins: + - "*" + log_level: "info" diff --git a/backend/go.mod b/backend/go.mod index d06c5ea..c0af5ae 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -6,7 +6,7 @@ require ( github.com/disintegration/imaging v1.6.2 github.com/golang-jwt/jwt/v5 v5.2.0 github.com/google/uuid v1.6.0 - github.com/stretchr/testify v1.9.0 + github.com/stretchr/testify v1.10.0 github.com/zeromicro/go-zero v1.8.4 golang.org/x/crypto v0.33.0 gorm.io/driver/mysql v1.5.2 @@ -71,4 +71,4 @@ require ( google.golang.org/protobuf v1.36.5 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect -) \ No newline at end of file +) diff --git a/backend/hash_password.go b/backend/hash_password.go deleted file mode 100644 index 0b83f8d..0000000 --- a/backend/hash_password.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "fmt" - "log" - "photography-backend/pkg/utils/hash" -) - -func main() { - password := "admin123" - hashedPassword, err := hash.HashPassword(password) - if err != nil { - log.Fatal(err) - } - fmt.Printf("Password: %s\n", password) - fmt.Printf("Hashed: %s\n", hashedPassword) -} \ No newline at end of file