f
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tyapi-server/internal/domains/api/entities"
|
||||
"tyapi-server/internal/domains/api/repositories"
|
||||
"tyapi-server/internal/shared/database"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const (
|
||||
ReportsTable = "reports"
|
||||
)
|
||||
|
||||
// GormReportRepository 报告记录 GORM 仓储实现
|
||||
type GormReportRepository struct {
|
||||
*database.BaseRepositoryImpl
|
||||
}
|
||||
|
||||
var _ repositories.ReportRepository = (*GormReportRepository)(nil)
|
||||
|
||||
// NewGormReportRepository 创建报告记录仓储实现
|
||||
func NewGormReportRepository(db *gorm.DB, logger *zap.Logger) repositories.ReportRepository {
|
||||
return &GormReportRepository{
|
||||
BaseRepositoryImpl: database.NewBaseRepositoryImpl(db, logger),
|
||||
}
|
||||
}
|
||||
|
||||
// Create 创建报告记录
|
||||
func (r *GormReportRepository) Create(ctx context.Context, report *entities.Report) error {
|
||||
return r.CreateEntity(ctx, report)
|
||||
}
|
||||
|
||||
// FindByReportID 根据报告编号查询记录
|
||||
func (r *GormReportRepository) FindByReportID(ctx context.Context, reportID string) (*entities.Report, error) {
|
||||
var report entities.Report
|
||||
if err := r.FindOneByField(ctx, &report, "report_id", reportID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &report, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user