mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
PR
This commit is contained in:
@@ -11,6 +11,7 @@ type BaseRepository[T any] interface {
|
||||
GetAll(ctx context.Context, offset, limit int, modifier func(*gorm.DB) *gorm.DB) ([]T, int64, error)
|
||||
GetByID(ctx context.Context, id uint, modifier func(*gorm.DB) *gorm.DB) (*T, error)
|
||||
GetByIDs(ctx context.Context, ids []uint, modifier func(*gorm.DB) *gorm.DB) ([]T, error)
|
||||
First(ctx context.Context, modifier func(*gorm.DB) *gorm.DB) (*T, error)
|
||||
|
||||
CreateOne(ctx context.Context, entity *T, modifier func(*gorm.DB) *gorm.DB) error
|
||||
CreateMany(ctx context.Context, entities []*T, modifier func(*gorm.DB) *gorm.DB) error
|
||||
@@ -96,6 +97,21 @@ func (r *BaseRepositoryImpl[T]) GetByIDs(
|
||||
return entities, nil
|
||||
}
|
||||
|
||||
func (r *BaseRepositoryImpl[T]) First(
|
||||
ctx context.Context,
|
||||
modifier func(*gorm.DB) *gorm.DB,
|
||||
) (*T, error) {
|
||||
entity := new(T)
|
||||
q := r.db.WithContext(ctx)
|
||||
if modifier != nil {
|
||||
q = modifier(q)
|
||||
}
|
||||
if err := q.First(entity).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
// ---- CREATE ----
|
||||
func (r *BaseRepositoryImpl[T]) CreateOne(
|
||||
ctx context.Context,
|
||||
|
||||
Reference in New Issue
Block a user