Skip to content

Commit

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

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

func (s *ContentServerImpl) CreateProduct(ctx context.Context, req *content.CreateProductReq) (res *content.CreateProductResp, err error) {
Expand Down
21 changes: 1 addition & 20 deletions biz/application/service/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ 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 @@ -367,15 +366,6 @@ 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 @@ -667,19 +657,13 @@ 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 @@ -690,12 +674,9 @@ 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)
zone, err := s.ZoneMongoMapper.FindOne(ctx, req.Id)
label, err := s.ZoneMongoMapper.FindOne(ctx, req.Id)
if err != nil {
return resp, err
}
resp.Zone = convertor.ZoneMapperToZone(zone)
resp.Zone = convertor.ZoneMapperToZone(label)
return resp, nil
}

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

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

var (
NotDel int64 = 1
SoftDel int64 = 2
HardDel int64 = 3
)
6 changes: 4 additions & 2 deletions biz/infrastructure/convertor/convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ 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 @@ -80,8 +79,11 @@ 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: 2 additions & 0 deletions biz/infrastructure/mapper/file/filter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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 @@ -73,6 +74,7 @@ func (f *MongoFileFilter) CheckOnlyFileIds() {
return oid
}),
}
fmt.Println(f.m[consts.ID])
}
}

Expand Down
10 changes: 6 additions & 4 deletions biz/infrastructure/mapper/file/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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 @@ -40,7 +41,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, userId string) (int64, error)
Delete(ctx context.Context, id string) (int64, error)
GetConn() *monc.Model
StartClient() *mongo.Client
}
Expand All @@ -58,7 +59,6 @@ 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,12 +184,14 @@ 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 @@ -310,7 +312,7 @@ func (m *MongoMapper) Update(ctx context.Context, data *File) (*mongo.UpdateResu
return res, err
}

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

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{consts.FatherId: fopts}
filter := bson.M{}
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 @@ -19,9 +19,7 @@ require (
google.golang.org/grpc v1.60.1
)

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

require (
github.com/apache/thrift v0.16.0 // indirect
Expand Down

0 comments on commit 93d345a

Please sign in to comment.