package repo import ( "errors" "mats/conf" "mats/db/model" "time" "go.mongodb.org/mongo-driver/bson/primitive" ) type AssetTextureRepo struct { Conf *conf.AppAsset Model *model.AssetTexture } func (repo *AssetTextureRepo) GetEntity() interface{} { return repo.Model } func (repo *AssetTextureRepo) Upload(ctx *RepoSession, userId string) (interface{}, error) { asset := repo.Model if asset.Image == nil || len(asset.Image.Url) < 0 || len(asset.Name) < 0 { return nil, errors.New("图片或名称不能为空!") } asset.CreateTime = time.Now() asset.UserId, _ = primitive.ObjectIDFromHex(userId) asset.UpdateTime = time.Now() asset.State = model.AssetState_Created collectionName := "asset-" + repo.Conf.Type return RepoAddDoc(ctx, collectionName, asset) } func (repo *AssetTextureRepo) Update(ctx *RepoSession) (interface{}, error) { asset := repo.Model if len(asset.Id) < 1 { return nil, errors.New("id不能为空!") } id := asset.Id.Hex() asset.Id = primitive.NilObjectID asset.UpdateTime = time.Now() collectionName := "asset-" + repo.Conf.Type return RepoUpdateSetDoc(ctx, collectionName, id, asset) } func (repo *AssetTextureRepo) Detail(ctx *RepoSession, id string) (interface{}, error) { return nil, errors.New("no impl") }