mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-28 11:16:37 +08:00
8e06b7e149
- Remove all license-related code (handler/service/repository/model) License authorization is managed by separate server: https://github.com/ShukeBta/MediaStationLicenseServer - Fix compilation errors: model field alignment, method name fixes, route conflicts, struct literal corrections (7 files) - Add Chinese README.md as primary, English README_EN.md - Update .gitignore: exclude .workbuddy/, editor backups - Add new repository files: assistant, play_profile, storage_config
40 lines
1.1 KiB
Go
40 lines
1.1 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/ShukeBta/MediaStationGo/internal/model"
|
|
)
|
|
|
|
// StorageConfigRepository persists model.StorageConfig records.
|
|
type StorageConfigRepository struct{ db *gorm.DB }
|
|
|
|
// Get returns the config row by type, or (nil, nil).
|
|
func (r *StorageConfigRepository) Get(ctx context.Context, kind string) (*model.StorageConfig, error) {
|
|
var c model.StorageConfig
|
|
err := r.db.WithContext(ctx).Where("type = ?", kind).First(&c).Error
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return nil, nil
|
|
}
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &c, nil
|
|
}
|
|
|
|
// List returns all storage configs.
|
|
func (r *StorageConfigRepository) List(ctx context.Context) ([]model.StorageConfig, error) {
|
|
var rows []model.StorageConfig
|
|
err := r.db.WithContext(ctx).Order("type asc").Find(&rows).Error
|
|
return rows, err
|
|
}
|
|
|
|
// Upsert creates or replaces a storage config keyed by Type.
|
|
func (r *StorageConfigRepository) Upsert(ctx context.Context, c *model.StorageConfig) error {
|
|
return r.db.WithContext(ctx).Where("type = ?", c.Type).
|
|
Assign(*c).FirstOrCreate(c).Error
|
|
}
|