2026-06-26 08:37:04 +00:00
|
|
|
package setting
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
settinguc "haixun-backend/internal/model/setting/domain/usecase"
|
|
|
|
|
"haixun-backend/internal/svc"
|
|
|
|
|
"haixun-backend/internal/types"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type UpsertSettingLogic struct {
|
|
|
|
|
ctx context.Context
|
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewUpsertSettingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpsertSettingLogic {
|
|
|
|
|
return &UpsertSettingLogic{ctx: ctx, svcCtx: svcCtx}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *UpsertSettingLogic) UpsertSetting(req *types.SettingUpsertReq) (*types.SettingData, error) {
|
2026-06-26 16:02:06 +00:00
|
|
|
if err := authorizeSettingAccess(l.ctx, l.svcCtx, req.Scope, req.ScopeID); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
2026-06-26 08:37:04 +00:00
|
|
|
item, err := l.svcCtx.Setting.Upsert(l.ctx, settinguc.UpsertRequest{
|
|
|
|
|
Scope: req.Scope,
|
|
|
|
|
ScopeID: req.ScopeID,
|
|
|
|
|
Key: req.Key,
|
|
|
|
|
Value: req.Value,
|
|
|
|
|
Version: req.Version,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
data := toSettingData(item)
|
|
|
|
|
return &data, nil
|
|
|
|
|
}
|