kra-oa/internal/service/audit_log_file.go

44 lines
1.5 KiB
Go

package service
import (
"context"
"kra/internal/biz"
)
type LogViewerService struct{ uc *biz.LogViewerUsecase }
func NewLogViewerService(uc *biz.LogViewerUsecase) *LogViewerService {
return &LogViewerService{uc: uc}
}
func (s *LogViewerService) LogDates(ctx context.Context, month string) (map[string]any, error) {
items, err := s.uc.LogDates(ctx, month)
if err != nil {
return nil, err
}
out := make([]map[string]any, 0, len(items))
for _, v := range items {
out = append(out, map[string]any{"date": v.Date, "fileCount": v.FileCount})
}
return map[string]any{"month": month, "dates": out}, nil
}
func (s *LogViewerService) LogFiles(ctx context.Context, date string) (map[string]any, error) {
items, err := s.uc.LogFiles(ctx, date)
if err != nil {
return nil, err
}
out := make([]map[string]any, 0, len(items))
for _, v := range items {
out = append(out, map[string]any{"path": v.Path, "name": v.Name, "size": v.Size, "modifiedAt": v.ModifiedAt})
}
return map[string]any{"date": date, "files": out}, nil
}
func (s *LogViewerService) LogContent(ctx context.Context, date, path string, cursor *int64) (map[string]any, error) {
v, err := s.uc.LogContent(ctx, date, path, cursor)
if err != nil {
return nil, err
}
return map[string]any{"date": v.Date, "path": v.Path, "content": v.Content, "lineCount": v.LineCount, "nextCursor": v.NextCursor, "hasMore": v.HasMore, "limitedByBytes": v.LimitedByBytes, "size": v.Size, "modifiedAt": v.ModifiedAt}, nil
}