refactor: split backend transport and domain modules
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"io"
|
||||
"kra/internal/biz"
|
||||
"kra/internal/conf"
|
||||
"kra/internal/service/dto"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -26,6 +27,22 @@ type TaskService struct {
|
||||
func NewTaskService(uc *biz.TaskUsecase, media *biz.MediaUsecase, config *conf.AdminBackend) *TaskService {
|
||||
return &TaskService{uc: uc, media: media, config: config}
|
||||
}
|
||||
func taskDomain(v *dto.TaskRequest) *biz.TimedTask {
|
||||
return &biz.TimedTask{ID: v.ID, Name: v.Name, Description: v.Description, Spec: v.Spec, WithSeconds: v.WithSeconds, ExecutorType: v.ExecutorType, MethodName: v.MethodName, Params: v.Params, HTTPURL: v.HTTPURL, HTTPMethod: v.HTTPMethod, HTTPHeader: v.HTTPHeader, HTTPBody: v.HTTPBody, HTTPAllowPrivate: v.HTTPAllowPrivate, Enabled: v.Enabled}
|
||||
}
|
||||
func (s *TaskService) CreateRequest(ctx context.Context, req *dto.TaskRequest) (uint, error) {
|
||||
value := taskDomain(req)
|
||||
if err := s.Create(ctx, value); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return value.ID, nil
|
||||
}
|
||||
func (s *TaskService) UpdateRequest(ctx context.Context, req *dto.TaskRequest) error {
|
||||
return s.Update(ctx, taskDomain(req))
|
||||
}
|
||||
func (s *TaskService) ListRequest(ctx context.Context, page, size int, name, executorType string, enabled *bool, next map[uint]time.Time) ([]map[string]any, int64, error) {
|
||||
return s.Tasks(ctx, page, size, &biz.TimedTask{Name: name, ExecutorType: executorType, EnabledFilter: enabled}, next)
|
||||
}
|
||||
func (s *TaskService) Validate(v *biz.TimedTask) error {
|
||||
if v.Name == "" {
|
||||
return errors.New("任务名不能为空")
|
||||
|
||||
Reference in New Issue
Block a user