优化结构
This commit is contained in:
+10
-10
@@ -3,21 +3,21 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"kra/internal/biz/system"
|
||||
"time"
|
||||
|
||||
taskbiz "kra/internal/biz/task"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type TaskService struct {
|
||||
uc *system.TaskApplicationUsecase
|
||||
uc *taskbiz.TaskApplicationUsecase
|
||||
}
|
||||
|
||||
func NewTaskService(uc *system.TaskApplicationUsecase) *TaskService {
|
||||
func NewTaskService(uc *taskbiz.TaskApplicationUsecase) *TaskService {
|
||||
return &TaskService{uc: uc}
|
||||
}
|
||||
func taskDomain(v *dto.TaskRequest) *system.TimedTask {
|
||||
return &system.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 taskDomain(v *dto.TaskRequest) *taskbiz.TimedTask {
|
||||
return &taskbiz.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)
|
||||
@@ -30,12 +30,12 @@ func (s *TaskService) UpdateRequest(ctx context.Context, req *dto.TaskRequest) e
|
||||
return s.Update(ctx, taskDomain(req))
|
||||
}
|
||||
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, &system.TimedTask{Name: name, ExecutorType: executorType, EnabledFilter: enabled})
|
||||
return s.Tasks(ctx, page, size, &taskbiz.TimedTask{Name: name, ExecutorType: executorType, EnabledFilter: enabled})
|
||||
}
|
||||
func (s *TaskService) Create(ctx context.Context, v *system.TimedTask) error {
|
||||
func (s *TaskService) Create(ctx context.Context, v *taskbiz.TimedTask) error {
|
||||
return s.uc.Create(ctx, v)
|
||||
}
|
||||
func (s *TaskService) Update(ctx context.Context, v *system.TimedTask) error {
|
||||
func (s *TaskService) Update(ctx context.Context, v *taskbiz.TimedTask) error {
|
||||
return s.uc.Update(ctx, v)
|
||||
}
|
||||
func (s *TaskService) Delete(ctx context.Context, id uint) error {
|
||||
@@ -44,10 +44,10 @@ 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 *system.TimedTask, next *time.Time) *dto.TaskResponse {
|
||||
func taskDTO(v *taskbiz.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 *system.TimedTask) ([]*dto.TaskResponse, int64, error) {
|
||||
func (s *TaskService) Tasks(ctx context.Context, page, size int, q *taskbiz.TimedTask) ([]*dto.TaskResponse, int64, error) {
|
||||
items, total, next, err := s.uc.List(ctx, page, size, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
|
||||
Reference in New Issue
Block a user