37 lines
927 B
Go
37 lines
927 B
Go
package systemconfig
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"hfb_sys/backend/internal/modules/rentergrowth"
|
|
)
|
|
|
|
func (s *Service) Update(ctx context.Context, actorID uint64, key string, req UpdateRequest, meta AuditMeta) (*ConfigDTO, error) {
|
|
if s.repo == nil {
|
|
return nil, ErrDependencyUnavailable
|
|
}
|
|
if key == "" || (req.Value == "" && key != "integration.paddle_ocr_token") {
|
|
return nil, ErrInvalidConfig
|
|
}
|
|
if key == "listing.publish_cooldown_minutes" {
|
|
minutes, err := strconv.Atoi(strings.TrimSpace(req.Value))
|
|
if err != nil || minutes < 0 {
|
|
return nil, ErrInvalidConfig
|
|
}
|
|
}
|
|
if key == rentergrowth.ConfigKey {
|
|
cfg, err := rentergrowth.ParseConfigValue(req.Value)
|
|
if err != nil {
|
|
return nil, ErrInvalidConfig
|
|
}
|
|
value, err := rentergrowth.MarshalConfig(cfg)
|
|
if err != nil {
|
|
return nil, ErrInvalidConfig
|
|
}
|
|
req.Value = value
|
|
}
|
|
return s.repo.Update(ctx, actorID, key, req, meta)
|
|
}
|