mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-24 15:25:43 +00:00
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gitlab.com/mbugroup/lti-api.git/internal/common/repository"
|
|
entity "gitlab.com/mbugroup/lti-api.git/internal/entities"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type KandangRepository interface {
|
|
repository.BaseRepository[entity.Kandang]
|
|
LocationExists(ctx context.Context, areaId uint) (bool, error)
|
|
PicExists(ctx context.Context, areaId uint) (bool, error)
|
|
NameExists(ctx context.Context, name string, excludeID *uint) (bool, error)
|
|
}
|
|
|
|
type KandangRepositoryImpl struct {
|
|
*repository.BaseRepositoryImpl[entity.Kandang]
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewKandangRepository(db *gorm.DB) KandangRepository {
|
|
return &KandangRepositoryImpl{
|
|
BaseRepositoryImpl: repository.NewBaseRepository[entity.Kandang](db),
|
|
db: db,
|
|
}
|
|
}
|
|
|
|
func (r *KandangRepositoryImpl) LocationExists(ctx context.Context, locationId uint) (bool, error) {
|
|
return repository.Exists[entity.Location](ctx, r.db, locationId)
|
|
}
|
|
|
|
func (r *KandangRepositoryImpl) PicExists(ctx context.Context, picId uint) (bool, error) {
|
|
return repository.Exists[entity.User](ctx, r.db, picId)
|
|
}
|
|
|
|
func (r *KandangRepositoryImpl) NameExists(ctx context.Context, name string, excludeID *uint) (bool, error) {
|
|
return repository.ExistsByName[entity.Kandang](ctx, r.db, name, excludeID)
|
|
}
|