repository

package
v0.0.0-...-30b4b00 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package repository 定义数据访问层接口 遵循 Repository 模式,将数据访问逻辑与业务逻辑分离

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelRepository

type ChannelRepository interface {

	// GetByID 根据渠道 ID 获取渠道(带缓存)
	GetByID(id int, useCache bool) (*model.Channel, error)

	// GetByType 根据渠道类型分页获取渠道
	GetByType(startIdx int, num int, idSort bool, channelType int) ([]*model.Channel, error)

	// GetAll 分页获取所有渠道
	GetAll(startIdx int, num int, selectAll bool, idSort bool, sortOptions ...model.ChannelSortOptions) ([]*model.Channel, error)

	// Search 根据关键词/分组/模型搜索渠道
	Search(keyword string, group string, model string, idSort bool, sortOptions ...model.ChannelSortOptions) ([]*model.Channel, error)

	// Insert 创建渠道
	Insert(channel *model.Channel) error

	// Update 更新渠道配置
	Update(channel *model.Channel) error

	// Delete 删除渠道
	Delete(id int) error

	// InvalidateCache 使渠道缓存失效
	InvalidateCache(id int)

	// RefreshCache 刷新所有渠道缓存
	RefreshCache()

	// GetByModel 根据模型获取可用渠道列表(已排序)
	// Deprecated: use Search instead
	GetByModel(modelName string) ([]*model.Channel, error)

	// IsEnabled 检查渠道是否启用
	IsEnabled(id int) bool
}

ChannelRepository 渠道数据访问接口 所有渠道数据操作必须通过此接口

type SkillRepository

type SkillRepository interface {

	// List 分页检索技能目录(category/keyword/status 为空表示不过滤该维度)
	List(category string, keyword string, status string, startIdx int, num int) ([]*model.Skill, int64, error)

	// GetById 根据 ID 获取技能
	GetById(id int64) (*model.Skill, error)

	// GetByNameVersion 根据「名称 + 版本」唯一键获取技能
	GetByNameVersion(name string, version string) (*model.Skill, error)

	// Create 发布(注册)一个新技能版本
	Create(s *model.Skill) error

	// IncrDownloads 下载计数 +1
	IncrDownloads(id int64) error
}

SkillRepository Agent Marketplace 技能目录数据访问接口

type TokenRepository

type TokenRepository interface {

	// GetByKey 根据令牌 Key 获取(useCache=false 时直接从 DB 读取)
	GetByKey(key string, useCache bool) (*model.Token, error)

	// GetByID 根据 ID 获取令牌
	GetByID(id int) (*model.Token, error)

	// GetByIDAndUser 根据 ID + 用户 ID 获取令牌(含权限校验)
	GetByIDAndUser(id, userId int) (*model.Token, error)

	// GetByUserID 根据用户 ID 获取所有令牌(分页)
	GetByUserID(userId, startIdx, num int) ([]*model.Token, error)

	// SearchTokens 搜索用户令牌
	SearchTokens(userId int, keyword, token string, startIdx, num int) ([]*model.Token, int64, error)

	// CountByUserID 统计用户令牌数量
	CountByUserID(userId int) (int64, error)

	// Create 创建新令牌
	Create(token *model.Token) error

	// Update 更新令牌
	Update(token *model.Token) error

	// Delete 删除令牌(自动校验用户 ID)
	Delete(id, userId int) error

	// BatchDelete 批量删除令牌
	BatchDelete(ids []int, userId int) (int, error)

	// GetKeysByIds 批量获取令牌 Key
	GetKeysByIds(ids []int, userId int) ([]model.Token, error)

	// InvalidateCache 使令牌缓存失效
	InvalidateCache(key string)

	// UpdateUsedQuota 更新已用配额
	UpdateUsedQuota(id int, quota int) error

	// GetUsedQuota 获取已用配额
	GetUsedQuota(id int) (int, error)
}

