package photo import ( "context" "photography-backend/internal/model" "photography-backend/internal/svc" "photography-backend/internal/types" "photography-backend/pkg/errorx" "github.com/zeromicro/go-zero/core/logx" ) type GetPhotoLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } // 获取照片详情 func NewGetPhotoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPhotoLogic { return &GetPhotoLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *GetPhotoLogic) GetPhoto(req *types.GetPhotoRequest) (resp *types.GetPhotoResponse, err error) { // 1. 查询照片信息 photo, err := l.svcCtx.PhotoModel.FindOne(l.ctx, req.Id) if err != nil { if err == model.ErrNotFound { return nil, errorx.NewWithCode(errorx.PhotoNotFound) } logx.Errorf("查询照片失败: %v", err) return nil, errorx.NewWithCode(errorx.ServerError) } // 2. 返回结果 return &types.GetPhotoResponse{ BaseResponse: types.BaseResponse{ Code: errorx.Success, Message: "查询成功", }, Data: 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(), }, }, nil }