70 lines
3.3 KiB
Go
70 lines
3.3 KiB
Go
// Copyright © 2023 OpenIM open source community. All rights reserved.
|
||
//
|
||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||
// you may not use this file except in compliance with the License.
|
||
// You may obtain a copy of the License at
|
||
//
|
||
// http://www.apache.org/licenses/LICENSE-2.0
|
||
//
|
||
// Unless required by applicable law or agreed to in writing, software
|
||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
// See the License for the specific language governing permissions and
|
||
// limitations under the License.
|
||
|
||
package chat
|
||
|
||
import (
|
||
"context"
|
||
"time"
|
||
|
||
"github.com/openimsdk/tools/db/pagination"
|
||
)
|
||
|
||
// FavoriteType 收藏类型
|
||
const (
|
||
FavoriteTypeText = 1 // 文本
|
||
FavoriteTypeImage = 2 // 图片
|
||
FavoriteTypeLink = 3 // 链接
|
||
FavoriteTypeFile = 4 // 文件
|
||
FavoriteTypeVoice = 5 // 语音
|
||
FavoriteTypeVideo = 6 // 视频
|
||
FavoriteTypeLocation = 7 // 位置
|
||
)
|
||
|
||
type Favorite struct {
|
||
ID string `bson:"_id"` // 收藏ID(MongoDB ObjectID)
|
||
UserID string `bson:"user_id"` // 用户ID(收藏者)
|
||
Type int32 `bson:"type"` // 收藏类型:1-文本,2-图片,3-链接,4-文件,5-语音,6-视频,7-位置
|
||
Title string `bson:"title"` // 标题(可选)
|
||
Content string `bson:"content"` // 内容(根据类型不同,可能是文本、图片URL、链接URL、文件路径等)
|
||
Description string `bson:"description"` // 摘要/描述(可选)
|
||
Thumbnail string `bson:"thumbnail"` // 缩略图URL(用于图片、视频、链接等)
|
||
LinkURL string `bson:"link_url"` // 链接URL(用于链接类型)
|
||
FileSize int64 `bson:"file_size"` // 文件大小(字节,用于文件、语音、视频等)
|
||
Duration int32 `bson:"duration"` // 时长(秒,用于语音、视频等)
|
||
Location string `bson:"location"` // 位置信息(JSON格式,用于位置类型)
|
||
Tags []string `bson:"tags"` // 标签列表
|
||
Remark string `bson:"remark"` // 备注(可选)
|
||
Status int32 `bson:"status"` // 状态:0-已删除,1-正常
|
||
CreateTime time.Time `bson:"create_time"` // 创建时间
|
||
UpdateTime time.Time `bson:"update_time"` // 更新时间
|
||
}
|
||
|
||
func (Favorite) TableName() string {
|
||
return "favorites"
|
||
}
|
||
|
||
type FavoriteInterface interface {
|
||
Create(ctx context.Context, favorites ...*Favorite) error
|
||
Take(ctx context.Context, favoriteID string) (*Favorite, error)
|
||
FindByUserID(ctx context.Context, userID string, pagination pagination.Pagination) (int64, []*Favorite, error)
|
||
FindByUserIDAndType(ctx context.Context, userID string, favoriteType int32, pagination pagination.Pagination) (int64, []*Favorite, error)
|
||
SearchByKeyword(ctx context.Context, userID string, keyword string, pagination pagination.Pagination) (int64, []*Favorite, error)
|
||
Update(ctx context.Context, favoriteID string, data map[string]any) error
|
||
Delete(ctx context.Context, favoriteIDs []string) error
|
||
DeleteByUserID(ctx context.Context, userID string) error
|
||
CountByUserID(ctx context.Context, userID string) (int64, error)
|
||
FindByTags(ctx context.Context, userID string, tags []string, pagination pagination.Pagination) (int64, []*Favorite, error)
|
||
}
|