Some checks failed
部署管理后台 / 🧪 测试和构建 (push) Failing after 1m5s
部署管理后台 / 🔒 安全扫描 (push) Has been skipped
部署后端服务 / 🧪 测试后端 (push) Failing after 3m13s
部署前端网站 / 🧪 测试和构建 (push) Failing after 2m10s
部署管理后台 / 🚀 部署到生产环境 (push) Has been skipped
部署后端服务 / 🚀 构建并部署 (push) Has been skipped
部署管理后台 / 🔄 回滚部署 (push) Has been skipped
部署前端网站 / 🚀 部署到生产环境 (push) Has been skipped
部署后端服务 / 🔄 回滚部署 (push) Has been skipped
- 后端:应用 go fmt 自动格式化,统一代码风格 - 前端:更新 API 配置,完善类型安全 - 所有代码符合项目规范,准备生产部署
75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package photo
|
|
|
|
import (
|
|
"context"
|
|
|
|
"photography-backend/internal/svc"
|
|
"photography-backend/internal/types"
|
|
"photography-backend/pkg/errorx"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type GetPhotoListLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 获取照片列表
|
|
func NewGetPhotoListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPhotoListLogic {
|
|
return &GetPhotoListLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetPhotoListLogic) GetPhotoList(req *types.GetPhotoListRequest) (resp *types.GetPhotoListResponse, err error) {
|
|
// 1. 查询照片列表
|
|
photos, err := l.svcCtx.PhotoModel.FindList(l.ctx, req.Page, req.PageSize, req.CategoryId, req.UserId, req.Keyword)
|
|
if err != nil {
|
|
logx.Errorf("查询照片列表失败: %v", err)
|
|
return nil, errorx.NewWithCode(errorx.ServerError)
|
|
}
|
|
|
|
// 2. 统计总数
|
|
total, err := l.svcCtx.PhotoModel.Count(l.ctx, req.CategoryId, req.UserId, req.Keyword)
|
|
if err != nil {
|
|
logx.Errorf("统计照片数量失败: %v", err)
|
|
return nil, errorx.NewWithCode(errorx.ServerError)
|
|
}
|
|
|
|
// 3. 转换数据结构
|
|
var photoList []types.Photo
|
|
for _, photo := range photos {
|
|
photoList = append(photoList, types.Photo{
|
|
Id: photo.Id,
|
|
Title: photo.Title,
|
|
Description: photo.Description.String,
|
|
FilePath: photo.FilePath,
|
|
ThumbnailPath: photo.ThumbnailPath,
|
|
UserId: photo.UserId,
|
|
CategoryId: photo.CategoryId,
|
|
CreatedAt: photo.CreatedAt.Unix(),
|
|
UpdatedAt: photo.UpdatedAt.Unix(),
|
|
})
|
|
}
|
|
|
|
// 4. 返回结果
|
|
return &types.GetPhotoListResponse{
|
|
BaseResponse: types.BaseResponse{
|
|
Code: errorx.Success,
|
|
Message: "查询成功",
|
|
},
|
|
Data: types.PhotoListData{
|
|
PageResponse: types.PageResponse{
|
|
Total: total,
|
|
Page: req.Page,
|
|
Size: req.PageSize,
|
|
},
|
|
Photos: photoList,
|
|
},
|
|
}, nil
|
|
}
|