优化结构
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
"kra/app/system/internal/biz"
|
||||
"kra/app/system/internal/dto"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
@@ -67,7 +66,7 @@ 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 {
|
||||
func exportTemplateDomain(value *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}
|
||||
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})
|
||||
@@ -77,31 +76,31 @@ func exportTemplateDomain(value *dto.ExportTemplateRequest) *biz.ExportTemplate
|
||||
}
|
||||
return out
|
||||
}
|
||||
func (s *ExportService) CreateRequest(ctx context.Context, req *dto.ExportTemplateRequest) error {
|
||||
func (s *ExportService) CreateRequest(ctx context.Context, req *ExportTemplateRequest) error {
|
||||
return s.Create(ctx, exportTemplateDomain(req))
|
||||
}
|
||||
func (s *ExportService) UpdateRequest(ctx context.Context, req *dto.ExportTemplateRequest) error {
|
||||
func (s *ExportService) UpdateRequest(ctx context.Context, req *ExportTemplateRequest) error {
|
||||
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) {
|
||||
func (s *ExportService) TemplatesFilter(ctx context.Context, page, size int, name, tableName, templateID string, start, end *time.Time) ([]*ExportTemplateResponse, int64, error) {
|
||||
return s.Templates(ctx, page, size, &biz.ExportTemplate{Name: name, TableName: tableName, TemplateID: templateID, StartCreatedAt: start, EndCreatedAt: end})
|
||||
}
|
||||
func exportDTO(v *biz.ExportTemplate) *dto.ExportTemplateResponse {
|
||||
var conditions []dto.ExportConditionResponse
|
||||
func exportDTO(v *biz.ExportTemplate) *ExportTemplateResponse {
|
||||
var conditions []ExportConditionResponse
|
||||
if v.Conditions != nil {
|
||||
conditions = make([]dto.ExportConditionResponse, 0, len(v.Conditions))
|
||||
conditions = make([]ExportConditionResponse, 0, len(v.Conditions))
|
||||
for _, x := range v.Conditions {
|
||||
conditions = append(conditions, dto.ExportConditionResponse{ID: x.ID, CreatedAt: x.CreatedAt, UpdatedAt: x.UpdatedAt, TemplateID: x.TemplateID, From: x.From, Column: x.Column, Operator: x.Operator})
|
||||
conditions = append(conditions, ExportConditionResponse{ID: x.ID, CreatedAt: x.CreatedAt, UpdatedAt: x.UpdatedAt, TemplateID: x.TemplateID, From: x.From, Column: x.Column, Operator: x.Operator})
|
||||
}
|
||||
}
|
||||
var joins []dto.ExportJoinResponse
|
||||
var joins []ExportJoinResponse
|
||||
if v.Joins != nil {
|
||||
joins = make([]dto.ExportJoinResponse, 0, len(v.Joins))
|
||||
joins = make([]ExportJoinResponse, 0, len(v.Joins))
|
||||
for _, x := range v.Joins {
|
||||
joins = append(joins, dto.ExportJoinResponse{ID: x.ID, CreatedAt: x.CreatedAt, UpdatedAt: x.UpdatedAt, TemplateID: x.TemplateID, Join: x.Join, Table: x.Table, On: x.On})
|
||||
joins = append(joins, ExportJoinResponse{ID: x.ID, CreatedAt: x.CreatedAt, UpdatedAt: x.UpdatedAt, TemplateID: x.TemplateID, Join: x.Join, Table: x.Table, On: x.On})
|
||||
}
|
||||
}
|
||||
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}
|
||||
return &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 {
|
||||
return s.uc.CreateExportTemplate(ctx, v)
|
||||
@@ -112,19 +111,19 @@ func (s *ExportService) Update(ctx context.Context, v *biz.ExportTemplate) error
|
||||
func (s *ExportService) Delete(ctx context.Context, ids []uint) error {
|
||||
return s.uc.DeleteExportTemplates(ctx, ids)
|
||||
}
|
||||
func (s *ExportService) Template(ctx context.Context, id uint, tid string) (*dto.ExportTemplateResponse, error) {
|
||||
func (s *ExportService) Template(ctx context.Context, id uint, tid string) (*ExportTemplateResponse, error) {
|
||||
v, err := s.uc.FindExportTemplate(ctx, id, tid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
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 *biz.ExportTemplate) ([]*ExportTemplateResponse, int64, error) {
|
||||
items, total, err := s.uc.ListExportTemplates(ctx, page, size, q)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*dto.ExportTemplateResponse, 0, len(items))
|
||||
out := make([]*ExportTemplateResponse, 0, len(items))
|
||||
for _, v := range items {
|
||||
out = append(out, exportDTO(v))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user