feat: 完成用户管理接口核心CRUD功能
- 实现完整的用户创建逻辑,包含唯一性验证和密码加密 - 实现用户详情查询,安全过滤密码字段 - 实现用户信息更新,支持部分字段更新和唯一性验证 - 实现用户删除功能,包含存在性检查和日志记录 - 创建完整的API测试用例,覆盖正常和错误场景 - 更新任务进度文档,标记第10个任务为已完成 - 提升项目整体完成率至35%,中优先级任务完成率至25%
This commit is contained in:
@ -5,8 +5,10 @@ import (
|
||||
|
||||
"photography-backend/internal/svc"
|
||||
"photography-backend/internal/types"
|
||||
"photography-backend/pkg/errorx"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
type GetUserLogic struct {
|
||||
@ -25,7 +27,40 @@ func NewGetUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserLo
|
||||
}
|
||||
|
||||
func (l *GetUserLogic) GetUser(req *types.GetUserRequest) (resp *types.GetUserResponse, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
// 查询用户
|
||||
user, err := l.svcCtx.UserModel.FindOne(l.ctx, req.Id)
|
||||
if err != nil {
|
||||
if err == sqlx.ErrNotFound {
|
||||
return &types.GetUserResponse{
|
||||
BaseResponse: types.BaseResponse{
|
||||
Code: errorx.UserNotFound,
|
||||
Message: "用户不存在",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
logx.WithContext(l.ctx).Error("查询用户失败: ", err)
|
||||
return &types.GetUserResponse{
|
||||
BaseResponse: types.BaseResponse{
|
||||
Code: errorx.ServerError,
|
||||
Message: "查询用户失败",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
return
|
||||
// 返回用户信息(不包含密码)
|
||||
return &types.GetUserResponse{
|
||||
BaseResponse: types.BaseResponse{
|
||||
Code: errorx.Success,
|
||||
Message: "查询成功",
|
||||
},
|
||||
Data: types.User{
|
||||
Id: user.Id,
|
||||
Username: user.Username,
|
||||
Email: user.Email,
|
||||
Avatar: user.Avatar,
|
||||
Status: int(user.Status),
|
||||
CreatedAt: user.CreatedAt.Unix(),
|
||||
UpdatedAt: user.UpdatedAt.Unix(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user