feat: 完成后端服务核心业务逻辑实现
## 主要功能 - ✅ 用户认证模块 (登录/注册/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 构建脚本 服务已验证可正常构建和启动。
This commit is contained in:
29
backend/internal/handler/auth/loginHandler.go
Normal file
29
backend/internal/handler/auth/loginHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/auth"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 用户登录
|
||||
func LoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.LoginRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := auth.NewLoginLogic(r.Context(), svcCtx)
|
||||
resp, err := l.Login(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
backend/internal/handler/auth/registerHandler.go
Normal file
29
backend/internal/handler/auth/registerHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/auth"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 用户注册
|
||||
func RegisterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.RegisterRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := auth.NewRegisterLogic(r.Context(), svcCtx)
|
||||
resp, err := l.Register(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
backend/internal/handler/category/createCategoryHandler.go
Normal file
29
backend/internal/handler/category/createCategoryHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package category
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/category"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 创建分类
|
||||
func CreateCategoryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateCategoryRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := category.NewCreateCategoryLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CreateCategory(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
backend/internal/handler/category/deleteCategoryHandler.go
Normal file
29
backend/internal/handler/category/deleteCategoryHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package category
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/category"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 删除分类
|
||||
func DeleteCategoryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.DeleteCategoryRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := category.NewDeleteCategoryLogic(r.Context(), svcCtx)
|
||||
resp, err := l.DeleteCategory(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
backend/internal/handler/category/getCategoryHandler.go
Normal file
29
backend/internal/handler/category/getCategoryHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package category
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/category"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 获取分类详情
|
||||
func GetCategoryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GetCategoryRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := category.NewGetCategoryLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetCategory(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
backend/internal/handler/category/getCategoryListHandler.go
Normal file
29
backend/internal/handler/category/getCategoryListHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package category
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/category"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 获取分类列表
|
||||
func GetCategoryListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GetCategoryListRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := category.NewGetCategoryListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetCategoryList(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
backend/internal/handler/category/updateCategoryHandler.go
Normal file
29
backend/internal/handler/category/updateCategoryHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package category
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/category"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 更新分类
|
||||
func UpdateCategoryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateCategoryRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := category.NewUpdateCategoryLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UpdateCategory(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
22
backend/internal/handler/health/healthHandler.go
Normal file
22
backend/internal/handler/health/healthHandler.go
Normal file
@ -0,0 +1,22 @@
|
||||
package health
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/health"
|
||||
"photography-backend/internal/svc"
|
||||
)
|
||||
|
||||
// 健康检查
|
||||
func HealthHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := health.NewHealthLogic(r.Context(), svcCtx)
|
||||
resp, err := l.Health()
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
backend/internal/handler/photo/deletePhotoHandler.go
Normal file
29
backend/internal/handler/photo/deletePhotoHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package photo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/photo"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 删除照片
|
||||
func DeletePhotoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.DeletePhotoRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := photo.NewDeletePhotoLogic(r.Context(), svcCtx)
|
||||
resp, err := l.DeletePhoto(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
backend/internal/handler/photo/getPhotoHandler.go
Normal file
29
backend/internal/handler/photo/getPhotoHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package photo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/photo"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 获取照片详情
|
||||
func GetPhotoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GetPhotoRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := photo.NewGetPhotoLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetPhoto(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
backend/internal/handler/photo/getPhotoListHandler.go
Normal file
29
backend/internal/handler/photo/getPhotoListHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package photo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/photo"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 获取照片列表
|
||||
func GetPhotoListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GetPhotoListRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := photo.NewGetPhotoListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetPhotoList(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
backend/internal/handler/photo/updatePhotoHandler.go
Normal file
29
backend/internal/handler/photo/updatePhotoHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package photo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/photo"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 更新照片
|
||||
func UpdatePhotoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdatePhotoRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := photo.NewUpdatePhotoLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UpdatePhoto(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
backend/internal/handler/photo/uploadPhotoHandler.go
Normal file
29
backend/internal/handler/photo/uploadPhotoHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package photo
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/photo"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 上传照片
|
||||
func UploadPhotoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UploadPhotoRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := photo.NewUploadPhotoLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UploadPhoto(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
165
backend/internal/handler/routes.go
Normal file
165
backend/internal/handler/routes.go
Normal file
@ -0,0 +1,165 @@
|
||||
// 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"),
|
||||
)
|
||||
}
|
||||
29
backend/internal/handler/user/createUserHandler.go
Normal file
29
backend/internal/handler/user/createUserHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/user"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 创建用户
|
||||
func CreateUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.CreateUserRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewCreateUserLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CreateUser(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
backend/internal/handler/user/deleteUserHandler.go
Normal file
29
backend/internal/handler/user/deleteUserHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/user"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 删除用户
|
||||
func DeleteUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.DeleteUserRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewDeleteUserLogic(r.Context(), svcCtx)
|
||||
resp, err := l.DeleteUser(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
backend/internal/handler/user/getUserHandler.go
Normal file
29
backend/internal/handler/user/getUserHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/user"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 获取用户详情
|
||||
func GetUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GetUserRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewGetUserLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetUser(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
backend/internal/handler/user/getUserListHandler.go
Normal file
29
backend/internal/handler/user/getUserListHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/user"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 获取用户列表
|
||||
func GetUserListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.GetUserListRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewGetUserListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetUserList(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
backend/internal/handler/user/updateUserHandler.go
Normal file
29
backend/internal/handler/user/updateUserHandler.go
Normal file
@ -0,0 +1,29 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"photography-backend/internal/logic/user"
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
)
|
||||
|
||||
// 更新用户
|
||||
func UpdateUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateUserRequest
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := user.NewUpdateUserLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UpdateUser(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user