优化结构
This commit is contained in:
@@ -2,7 +2,7 @@ package dto
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"kra/internal/biz/system"
|
||||
integrationbiz "kra/internal/biz/integration"
|
||||
)
|
||||
|
||||
type IntegrationConfigRequest struct {
|
||||
@@ -11,12 +11,12 @@ type IntegrationConfigRequest struct {
|
||||
}
|
||||
|
||||
type IntegrationConfigResponse struct {
|
||||
Kind string `json:"kind"`
|
||||
Provider string `json:"provider"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Configured bool `json:"configured"`
|
||||
Config json.RawMessage `json:"config"`
|
||||
Fields []system.IntegrationConfigField `json:"fields"`
|
||||
Kind string `json:"kind"`
|
||||
Provider string `json:"provider"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Configured bool `json:"configured"`
|
||||
Config json.RawMessage `json:"config"`
|
||||
Fields []integrationbiz.IntegrationConfigField `json:"fields"`
|
||||
}
|
||||
|
||||
@@ -3,16 +3,16 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"kra/internal/biz/system"
|
||||
integrationbiz "kra/internal/biz/integration"
|
||||
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type IntegrationConfigService struct {
|
||||
uc *system.IntegrationConfigUsecase
|
||||
uc *integrationbiz.IntegrationConfigUsecase
|
||||
}
|
||||
|
||||
func NewIntegrationConfigService(uc *system.IntegrationConfigUsecase) *IntegrationConfigService {
|
||||
func NewIntegrationConfigService(uc *integrationbiz.IntegrationConfigUsecase) *IntegrationConfigService {
|
||||
return &IntegrationConfigService{uc: uc}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@ func (s *IntegrationConfigService) List(ctx context.Context, kind string) ([]*dt
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
byProvider := make(map[string]*system.IntegrationConfig, len(configs))
|
||||
byProvider := make(map[string]*integrationbiz.IntegrationConfig, len(configs))
|
||||
for _, config := range configs {
|
||||
if config != nil {
|
||||
byProvider[config.Provider] = config
|
||||
}
|
||||
}
|
||||
definitions := system.IntegrationDefinitions(kind)
|
||||
definitions := integrationbiz.IntegrationDefinitions(kind)
|
||||
result := make([]*dto.IntegrationConfigResponse, 0, len(definitions)+len(configs))
|
||||
for _, definition := range definitions {
|
||||
config, configured := byProvider[definition.Provider]
|
||||
@@ -54,7 +54,7 @@ func (s *IntegrationConfigService) Find(ctx context.Context, kind, provider stri
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
definition, found := system.IntegrationDefinition(config.Kind, config.Provider)
|
||||
definition, found := integrationbiz.IntegrationDefinition(config.Kind, config.Provider)
|
||||
response := &dto.IntegrationConfigResponse{Kind: config.Kind, Provider: config.Provider, Name: config.Provider, Enabled: config.Enabled, Configured: true, Config: config.Values}
|
||||
if found {
|
||||
response.Name = definition.Name
|
||||
@@ -69,14 +69,14 @@ func (s *IntegrationConfigService) Save(ctx context.Context, kind, provider stri
|
||||
if req == nil {
|
||||
return s.uc.Save(ctx, nil)
|
||||
}
|
||||
return s.uc.Save(ctx, &system.IntegrationConfig{Kind: kind, Provider: provider, Enabled: req.Enabled, Values: req.Config})
|
||||
return s.uc.Save(ctx, &integrationbiz.IntegrationConfig{Kind: kind, Provider: provider, Enabled: req.Enabled, Values: req.Config})
|
||||
}
|
||||
|
||||
func (s *IntegrationConfigService) Test(ctx context.Context, kind, provider string, req *dto.IntegrationConfigRequest) error {
|
||||
if req == nil {
|
||||
return s.uc.Test(ctx, nil)
|
||||
}
|
||||
return s.uc.Test(ctx, &system.IntegrationConfig{Kind: kind, Provider: provider, Enabled: true, Values: req.Config})
|
||||
return s.uc.Test(ctx, &integrationbiz.IntegrationConfig{Kind: kind, Provider: provider, Enabled: true, Values: req.Config})
|
||||
}
|
||||
|
||||
func (s *IntegrationConfigService) Delete(ctx context.Context, kind, provider string) error {
|
||||
|
||||
+13
-13
@@ -3,14 +3,14 @@ package service
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"kra/internal/biz/system"
|
||||
paymentbiz "kra/internal/biz/payment"
|
||||
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type PaymentService struct{ uc *system.PaymentUsecase }
|
||||
type PaymentService struct{ uc *paymentbiz.PaymentUsecase }
|
||||
|
||||
func NewPaymentService(uc *system.PaymentUsecase) *PaymentService { return &PaymentService{uc: uc} }
|
||||
func NewPaymentService(uc *paymentbiz.PaymentUsecase) *PaymentService { return &PaymentService{uc: uc} }
|
||||
func (s *PaymentService) Order(ctx context.Context, provider, tradeNo string) (*dto.PaymentOrderResponse, error) {
|
||||
order, err := s.uc.Order(ctx, provider, tradeNo)
|
||||
if err != nil {
|
||||
@@ -44,7 +44,7 @@ func (s *PaymentService) Orders(ctx context.Context, req *dto.PaymentOrderListRe
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
items, total, err := s.uc.Orders(ctx, page, pageSize, system.PaymentOrderFilter{
|
||||
items, total, err := s.uc.Orders(ctx, page, pageSize, paymentbiz.PaymentOrderFilter{
|
||||
Provider: req.Provider, TradeNo: req.TradeNo, BusinessType: req.BusinessType,
|
||||
BusinessID: req.BusinessID, PaymentStatus: req.PaymentStatus, RefundStatus: req.RefundStatus,
|
||||
})
|
||||
@@ -62,7 +62,7 @@ func (s *PaymentService) Orders(ctx context.Context, req *dto.PaymentOrderListRe
|
||||
return result, total, page, pageSize, nil
|
||||
}
|
||||
|
||||
func paymentOrderResponse(order *system.PaymentOrder) (*dto.PaymentOrderResponse, error) {
|
||||
func paymentOrderResponse(order *paymentbiz.PaymentOrder) (*dto.PaymentOrderResponse, error) {
|
||||
if order == nil {
|
||||
return nil, errors.New("支付订单为空")
|
||||
}
|
||||
@@ -84,7 +84,7 @@ func (s *PaymentService) Create(ctx context.Context, req *dto.PaymentRequest) (*
|
||||
if req == nil {
|
||||
return nil, errors.New("支付请求为空")
|
||||
}
|
||||
result, err := s.uc.Create(ctx, &system.PaymentRequest{
|
||||
result, err := s.uc.Create(ctx, &paymentbiz.PaymentRequest{
|
||||
Provider: req.Provider, TradeNo: req.TradeNo, Subject: req.Subject,
|
||||
Amount: req.Amount, OriginalAmount: req.OriginalAmount, Currency: req.Currency,
|
||||
NotifyURL: req.NotifyURL, ReturnURL: req.ReturnURL, ClientIP: req.ClientIP,
|
||||
@@ -130,13 +130,13 @@ func (s *PaymentService) Fulfill(ctx context.Context, req *dto.PaymentFulfillReq
|
||||
}
|
||||
func (s *PaymentService) Callback(ctx context.Context, req *dto.PaymentCallbackRequest) (dto.PaymentCallbackAck, error) {
|
||||
if req == nil {
|
||||
return paymentCallbackAckResponse(system.DefaultPaymentCallbackAck("", false)), errors.New("支付回调请求为空")
|
||||
return paymentCallbackAckResponse(paymentbiz.DefaultPaymentCallbackAck("", false)), errors.New("支付回调请求为空")
|
||||
}
|
||||
result, err := s.uc.Callback(ctx, &system.PaymentCallback{Provider: req.Provider, Headers: req.Headers, Body: req.Body, Query: req.Query})
|
||||
result, err := s.uc.Callback(ctx, &paymentbiz.PaymentCallback{Provider: req.Provider, Headers: req.Headers, Body: req.Body, Query: req.Query})
|
||||
if err != nil {
|
||||
return paymentCallbackAckResponse(system.CallbackFailure(err, system.DefaultPaymentCallbackAck(req.Provider, false))), err
|
||||
return paymentCallbackAckResponse(paymentbiz.CallbackFailure(err, paymentbiz.DefaultPaymentCallbackAck(req.Provider, false))), err
|
||||
}
|
||||
ack := system.DefaultPaymentCallbackAck(req.Provider, true)
|
||||
ack := paymentbiz.DefaultPaymentCallbackAck(req.Provider, true)
|
||||
if result != nil && result.SuccessAck.StatusCode != 0 {
|
||||
ack = result.SuccessAck
|
||||
}
|
||||
@@ -144,10 +144,10 @@ func (s *PaymentService) Callback(ctx context.Context, req *dto.PaymentCallbackR
|
||||
}
|
||||
|
||||
func DefaultPaymentCallbackAck(provider string, success bool) dto.PaymentCallbackAck {
|
||||
return paymentCallbackAckResponse(system.DefaultPaymentCallbackAck(provider, success))
|
||||
return paymentCallbackAckResponse(paymentbiz.DefaultPaymentCallbackAck(provider, success))
|
||||
}
|
||||
|
||||
func paymentResultResponse(result *system.PaymentResult) *dto.PaymentResultResponse {
|
||||
func paymentResultResponse(result *paymentbiz.PaymentResult) *dto.PaymentResultResponse {
|
||||
if result == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -165,6 +165,6 @@ func paymentResultResponse(result *system.PaymentResult) *dto.PaymentResultRespo
|
||||
}
|
||||
}
|
||||
|
||||
func paymentCallbackAckResponse(ack system.PaymentCallbackAck) dto.PaymentCallbackAck {
|
||||
func paymentCallbackAckResponse(ack paymentbiz.PaymentCallbackAck) dto.PaymentCallbackAck {
|
||||
return dto.PaymentCallbackAck{StatusCode: ack.StatusCode, ContentType: ack.ContentType, Body: ack.Body}
|
||||
}
|
||||
|
||||
+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