59 lines
2.3 KiB
Go
59 lines
2.3 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"kra/internal/biz"
|
|
"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 *ParameterService) CreateParameterRequest(ctx context.Context, req *dto.SystemParameterRequest) error {
|
|
return s.CreateParameter(ctx, parameterDomain(req))
|
|
}
|
|
func (s *ParameterService) UpdateParameterRequest(ctx context.Context, req *dto.SystemParameterRequest) error {
|
|
return s.UpdateParameter(ctx, parameterDomain(req))
|
|
}
|
|
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 *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
|
|
}
|
|
out := make([]map[string]any, 0, len(items))
|
|
for _, v := range items {
|
|
out = append(out, parameterDTO(v))
|
|
}
|
|
return out, total, nil
|
|
}
|
|
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 *ParameterService) CreateParameter(ctx context.Context, v *biz.SystemParameter) error {
|
|
return s.uc.CreateParameter(ctx, v)
|
|
}
|
|
func (s *ParameterService) UpdateParameter(ctx context.Context, v *biz.SystemParameter) error {
|
|
return s.uc.UpdateParameter(ctx, v)
|
|
}
|
|
func (s *ParameterService) DeleteParameters(ctx context.Context, ids []uint) error {
|
|
return s.uc.DeleteParameters(ctx, ids)
|
|
}
|