优化结构
This commit is contained in:
+13
-13
@@ -4,10 +4,10 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"kra/internal/biz/system"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"kra/internal/biz"
|
||||
"kra/internal/service/dto"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -20,8 +20,8 @@ var (
|
||||
)
|
||||
|
||||
type ExportService struct {
|
||||
uc *biz.ExportUsecase
|
||||
cache biz.Cache
|
||||
uc *system.ExportUsecase
|
||||
cache system.Cache
|
||||
}
|
||||
|
||||
type ExportToken struct {
|
||||
@@ -36,7 +36,7 @@ type exportTokenCache struct {
|
||||
Blank bool `json:"blank"`
|
||||
}
|
||||
|
||||
func NewExportService(uc *biz.ExportUsecase, cache biz.Cache) *ExportService {
|
||||
func NewExportService(uc *system.ExportUsecase, cache system.Cache) *ExportService {
|
||||
return &ExportService{uc: uc, cache: cache}
|
||||
}
|
||||
|
||||
@@ -67,13 +67,13 @@ func (s *ExportService) ConsumeToken(ctx context.Context, token string, expectBl
|
||||
_ = s.cache.Delete(ctx, "export:"+token)
|
||||
return &ExportToken{TemplateID: value.TemplateID, Params: value.Params, Blank: value.Blank}, nil
|
||||
}
|
||||
func exportTemplateDomain(value *dto.ExportTemplateRequest) *biz.ExportTemplate {
|
||||
out := &biz.ExportTemplate{ID: value.ID, DBName: value.DBName, Name: value.Name, TableName: value.TableName, TemplateID: value.TemplateID, TemplateInfo: value.TemplateInfo, SQL: value.SQL, ImportSQL: value.ImportSQL, Limit: value.Limit, Order: value.Order}
|
||||
func exportTemplateDomain(value *dto.ExportTemplateRequest) *system.ExportTemplate {
|
||||
out := &system.ExportTemplate{ID: value.ID, DBName: value.DBName, Name: value.Name, TableName: value.TableName, TemplateID: value.TemplateID, TemplateInfo: value.TemplateInfo, SQL: value.SQL, ImportSQL: value.ImportSQL, Limit: value.Limit, Order: value.Order}
|
||||
for _, item := range value.Conditions {
|
||||
out.Conditions = append(out.Conditions, biz.ExportCondition{ID: item.ID, CreatedAt: item.CreatedAt, UpdatedAt: item.UpdatedAt, TemplateID: item.TemplateID, From: item.From, Column: item.Column, Operator: item.Operator})
|
||||
out.Conditions = append(out.Conditions, system.ExportCondition{ID: item.ID, CreatedAt: item.CreatedAt, UpdatedAt: item.UpdatedAt, TemplateID: item.TemplateID, From: item.From, Column: item.Column, Operator: item.Operator})
|
||||
}
|
||||
for _, item := range value.Joins {
|
||||
out.Joins = append(out.Joins, biz.ExportJoin{ID: item.ID, CreatedAt: item.CreatedAt, UpdatedAt: item.UpdatedAt, TemplateID: item.TemplateID, Join: item.Join, Table: item.Table, On: item.On})
|
||||
out.Joins = append(out.Joins, system.ExportJoin{ID: item.ID, CreatedAt: item.CreatedAt, UpdatedAt: item.UpdatedAt, TemplateID: item.TemplateID, Join: item.Join, Table: item.Table, On: item.On})
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -84,9 +84,9 @@ func (s *ExportService) UpdateRequest(ctx context.Context, req *dto.ExportTempla
|
||||
return s.Update(ctx, exportTemplateDomain(req))
|
||||
}
|
||||
func (s *ExportService) TemplatesFilter(ctx context.Context, page, size int, name, tableName, templateID string, start, end *time.Time) ([]*dto.ExportTemplateResponse, int64, error) {
|
||||
return s.Templates(ctx, page, size, &biz.ExportTemplate{Name: name, TableName: tableName, TemplateID: templateID, StartCreatedAt: start, EndCreatedAt: end})
|
||||
return s.Templates(ctx, page, size, &system.ExportTemplate{Name: name, TableName: tableName, TemplateID: templateID, StartCreatedAt: start, EndCreatedAt: end})
|
||||
}
|
||||
func exportDTO(v *biz.ExportTemplate) *dto.ExportTemplateResponse {
|
||||
func exportDTO(v *system.ExportTemplate) *dto.ExportTemplateResponse {
|
||||
var conditions []dto.ExportConditionResponse
|
||||
if v.Conditions != nil {
|
||||
conditions = make([]dto.ExportConditionResponse, 0, len(v.Conditions))
|
||||
@@ -103,10 +103,10 @@ func exportDTO(v *biz.ExportTemplate) *dto.ExportTemplateResponse {
|
||||
}
|
||||
return &dto.ExportTemplateResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, DBName: v.DBName, Name: v.Name, TableName: v.TableName, TemplateID: v.TemplateID, TemplateInfo: v.TemplateInfo, SQL: v.SQL, ImportSQL: v.ImportSQL, Limit: v.Limit, Order: v.Order, Conditions: conditions, Joins: joins}
|
||||
}
|
||||
func (s *ExportService) Create(ctx context.Context, v *biz.ExportTemplate) error {
|
||||
func (s *ExportService) Create(ctx context.Context, v *system.ExportTemplate) error {
|
||||
return s.uc.CreateExportTemplate(ctx, v)
|
||||
}
|
||||
func (s *ExportService) Update(ctx context.Context, v *biz.ExportTemplate) error {
|
||||
func (s *ExportService) Update(ctx context.Context, v *system.ExportTemplate) error {
|
||||
return s.uc.UpdateExportTemplate(ctx, v)
|
||||
}
|
||||
func (s *ExportService) Delete(ctx context.Context, ids []uint) error {
|
||||
@@ -119,7 +119,7 @@ func (s *ExportService) Template(ctx context.Context, id uint, tid string) (*dto
|
||||
}
|
||||
return exportDTO(v), nil
|
||||
}
|
||||
func (s *ExportService) Templates(ctx context.Context, page, size int, q *biz.ExportTemplate) ([]*dto.ExportTemplateResponse, int64, error) {
|
||||
func (s *ExportService) Templates(ctx context.Context, page, size int, q *system.ExportTemplate) ([]*dto.ExportTemplateResponse, int64, error) {
|
||||
items, total, err := s.uc.ListExportTemplates(ctx, page, size, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
|
||||
Reference in New Issue
Block a user