优化
This commit is contained in:
@@ -14,17 +14,36 @@ func errorDTO(v *biz.ErrorRecord) *dto.ErrorRecordResponse {
|
||||
func (s *AuditRecorder) CreateError(ctx context.Context, v *biz.ErrorRecord) error {
|
||||
return s.uc.CreateError(ctx, v)
|
||||
}
|
||||
func errorDomain(value *dto.ErrorRecordRequest) *biz.ErrorRecord {
|
||||
return &biz.ErrorRecord{ID: value.ID, Form: value.Form, Info: value.Info, Level: value.Level, RequestID: value.RequestID, TraceID: value.TraceID, Solution: value.Solution, Status: value.Status}
|
||||
func recordedErrorDomain(value *dto.ErrorRecordRequest) *biz.ErrorRecord {
|
||||
form, info := value.Form, value.Info
|
||||
result := &biz.ErrorRecord{Form: &form, Info: &info, Level: value.Level, RequestID: value.RequestID, TraceID: value.TraceID, Status: value.Status}
|
||||
if value.Solution != "" {
|
||||
solution := value.Solution
|
||||
result.Solution = &solution
|
||||
}
|
||||
return result
|
||||
}
|
||||
func mutatedErrorDomain(value *dto.ErrorRecordMutationRequest) *biz.ErrorRecord {
|
||||
return &biz.ErrorRecord{ID: value.ID, CreatedAt: value.CreatedAt, UpdatedAt: value.UpdatedAt, Form: value.Form, Info: value.Info, Level: value.Level, RequestID: value.RequestID, TraceID: value.TraceID, Solution: value.Solution, Status: value.Status}
|
||||
}
|
||||
func (s *AuditRecorder) CreateErrorRequest(ctx context.Context, req *dto.ErrorRecordRequest) error {
|
||||
return s.CreateError(ctx, errorDomain(req))
|
||||
return s.CreateError(ctx, recordedErrorDomain(req))
|
||||
}
|
||||
func (s *AuditService) UpdateErrorRequest(ctx context.Context, req *dto.ErrorRecordRequest) error {
|
||||
return s.UpdateError(ctx, errorDomain(req))
|
||||
func (s *AuditRecorder) CreateErrorMutationRequest(ctx context.Context, req *dto.ErrorRecordMutationRequest) error {
|
||||
return s.CreateError(ctx, mutatedErrorDomain(req))
|
||||
}
|
||||
func (s *AuditService) UpdateErrorRequest(ctx context.Context, req *dto.ErrorRecordMutationRequest) error {
|
||||
return s.UpdateError(ctx, mutatedErrorDomain(req))
|
||||
}
|
||||
func (s *AuditService) ErrorsFilter(ctx context.Context, page, size int, form, info string, createdAtRange []time.Time) ([]*dto.ErrorRecordResponse, int64, error) {
|
||||
return s.Errors(ctx, page, size, &biz.ErrorRecord{Form: form, Info: info, CreatedAtRange: createdAtRange})
|
||||
query := &biz.ErrorRecord{CreatedAtRange: createdAtRange}
|
||||
if form != "" {
|
||||
query.Form = &form
|
||||
}
|
||||
if info != "" {
|
||||
query.Info = &info
|
||||
}
|
||||
return s.Errors(ctx, page, size, query)
|
||||
}
|
||||
func (s *AuditService) UpdateError(ctx context.Context, v *biz.ErrorRecord) error {
|
||||
return s.uc.UpdateError(ctx, v)
|
||||
|
||||
@@ -56,8 +56,7 @@ type AuditIDQuery struct {
|
||||
}
|
||||
|
||||
type ErrorRecordRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
Form string `json:"form" binding:"required"`
|
||||
Form string `json:"form"`
|
||||
Info string `json:"info"`
|
||||
Level string `json:"level"`
|
||||
RequestID string `json:"request_id"`
|
||||
@@ -66,6 +65,22 @@ type ErrorRecordRequest struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// ErrorRecordMutationRequest mirrors the public error-record model. Pointer
|
||||
// fields preserve the distinction between an omitted value and an explicitly
|
||||
// supplied empty string, which is required by the update contract.
|
||||
type ErrorRecordMutationRequest struct {
|
||||
ID uint `json:"ID"`
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
Form *string `json:"form" binding:"required"`
|
||||
Info *string `json:"info"`
|
||||
Level string `json:"level"`
|
||||
RequestID string `json:"request_id"`
|
||||
TraceID string `json:"trace_id"`
|
||||
Solution *string `json:"solution"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type OperationRecordResponse struct {
|
||||
ID uint `json:"ID"`
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
@@ -123,12 +138,12 @@ type ErrorRecordResponse struct {
|
||||
CreatedAt time.Time `json:"CreatedAt"`
|
||||
UpdatedAt time.Time `json:"UpdatedAt"`
|
||||
DeletedAt any `json:"-"`
|
||||
Form string `json:"form"`
|
||||
Info string `json:"info"`
|
||||
Form *string `json:"form"`
|
||||
Info *string `json:"info"`
|
||||
Level string `json:"level"`
|
||||
RequestID string `json:"request_id"`
|
||||
TraceID string `json:"trace_id"`
|
||||
Solution string `json:"solution"`
|
||||
Solution *string `json:"solution"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user