2022-09-22 16:16:04 +08:00
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-10-17 16:32:31 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/model"
|
2022-09-22 16:16:04 +08:00
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
type AppDetailRepo struct {
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:33:55 +08:00
|
|
|
func (a AppDetailRepo) WithVersion(version string) DBOption {
|
|
|
|
return func(g *gorm.DB) *gorm.DB {
|
|
|
|
return g.Where("version = ?", version)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func (a AppDetailRepo) WithAppId(id uint) DBOption {
|
|
|
|
return func(g *gorm.DB) *gorm.DB {
|
|
|
|
return g.Where("app_id = ?", id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-03 17:35:39 +08:00
|
|
|
func (a AppDetailRepo) GetFirst(opts ...DBOption) (model.AppDetail, error) {
|
2022-09-23 16:33:55 +08:00
|
|
|
var detail model.AppDetail
|
2022-10-12 10:54:09 +08:00
|
|
|
err := getDb(opts...).Model(&model.AppDetail{}).Find(&detail).Error
|
2022-09-23 16:33:55 +08:00
|
|
|
return detail, err
|
|
|
|
}
|
|
|
|
|
2022-09-30 17:56:06 +08:00
|
|
|
func (a AppDetailRepo) Update(ctx context.Context, detail model.AppDetail) error {
|
2022-10-12 10:54:09 +08:00
|
|
|
return getTx(ctx).Save(&detail).Error
|
2022-09-30 17:56:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a AppDetailRepo) BatchCreate(ctx context.Context, details []model.AppDetail) error {
|
2022-10-12 10:54:09 +08:00
|
|
|
return getTx(ctx).Model(&model.AppDetail{}).Create(&details).Error
|
2022-09-22 16:16:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a AppDetailRepo) DeleteByAppIds(ctx context.Context, appIds []uint) error {
|
2022-10-12 10:54:09 +08:00
|
|
|
return getTx(ctx).Where("app_id in (?)", appIds).Delete(&model.AppDetail{}).Error
|
2022-09-22 16:16:04 +08:00
|
|
|
}
|
|
|
|
|
2022-10-03 17:35:39 +08:00
|
|
|
func (a AppDetailRepo) GetBy(opts ...DBOption) ([]model.AppDetail, error) {
|
2022-09-22 16:16:04 +08:00
|
|
|
var details []model.AppDetail
|
2022-10-12 10:54:09 +08:00
|
|
|
err := getDb(opts...).Find(&details).Error
|
2022-10-03 17:35:39 +08:00
|
|
|
return details, err
|
|
|
|
}
|
|
|
|
|
2022-10-12 10:54:09 +08:00
|
|
|
func (a AppDetailRepo) BatchUpdateBy(maps map[string]interface{}, opts ...DBOption) error {
|
|
|
|
db := getDb(opts...).Model(&model.AppDetail{})
|
|
|
|
if len(opts) == 0 {
|
|
|
|
db = db.Where("1=1")
|
2022-09-22 16:16:04 +08:00
|
|
|
}
|
2022-10-12 10:54:09 +08:00
|
|
|
return db.Updates(&maps).Error
|
2022-09-22 16:16:04 +08:00
|
|
|
}
|