- 创建头像上传API接口 (POST /api/v1/users/:id/avatar) - 实现完整的头像上传逻辑,包含权限验证和文件处理 - 添加头像图片处理功能,支持自动压缩和居中裁剪 - 完善静态文件服务,支持头像访问 - 创建完整的API测试用例 - 更新任务进度文档 任务11已完成,项目完成率提升至37.5%
118 lines
2.4 KiB
Plaintext
118 lines
2.4 KiB
Plaintext
syntax = "v1"
|
|
|
|
import "common.api"
|
|
|
|
// 用户管理接口
|
|
|
|
// 获取用户列表请求
|
|
type GetUserListRequest {
|
|
PageRequest
|
|
Keyword string `form:"keyword,optional"`
|
|
}
|
|
|
|
// 获取用户列表响应
|
|
type GetUserListResponse {
|
|
BaseResponse
|
|
Data UserListData `json:"data"`
|
|
}
|
|
|
|
type UserListData {
|
|
PageResponse
|
|
Users []User `json:"users"`
|
|
}
|
|
|
|
// 获取用户详情请求
|
|
type GetUserRequest {
|
|
Id int64 `path:"id"`
|
|
}
|
|
|
|
// 获取用户详情响应
|
|
type GetUserResponse {
|
|
BaseResponse
|
|
Data User `json:"data"`
|
|
}
|
|
|
|
// 创建用户请求
|
|
type CreateUserRequest {
|
|
Username string `json:"username" validate:"required"`
|
|
Email string `json:"email" validate:"required,email"`
|
|
Password string `json:"password" validate:"required,min=6"`
|
|
}
|
|
|
|
// 创建用户响应
|
|
type CreateUserResponse {
|
|
BaseResponse
|
|
Data User `json:"data"`
|
|
}
|
|
|
|
// 更新用户请求
|
|
type UpdateUserRequest {
|
|
Id int64 `path:"id"`
|
|
Username string `json:"username,optional"`
|
|
Email string `json:"email,optional"`
|
|
Avatar string `json:"avatar,optional"`
|
|
Status int `json:"status,optional"`
|
|
}
|
|
|
|
// 更新用户响应
|
|
type UpdateUserResponse {
|
|
BaseResponse
|
|
Data User `json:"data"`
|
|
}
|
|
|
|
// 删除用户请求
|
|
type DeleteUserRequest {
|
|
Id int64 `path:"id"`
|
|
}
|
|
|
|
// 删除用户响应
|
|
type DeleteUserResponse {
|
|
BaseResponse
|
|
}
|
|
|
|
// 上传头像请求
|
|
type UploadAvatarRequest {
|
|
Id int64 `path:"id"`
|
|
}
|
|
|
|
// 上传头像响应
|
|
type UploadAvatarResponse {
|
|
BaseResponse
|
|
Data UploadAvatarData `json:"data"`
|
|
}
|
|
|
|
type UploadAvatarData {
|
|
AvatarUrl string `json:"avatar_url"`
|
|
}
|
|
|
|
// 用户管理接口组
|
|
@server(
|
|
group: user
|
|
prefix: /api/v1/users
|
|
jwt: Auth
|
|
)
|
|
service photography-api {
|
|
@doc "获取用户列表"
|
|
@handler getUserList
|
|
get / (GetUserListRequest) returns (GetUserListResponse)
|
|
|
|
@doc "创建用户"
|
|
@handler createUser
|
|
post / (CreateUserRequest) returns (CreateUserResponse)
|
|
|
|
@doc "获取用户详情"
|
|
@handler getUser
|
|
get /:id (GetUserRequest) returns (GetUserResponse)
|
|
|
|
@doc "更新用户"
|
|
@handler updateUser
|
|
put /:id (UpdateUserRequest) returns (UpdateUserResponse)
|
|
|
|
@doc "删除用户"
|
|
@handler deleteUser
|
|
delete /:id (DeleteUserRequest) returns (DeleteUserResponse)
|
|
|
|
@doc "上传用户头像"
|
|
@handler uploadAvatar
|
|
post /:id/avatar (UploadAvatarRequest) returns (UploadAvatarResponse)
|
|
} |