This commit is contained in:
2026-08-15 01:40:51 +08:00
parent 2f165d3a45
commit e55fb57432
29 changed files with 163 additions and 124 deletions
+14 -8
View File
@@ -8,22 +8,28 @@ import (
"kra/internal/service/dto"
)
type ParameterService struct{ uc *biz.ParameterUsecase }
func NewParameterService(uc *biz.ParameterUsecase) *ParameterService {
return &ParameterService{uc: uc}
}
func parameterDomain(value *dto.SystemParameterRequest) *biz.SystemParameter {
return &biz.SystemParameter{ID: value.ID, Name: value.Name, Key: value.Key, Value: value.Value, Desc: value.Description}
}
func (s *SettingsService) CreateParameterRequest(ctx context.Context, req *dto.SystemParameterRequest) error {
func (s *ParameterService) CreateParameterRequest(ctx context.Context, req *dto.SystemParameterRequest) error {
return s.CreateParameter(ctx, parameterDomain(req))
}
func (s *SettingsService) UpdateParameterRequest(ctx context.Context, req *dto.SystemParameterRequest) error {
func (s *ParameterService) UpdateParameterRequest(ctx context.Context, req *dto.SystemParameterRequest) error {
return s.UpdateParameter(ctx, parameterDomain(req))
}
func (s *SettingsService) ParametersFilter(ctx context.Context, page, size int, name, key string, start, end *time.Time) ([]map[string]any, int64, error) {
func (s *ParameterService) ParametersFilter(ctx context.Context, page, size int, name, key string, start, end *time.Time) ([]map[string]any, int64, error) {
return s.Parameters(ctx, page, size, &biz.SystemParameter{Name: name, Key: key, StartCreatedAt: start, EndCreatedAt: end})
}
func parameterDTO(v *biz.SystemParameter) map[string]any {
return map[string]any{"ID": v.ID, "CreatedAt": v.CreatedAt, "UpdatedAt": v.UpdatedAt, "DeletedAt": nil, "name": v.Name, "key": v.Key, "value": v.Value, "desc": v.Desc}
}
func (s *SettingsService) Parameters(ctx context.Context, page, size int, q *biz.SystemParameter) ([]map[string]any, int64, error) {
func (s *ParameterService) Parameters(ctx context.Context, page, size int, q *biz.SystemParameter) ([]map[string]any, int64, error) {
items, total, err := s.uc.ListParameters(ctx, page, size, q)
if err != nil {
return nil, 0, err
@@ -34,19 +40,19 @@ func (s *SettingsService) Parameters(ctx context.Context, page, size int, q *biz
}
return out, total, nil
}
func (s *SettingsService) Parameter(ctx context.Context, id uint, key string) (map[string]any, error) {
func (s *ParameterService) Parameter(ctx context.Context, id uint, key string) (map[string]any, error) {
v, err := s.uc.FindParameter(ctx, id, key)
if err != nil {
return nil, err
}
return parameterDTO(v), nil
}
func (s *SettingsService) CreateParameter(ctx context.Context, v *biz.SystemParameter) error {
func (s *ParameterService) CreateParameter(ctx context.Context, v *biz.SystemParameter) error {
return s.uc.CreateParameter(ctx, v)
}
func (s *SettingsService) UpdateParameter(ctx context.Context, v *biz.SystemParameter) error {
func (s *ParameterService) UpdateParameter(ctx context.Context, v *biz.SystemParameter) error {
return s.uc.UpdateParameter(ctx, v)
}
func (s *SettingsService) DeleteParameters(ctx context.Context, ids []uint) error {
func (s *ParameterService) DeleteParameters(ctx context.Context, ids []uint) error {
return s.uc.DeleteParameters(ctx, ids)
}