mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-11 09:46:37 +08:00
refactor(repository): 收敛 model/repository 分层为唯一持久化入口
将 OpenFlare 与平台业务的数据访问从 model 与 apps 直连迁入 repository, model 仅保留实体与无 IO 规则;补充 code-check 架构守卫与开发规范。
This commit is contained in:
@@ -5,10 +5,12 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
db "github.com/Rain-kl/Wavelet/internal/infra/persistence"
|
||||
"github.com/Rain-kl/Wavelet/internal/model"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// PushHistoryListFilter filters push history pagination queries.
|
||||
@@ -48,6 +50,19 @@ func CreatePushHistory(ctx context.Context, history *model.PushHistory) error {
|
||||
return db.DB(ctx).Create(history).Error
|
||||
}
|
||||
|
||||
// CountPushHistoriesCreatedBefore returns how many push history rows were created before cutoff.
|
||||
func CountPushHistoriesCreatedBefore(ctx context.Context, cutoff time.Time) (int64, error) {
|
||||
var count int64
|
||||
err := db.DB(ctx).Model(&model.PushHistory{}).Where("created_at < ?", cutoff).Count(&count).Error
|
||||
return count, err
|
||||
}
|
||||
|
||||
// DeletePushHistoriesCreatedBefore deletes push history rows created before cutoff.
|
||||
func DeletePushHistoriesCreatedBefore(ctx context.Context, cutoff time.Time) (int64, error) {
|
||||
result := db.DB(ctx).Where("created_at < ?", cutoff).Delete(&model.PushHistory{})
|
||||
return result.RowsAffected, result.Error
|
||||
}
|
||||
|
||||
// PushHistoryQuery returns a scoped query builder for push histories.
|
||||
func PushHistoryQuery(ctx context.Context) *gorm.DB {
|
||||
return db.DB(ctx).Model(&model.PushHistory{})
|
||||
|
||||
Reference in New Issue
Block a user