TokenRepository 令牌数据访问接口

type UserRepository

type UserRepository interface {

	// GetByID 根据 ID 获取用户
	GetByID(id int, selectAll bool) (*model.User, error)

	// GetByEmail 根据邮箱获取用户
	GetByEmail(email string) (*model.User, error)

	// GetByAccessToken 根据访问令牌获取用户
	GetByAccessToken(token string) (*model.User, error)

	// GetAll 分页获取所有用户
	GetAll(pageInfo *common.PageInfo) (users []*model.User, total int64, err error)

	// Search 搜索用户
	Search(keyword string, group string, role *int, status *int, startIdx int, num int) ([]*model.User, int64, error)

	// Insert 创建用户
	Insert(user *model.User, inviterId int) error

	// Update 更新用户(调用 user.Update())
	Update(user *model.User, updatePassword bool) error

	// Edit 编辑用户(调用 user.Edit())
	Edit(user *model.User, updatePassword bool) error

	// Delete 软删除用户
	Delete(id int) error

	// HardDelete 硬删除用户
	HardDelete(id int) error

	// SetQuota 直接覆盖配额(管理员操作)
	SetQuota(id int, quota int) error

	// InvalidateCache 驱逐用户缓存
	InvalidateCache(id int) error

	// InvalidateTokensCache 驱逐用户所有令牌缓存
	InvalidateTokensCache(userId int) error

	// CheckExistOrDeleted 检查用户是否存在或已删除
	CheckExistOrDeleted(username string, email string) (bool, error)

	// IsEmailTaken 检查邮箱是否已被占用
	IsEmailTaken(email string) bool

	// GetQuota 获取用户配额
	GetQuota(id int, fromDB bool) (int, error)

	// GetUsedQuota 获取已使用配额
	GetUsedQuota(id int) (int, error)

	// IncreaseQuota 增加配额(db=false 仅更新缓存)
	IncreaseQuota(id int, quota int, db bool) error

	// DecreaseQuota 减少配额(db=false 仅更新缓存)
	DecreaseQuota(id int, quota int, db bool) error

	// DeltaUpdateQuota 原子更新配额
	DeltaUpdateQuota(id int, delta int) error

	// UpdateUsedQuotaAndRequestCount 原子更新已用配额和请求计数
	UpdateUsedQuotaAndRequestCount(id int, quota int) error

	// GetEmail 获取用户邮箱
	GetEmail(id int) (string, error)

	// GetGroup 获取用户分组
	GetGroup(id int, fromDB bool) (string, error)

	// GetSetting 获取用户设置
	GetSetting(id int, fromDB bool) (dto.UserSetting, error)

	// GetUsername 获取用户名
	GetUsername(id int, fromDB bool) (string, error)

	// GetIDByAffCode 根据推广码获取用户 ID
	GetIDByAffCode(affCode string) (int, error)

	// GetMaxID 获取最大用户 ID
	GetMaxID() int

	// IsAdmin 检查是否为管理员
	IsAdmin(userId int) bool

	// ResetPassword 重置密码
	ResetPassword(email string, password string) error

	// UpdateLastLoginAt 更新最后登录时间
	UpdateLastLoginAt(id int)

	// IsWeChatIDTaken 检查微信 ID 是否已被绑定
	IsWeChatIDTaken(wechatId string) bool

	// GetByPhone 根据手机号获取用户
	GetByPhone(phone string) (*model.User, error)

	// IsPhoneRegistered 检查手机号是否已注册
	IsPhoneRegistered(phone string) (bool, error)
}

UserRepository 用户数据访问接口 所有用户数据操作必须通过此接口,不得直接调用 model 层的 SQL 方法

Directories

Path Synopsis
Package impl MySQL 实现仓库 将 repository 接口委托到现有 model 层(所有函数均已验证存在)
Package impl MySQL 实现仓库 将 repository 接口委托到现有 model 层(所有函数均已验证存在)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL