74 lines
2.8 KiB
Go
74 lines
2.8 KiB
Go
package system
|
|
|
|
import (
|
|
"context"
|
|
"kra/internal/biz/system"
|
|
"time"
|
|
|
|
"kra/internal/service/dto"
|
|
)
|
|
|
|
func errorDTO(v *system.ErrorRecord) *dto.ErrorRecordResponse {
|
|
return &dto.ErrorRecordResponse{ID: v.ID, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, DeletedAt: nil, Form: v.Form, Info: v.Info, Level: v.Level, RequestID: v.RequestID, TraceID: v.TraceID, Solution: v.Solution, Status: v.Status}
|
|
}
|
|
func (s *AuditRecorder) CreateError(ctx context.Context, v *system.ErrorRecord) error {
|
|
return s.uc.CreateError(ctx, v)
|
|
}
|
|
func recordedErrorDomain(value *dto.ErrorRecordRequest) *system.ErrorRecord {
|
|
form, info := value.Form, value.Info
|
|
result := &system.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) *system.ErrorRecord {
|
|
return &system.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 (s *AuditRecorder) CreateErrorRequest(ctx context.Context, req *dto.ErrorRecordRequest) error {
|
|
return s.CreateError(ctx, recordedErrorDomain(req))
|
|
}
|
|
func (s *AuditRecorder) CreateErrorMutationRequest(ctx context.Context, req *dto.ErrorRecordMutationRequest) error {
|
|
value := mutatedErrorDomain(req)
|
|
value.ID = 0
|
|
return s.CreateError(ctx, value)
|
|
}
|
|
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) {
|
|
query := &system.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 *system.ErrorRecord) error {
|
|
return s.uc.UpdateError(ctx, v)
|
|
}
|
|
func (s *AuditService) DeleteErrors(ctx context.Context, ids []uint) error {
|
|
return s.uc.DeleteErrors(ctx, ids)
|
|
}
|
|
func (s *AuditService) Error(ctx context.Context, id uint) (*dto.ErrorRecordResponse, error) {
|
|
v, err := s.uc.FindError(ctx, id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return errorDTO(v), nil
|
|
}
|
|
func (s *AuditService) Errors(ctx context.Context, page, size int, q *system.ErrorRecord) ([]*dto.ErrorRecordResponse, int64, error) {
|
|
items, total, err := s.uc.ListErrors(ctx, page, size, q)
|
|
if err != nil {
|
|
return nil, 0, err
|
|
}
|
|
out := make([]*dto.ErrorRecordResponse, 0, len(items))
|
|
for _, v := range items {
|
|
out = append(out, errorDTO(v))
|
|
}
|
|
return out, total, nil
|
|
}
|