Skip to content

Commit

Permalink
Fix/新增cloudmind content.file.label (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Love-YeLin authored Feb 1, 2024
1 parent 93d345a commit 62b3f0e
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 26 deletions.
3 changes: 1 addition & 2 deletions biz/adaptor/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ type ContentServerImpl struct {
}

func (s *ContentServerImpl) CompletelyRemoveFile(ctx context.Context, req *content.CompletelyRemoveFileReq) (res *content.CompletelyRemoveFileResp, err error) {
//TODO implement me
panic("implement me")
return s.FileService.CompletelyRemoveFile(ctx, req)
}

func (s *ContentServerImpl) CreateProduct(ctx context.Context, req *content.CreateProductReq) (res *content.CreateProductResp, err error) {
Expand Down
21 changes: 20 additions & 1 deletion biz/application/service/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type IFileService interface {
UpdateFile(ctx context.Context, req *gencontent.UpdateFileReq) (resp *gencontent.UpdateFileResp, err error)
MoveFile(ctx context.Context, req *gencontent.MoveFileReq) (resp *gencontent.MoveFileResp, err error)
DeleteFile(ctx context.Context, req *gencontent.DeleteFileReq) (resp *gencontent.DeleteFileResp, err error)
CompletelyRemoveFile(ctx context.Context, req *gencontent.CompletelyRemoveFileReq) (resp *gencontent.CompletelyRemoveFileResp, err error)
RecoverRecycleBinFile(ctx context.Context, req *gencontent.RecoverRecycleBinFileReq) (resp *gencontent.RecoverRecycleBinFileResp, err error)
GetShareList(ctx context.Context, req *gencontent.GetShareListReq) (resp *gencontent.GetShareListResp, err error)
CreateShareCode(ctx context.Context, req *gencontent.CreateShareCodeReq) (resp *gencontent.CreateShareCodeResp, err error)
Expand Down Expand Up @@ -366,6 +367,15 @@ func (s *FileService) MoveFile(ctx context.Context, req *gencontent.MoveFileReq)
return resp, err
}

func (s *FileService) CompletelyRemoveFile(ctx context.Context, req *gencontent.CompletelyRemoveFileReq) (resp *gencontent.CompletelyRemoveFileResp, err error) {
resp = new(gencontent.CompletelyRemoveFileResp)
if _, err = s.FileMongoMapper.Delete(ctx, req.FileId, req.UserId); err != nil {
log.CtxError(ctx, "删除文件: 发生异常[%v]\n", err)
return resp, err
}
return resp, nil
}

func (s *FileService) DeleteFile(ctx context.Context, req *gencontent.DeleteFileReq) (resp *gencontent.DeleteFileResp, err error) {
resp = new(gencontent.DeleteFileResp)
var file *filemapper.File
Expand Down Expand Up @@ -657,13 +667,19 @@ func (s *FileService) SaveFileToPrivateSpace(ctx context.Context, req *genconten
return resp, consts.ErrIllegalOperation
}

// 查看目标文件夹和要保存的文件
if files, err = s.FileMongoMapper.FindManyNotPagination(ctx, &filemapper.FilterOptions{
OnlyFileIds: []string{req.FileId, req.FatherId},
OnlyIsDel: lo.ToPtr(int64(gencontent.IsDel_Is_no)),
}); err != nil {
return resp, err
}

// 判断目标文件夹和要保存的文件是否存在
if len(files) != 2 {
return resp, consts.ErrIllegalOperation
}

if files[0].ID.Hex() != req.FileId {
file = files[1]
objectfile = files[0]
Expand All @@ -674,9 +690,12 @@ func (s *FileService) SaveFileToPrivateSpace(ctx context.Context, req *genconten

if *objectfile.Size != consts.FolderSize {
return resp, consts.ErrFileIsNotDir
}
} // 如果目标文件不是文件夹,则返回错误
if file.UserId == objectfile.UserId {
return resp, consts.ErrIllegalOperation
} // 如果目标文件和要保存的文件是同一个用户的,则返回错误
if req.DocumentType == gencontent.DocumentType_DocumentType_public && (objectfile.Zone == "" || objectfile.SubZone == "") { // 如果要保存的文件不是社区文件,则返回错误
return resp, consts.ErrIllegalOperation
}

tx := s.FileMongoMapper.StartClient()
Expand Down
4 changes: 2 additions & 2 deletions biz/application/service/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ var ZoneSet = wire.NewSet(

func (s *ZoneService) GetZone(ctx context.Context, req *gencontent.GetZoneReq) (resp *gencontent.GetZoneResp, err error) {
resp = new(gencontent.GetZoneResp)
label, err := s.ZoneMongoMapper.FindOne(ctx, req.Id)
zone, err := s.ZoneMongoMapper.FindOne(ctx, req.Id)
if err != nil {
return resp, err
}
resp.Zone = convertor.ZoneMapperToZone(label)
resp.Zone = convertor.ZoneMapperToZone(zone)
return resp, nil
}

Expand Down
10 changes: 6 additions & 4 deletions biz/infrastructure/consts/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const (
Type = "type"
Path = "path"
FatherId = "fatherId"

Size = "size"
FileMd5 = "fileMd5"
IsDel = "isDel"
Expand All @@ -30,9 +29,6 @@ const (
RelationType = "relationType"
DefaultAvatarUrl = "d2042520dce2223751906a11e547d43e.png"
DefaultDescription = "点击添加描述,让大家更好的了解你..."
NotDel = 1
SoftDel = 2
HardDel = 3
PrivateSpace = 1
PublicSpace = 2
Intersection = 1
Expand All @@ -42,3 +38,9 @@ const (
Invalid = 2 // 无效
FolderSize = -1
)

var (
NotDel int64 = 1
SoftDel int64 = 2
HardDel int64 = 3
)
6 changes: 2 additions & 4 deletions biz/infrastructure/convertor/convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func FileMapperToFile(data *file.File) *gencontent.FileInfo {
Zone: data.Zone,
SubZone: data.SubZone,
Description: data.Description,
Labels: data.Labels,
Url: data.Url,
CreateAt: data.CreateAt.UnixMilli(),
UpdateAt: data.UpdateAt.UnixMilli(),
Expand All @@ -79,11 +80,8 @@ func FileToFileMapper(data *gencontent.File) *file.File {
Zone: data.Zone,
SubZone: data.SubZone,
Description: data.Description,
Labels: data.Labels,
Url: data.Url,
CreateAt: time.Time{},
UpdateAt: time.Time{},
DeletedAt: time.Time{},
Score_: 0,
}
}

Expand Down
2 changes: 0 additions & 2 deletions biz/infrastructure/mapper/file/filter.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package file

import (
"fmt"
"github.com/elastic/go-elasticsearch/v8/typedapi/types"
"github.com/samber/lo"
"go.mongodb.org/mongo-driver/bson"
Expand Down Expand Up @@ -74,7 +73,6 @@ func (f *MongoFileFilter) CheckOnlyFileIds() {
return oid
}),
}
fmt.Println(f.m[consts.ID])
}
}

Expand Down
10 changes: 4 additions & 6 deletions biz/infrastructure/mapper/file/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package file
import (
"context"
errorx "errors"
"fmt"
"github.com/CloudStriver/cloudmind-content/biz/infrastructure/config"
"github.com/CloudStriver/cloudmind-content/biz/infrastructure/consts"
"github.com/CloudStriver/go-pkg/utils/pagination"
Expand Down Expand Up @@ -41,7 +40,7 @@ type (
FindManyAndCount(ctx context.Context, fopts *FilterOptions, popts *pagination.PaginationOptions, sorter mongop.MongoCursor) ([]*File, int64, error)
Upsert(ctx context.Context, data *File) (*mongo.UpdateResult, error)
Update(ctx context.Context, data *File) (*mongo.UpdateResult, error)
Delete(ctx context.Context, id string) (int64, error)
Delete(ctx context.Context, id, userId string) (int64, error)
GetConn() *monc.Model
StartClient() *mongo.Client
}
Expand All @@ -59,6 +58,7 @@ type (
Zone string `bson:"zone,omitempty" json:"zone,omitempty"`
SubZone string `bson:"subZone,omitempty" json:"subZone,omitempty"`
Description string `bson:"description,omitempty" json:"description,omitempty"`
Labels []string `bson:"labels,omitempty" json:"labels,omitempty"`
Url string `bson:"url,omitempty" json:"url,omitempty"`
CreateAt time.Time `bson:"createAt,omitempty" json:"createAt,omitempty"`
UpdateAt time.Time `bson:"updateAt,omitempty" json:"updateAt,omitempty"`
Expand Down Expand Up @@ -184,14 +184,12 @@ func (m *MongoMapper) FindMany(ctx context.Context, fopts *FilterOptions, popts
return nil, err
}

fmt.Println(filter)
var data []*File
if err = m.conn.Find(ctx, &data, filter, &options.FindOptions{
Sort: sort,
Limit: popts.Limit,
Skip: popts.Offset,
}); err != nil {
fmt.Println(err)
if errorx.Is(err, monc.ErrNotFound) {
return nil, consts.ErrNotFound
}
Expand Down Expand Up @@ -312,7 +310,7 @@ func (m *MongoMapper) Update(ctx context.Context, data *File) (*mongo.UpdateResu
return res, err
}

func (m *MongoMapper) Delete(ctx context.Context, id string) (int64, error) {
func (m *MongoMapper) Delete(ctx context.Context, id, userId string) (int64, error) {
tracer := otel.GetTracerProvider().Tracer(trace.TraceName)
_, span := tracer.Start(ctx, "mongo.Delete", oteltrace.WithSpanKind(oteltrace.SpanKindConsumer))
defer span.End()
Expand All @@ -322,7 +320,7 @@ func (m *MongoMapper) Delete(ctx context.Context, id string) (int64, error) {
return 0, consts.ErrInvalidId
}
key := prefixFileCacheKey + id
resp, err := m.conn.DeleteOne(ctx, key, bson.M{consts.ID: oid})
resp, err := m.conn.DeleteOne(ctx, key, bson.M{consts.ID: oid, consts.UserId: userId})
return resp, err
}

Expand Down
4 changes: 2 additions & 2 deletions biz/infrastructure/mapper/zone/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (m *MongoMapper) Count(ctx context.Context, fopts string) (int64, error) {
_, span := tracer.Start(ctx, "mongo.Count", oteltrace.WithSpanKind(oteltrace.SpanKindConsumer))
defer span.End()

return m.conn.CountDocuments(ctx, bson.M{})
return m.conn.CountDocuments(ctx, bson.M{consts.FatherId: fopts})
}

func (m *MongoMapper) Insert(ctx context.Context, data *Zone) (string, error) {
Expand Down Expand Up @@ -111,7 +111,7 @@ func (m *MongoMapper) FindMany(ctx context.Context, fopts string, popts *paginat
defer span.End()

p := mongop.NewMongoPaginator(pagination.NewRawStore(sorter), popts)
filter := bson.M{}
filter := bson.M{consts.FatherId: fopts}
sort, err := p.MakeSortOptions(ctx, filter)
if err != nil {
return nil, err
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/CloudStriver/go-pkg v0.0.0-20231229114943-910edcb8788d
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240201060740-cadd39081dc7
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240201082032-be9a2ef30717
github.com/bytedance/sonic v1.10.2
github.com/cloudwego/kitex v0.8.0
github.com/elastic/go-elasticsearch/v8 v8.11.1
Expand All @@ -19,8 +19,6 @@ require (
google.golang.org/grpc v1.60.1
)

//replace github.com/CloudStriver/service-idl-gen-go => ../service-idl-gen-go

require (
github.com/apache/thrift v0.16.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ github.com/CloudStriver/go-pkg v0.0.0-20231229114943-910edcb8788d h1:c5M3637HJJN
github.com/CloudStriver/go-pkg v0.0.0-20231229114943-910edcb8788d/go.mod h1:Oj6+J8ixQxqNunSpl9v64q6tAQ83wY/rRFI+3rhHVCk=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240201060740-cadd39081dc7 h1:FUhcRGxdhBvxV3uFlbaiRjWJw516KM7wJLv9FhHUwvA=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240201060740-cadd39081dc7/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240201073608-8cd061d59e6d h1:wlZObzrhfV647crFvmvQsfxMftZ6ejCinzd84drnI7k=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240201073608-8cd061d59e6d/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240201082032-be9a2ef30717 h1:GQWaeW0C0gs85P6e6L3YTVzTnUSU7H1HCLZWcaj4F+U=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240201082032-be9a2ef30717/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY=
github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
Expand Down

0 comments on commit 62b3f0e

Please sign in to comment.