Files
photography/backend/internal/handler/routes.go
xujiang fa5f7a0ed2 feat: 实现用户头像上传功能
- 创建头像上传API接口 (POST /api/v1/users/:id/avatar)
- 实现完整的头像上传逻辑,包含权限验证和文件处理
- 添加头像图片处理功能,支持自动压缩和居中裁剪
- 完善静态文件服务,支持头像访问
- 创建完整的API测试用例
- 更新任务进度文档

任务11已完成,项目完成率提升至37.5%
2025-07-11 13:10:04 +08:00

167 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{
{
// 用户登录
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),
},
{
// 上传用户头像
Method: http.MethodPost,
Path: "/:id/avatar",
Handler: user.UploadAvatarHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
rest.WithPrefix("/api/v1/users"),
)
}