优化
This commit is contained in:
+11
-11
@@ -29,7 +29,7 @@ func (s *TaskService) CreateRequest(ctx context.Context, req *dto.TaskRequest) (
|
||||
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) ([]map[string]any, int64, error) {
|
||||
func (s *TaskService) ListRequest(ctx context.Context, page, size int, name, executorType string, enabled *bool) ([]*dto.TaskResponse, int64, error) {
|
||||
return s.Tasks(ctx, page, size, &biz.TimedTask{Name: name, ExecutorType: executorType, EnabledFilter: enabled})
|
||||
}
|
||||
func (s *TaskService) Create(ctx context.Context, v *biz.TimedTask) error {
|
||||
@@ -44,15 +44,15 @@ func (s *TaskService) Delete(ctx context.Context, id uint) error {
|
||||
func (s *TaskService) Toggle(ctx context.Context, id uint, enabled bool) error {
|
||||
return s.uc.Toggle(ctx, id, enabled)
|
||||
}
|
||||
func taskDTO(v *biz.TimedTask, next *time.Time) map[string]any {
|
||||
return map[string]any{"ID": v.ID, "CreatedAt": v.CreatedAt, "UpdatedAt": v.UpdatedAt, "DeletedAt": nil, "name": v.Name, "description": v.Description, "spec": v.Spec, "withSeconds": v.WithSeconds, "executorType": v.ExecutorType, "methodName": v.MethodName, "params": json.RawMessage(v.Params), "httpUrl": v.HTTPURL, "httpMethod": v.HTTPMethod, "httpHeader": json.RawMessage(v.HTTPHeader), "httpBody": v.HTTPBody, "httpAllowPrivate": v.HTTPAllowPrivate, "enabled": v.Enabled, "nextRunAt": next}
|
||||
func taskDTO(v *biz.TimedTask, next *time.Time) *dto.TaskResponse {
|
||||
return &dto.TaskResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Name: v.Name, Description: v.Description, Spec: v.Spec, WithSeconds: v.WithSeconds, ExecutorType: v.ExecutorType, MethodName: v.MethodName, Params: json.RawMessage(v.Params), HTTPURL: v.HTTPURL, HTTPMethod: v.HTTPMethod, HTTPHeader: json.RawMessage(v.HTTPHeader), HTTPBody: v.HTTPBody, HTTPAllowPrivate: v.HTTPAllowPrivate, Enabled: v.Enabled, NextRunAt: next}
|
||||
}
|
||||
func (s *TaskService) Tasks(ctx context.Context, page, size int, q *biz.TimedTask) ([]map[string]any, int64, error) {
|
||||
func (s *TaskService) Tasks(ctx context.Context, page, size int, q *biz.TimedTask) ([]*dto.TaskResponse, int64, error) {
|
||||
items, total, next, err := s.uc.List(ctx, page, size, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]map[string]any, 0, len(items))
|
||||
out := make([]*dto.TaskResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
var ptr *time.Time
|
||||
if value, ok := next[v.ID]; ok {
|
||||
@@ -64,14 +64,14 @@ func (s *TaskService) Tasks(ctx context.Context, page, size int, q *biz.TimedTas
|
||||
return out, total, nil
|
||||
}
|
||||
|
||||
func (s *TaskService) Logs(ctx context.Context, page, size int, taskID uint, status string) ([]map[string]any, int64, error) {
|
||||
func (s *TaskService) Logs(ctx context.Context, page, size int, taskID uint, status string) ([]*dto.TaskLogResponse, int64, error) {
|
||||
items, total, err := s.uc.Logs(ctx, page, size, taskID, status)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]map[string]any, 0, len(items))
|
||||
out := make([]*dto.TaskLogResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, map[string]any{"ID": v.ID, "CreatedAt": v.CreatedAt, "DeletedAt": nil, "taskId": v.TaskID, "taskName": v.TaskName, "triggerType": v.TriggerType, "startedAt": v.StartedAt, "finishedAt": v.FinishedAt, "durationMs": v.DurationMS, "status": v.Status, "errorMsg": v.ErrorMsg, "output": v.Output})
|
||||
out = append(out, &dto.TaskLogResponse{ID: v.ID, CreatedAt: v.CreatedAt, DeletedAt: nil, TaskID: v.TaskID, TaskName: v.TaskName, TriggerType: v.TriggerType, StartedAt: v.StartedAt, FinishedAt: v.FinishedAt, DurationMS: v.DurationMS, Status: v.Status, ErrorMsg: v.ErrorMsg, Output: v.Output})
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
@@ -81,11 +81,11 @@ func (s *TaskService) Reload(ctx context.Context) error { return s.uc.
|
||||
func (s *TaskService) Subscribe() chan []byte { return s.uc.Subscribe() }
|
||||
func (s *TaskService) Unsubscribe(events chan []byte) { s.uc.Unsubscribe(events) }
|
||||
|
||||
func (s *TaskService) RegisteredMethods() []map[string]any {
|
||||
func (s *TaskService) RegisteredMethods() []*dto.TaskMethodResponse {
|
||||
methods := biz.RegisteredTaskMethods()
|
||||
out := make([]map[string]any, 0, len(methods))
|
||||
out := make([]*dto.TaskMethodResponse, 0, len(methods))
|
||||
for _, method := range methods {
|
||||
out = append(out, map[string]any{"name": method.Name, "description": method.Description})
|
||||
out = append(out, &dto.TaskMethodResponse{Name: method.Name, Description: method.Description})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user