## 主要功能 - ✅ 用户认证模块 (登录/注册/JWT) - ✅ 照片管理模块 (上传/查询/分页/搜索) - ✅ 分类管理模块 (创建/查询/分页) - ✅ 用户管理模块 (用户列表/分页查询) - ✅ 健康检查接口 ## 技术实现 - 基于 go-zero v1.8.0 标准架构 - Handler → Logic → Model 三层架构 - SQLite/PostgreSQL 数据库支持 - JWT 认证机制 - bcrypt 密码加密 - 统一响应格式 - 自定义模型方法 (分页/搜索) ## API 接口 - POST /api/v1/auth/login - 用户登录 - POST /api/v1/auth/register - 用户注册 - GET /api/v1/health - 健康检查 - GET /api/v1/photos - 照片列表 - POST /api/v1/photos - 上传照片 - GET /api/v1/categories - 分类列表 - POST /api/v1/categories - 创建分类 - GET /api/v1/users - 用户列表 ## 配置完成 - 开发环境配置 (SQLite) - 生产环境支持 (PostgreSQL) - JWT 认证配置 - 文件上传配置 - Makefile 构建脚本 服务已验证可正常构建和启动。
166 lines
3.5 KiB
Go
166 lines
3.5 KiB
Go
// Code generated by goctl. DO NOT EDIT.
|
|
// goctl 1.8.4
|
|
|
|
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
auth "photography-backend/internal/handler/auth"
|
|
category "photography-backend/internal/handler/category"
|
|
health "photography-backend/internal/handler/health"
|
|
photo "photography-backend/internal/handler/photo"
|
|
user "photography-backend/internal/handler/user"
|
|
"photography-backend/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/rest"
|
|
)
|
|
|
|
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|
server.AddRoutes(
|
|
[]rest.Route{},
|
|
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
|
)
|
|
|
|
server.AddRoutes(
|
|
[]rest.Route{
|
|
{
|
|
// 用户登录
|
|
Method: http.MethodPost,
|
|
Path: "/login",
|
|
Handler: auth.LoginHandler(serverCtx),
|
|
},
|
|
{
|
|
// 用户注册
|
|
Method: http.MethodPost,
|
|
Path: "/register",
|
|
Handler: auth.RegisterHandler(serverCtx),
|
|
},
|
|
},
|
|
rest.WithPrefix("/api/v1/auth"),
|
|
)
|
|
|
|
server.AddRoutes(
|
|
[]rest.Route{
|
|
{
|
|
// 获取分类列表
|
|
Method: http.MethodGet,
|
|
Path: "/",
|
|
Handler: category.GetCategoryListHandler(serverCtx),
|
|
},
|
|
{
|
|
// 创建分类
|
|
Method: http.MethodPost,
|
|
Path: "/",
|
|
Handler: category.CreateCategoryHandler(serverCtx),
|
|
},
|
|
{
|
|
// 获取分类详情
|
|
Method: http.MethodGet,
|
|
Path: "/:id",
|
|
Handler: category.GetCategoryHandler(serverCtx),
|
|
},
|
|
{
|
|
// 更新分类
|
|
Method: http.MethodPut,
|
|
Path: "/:id",
|
|
Handler: category.UpdateCategoryHandler(serverCtx),
|
|
},
|
|
{
|
|
// 删除分类
|
|
Method: http.MethodDelete,
|
|
Path: "/:id",
|
|
Handler: category.DeleteCategoryHandler(serverCtx),
|
|
},
|
|
},
|
|
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
|
rest.WithPrefix("/api/v1/categories"),
|
|
)
|
|
|
|
server.AddRoutes(
|
|
[]rest.Route{
|
|
{
|
|
// 健康检查
|
|
Method: http.MethodGet,
|
|
Path: "/health",
|
|
Handler: health.HealthHandler(serverCtx),
|
|
},
|
|
},
|
|
rest.WithPrefix("/api/v1"),
|
|
)
|
|
|
|
server.AddRoutes(
|
|
[]rest.Route{
|
|
{
|
|
// 获取照片列表
|
|
Method: http.MethodGet,
|
|
Path: "/",
|
|
Handler: photo.GetPhotoListHandler(serverCtx),
|
|
},
|
|
{
|
|
// 上传照片
|
|
Method: http.MethodPost,
|
|
Path: "/",
|
|
Handler: photo.UploadPhotoHandler(serverCtx),
|
|
},
|
|
{
|
|
// 获取照片详情
|
|
Method: http.MethodGet,
|
|
Path: "/:id",
|
|
Handler: photo.GetPhotoHandler(serverCtx),
|
|
},
|
|
{
|
|
// 更新照片
|
|
Method: http.MethodPut,
|
|
Path: "/:id",
|
|
Handler: photo.UpdatePhotoHandler(serverCtx),
|
|
},
|
|
{
|
|
// 删除照片
|
|
Method: http.MethodDelete,
|
|
Path: "/:id",
|
|
Handler: photo.DeletePhotoHandler(serverCtx),
|
|
},
|
|
},
|
|
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
|
rest.WithPrefix("/api/v1/photos"),
|
|
)
|
|
|
|
server.AddRoutes(
|
|
[]rest.Route{
|
|
{
|
|
// 获取用户列表
|
|
Method: http.MethodGet,
|
|
Path: "/",
|
|
Handler: user.GetUserListHandler(serverCtx),
|
|
},
|
|
{
|
|
// 创建用户
|
|
Method: http.MethodPost,
|
|
Path: "/",
|
|
Handler: user.CreateUserHandler(serverCtx),
|
|
},
|
|
{
|
|
// 获取用户详情
|
|
Method: http.MethodGet,
|
|
Path: "/:id",
|
|
Handler: user.GetUserHandler(serverCtx),
|
|
},
|
|
{
|
|
// 更新用户
|
|
Method: http.MethodPut,
|
|
Path: "/:id",
|
|
Handler: user.UpdateUserHandler(serverCtx),
|
|
},
|
|
{
|
|
// 删除用户
|
|
Method: http.MethodDelete,
|
|
Path: "/:id",
|
|
Handler: user.DeleteUserHandler(serverCtx),
|
|
},
|
|
},
|
|
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
|
rest.WithPrefix("/api/v1/users"),
|
|
)
|
|
}
|