commit code
This commit is contained in:
@ -3,11 +3,14 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
|
||||
"godemo/category/category"
|
||||
"godemo/file/file"
|
||||
"godemo/gallery/gallery"
|
||||
"godemo/gallery/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type UploadImageLogic struct {
|
||||
@ -27,13 +30,18 @@ func NewUploadImageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Uploa
|
||||
// 图片上传
|
||||
func (l *UploadImageLogic) UploadImage(in *gallery.UploadImageRequest) (*gallery.UploadImageResponse, error) {
|
||||
// 1. 根据 in.CategoryId 查询分类信息,获取分类名称
|
||||
var categoryName string
|
||||
getCategoryRpcResp, getCategoryRpcErr := l.svcCtx.CategoryRpc.GetCategory(l.ctx, &category.GetCategoryRequest{
|
||||
Id: *in.CategoryId,
|
||||
})
|
||||
if getCategoryRpcErr != nil {
|
||||
return nil, status.Error(codes.Internal, getCategoryRpcErr.Error())
|
||||
}
|
||||
|
||||
// 2. 调用 file rpc Upload 接口,上传文件到MinIO
|
||||
l.svcCtx.FileRpc.Upload(l.ctx, &file.UploadRequest{
|
||||
fileUploadRpcResp, fileUploadRpcErr := l.svcCtx.FileRpc.Upload(l.ctx, &file.UploadRequest{
|
||||
Filename: in.FileName,
|
||||
Content: in.FileContent,
|
||||
Folder: categoryName,
|
||||
Folder: getCategoryRpcResp.Category.Name,
|
||||
})
|
||||
|
||||
// 3. 图片信息存入数据库
|
||||
|
||||
Reference in New Issue
Block a user