From 7cd8aacf96987892605fe6cc1469619a7d42b4e2 Mon Sep 17 00:00:00 2001 From: divyam234 <47589864+divyam234@users.noreply.github.com> Date: Fri, 19 Apr 2024 04:28:33 +0530 Subject: [PATCH] Fix typo in TotalUploaded field name in UploadStats struct --- pkg/schemas/upload.go | 2 +- pkg/services/upload.go | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/pkg/schemas/upload.go b/pkg/schemas/upload.go index e088c00f..41738631 100644 --- a/pkg/schemas/upload.go +++ b/pkg/schemas/upload.go @@ -34,5 +34,5 @@ type UploadPart struct { type UploadStats struct { UploadDate string `json:"uploadDate"` - TotalUploaded int64 `json:"totalUpladed"` + TotalUploaded int64 `json:"totalUploaded"` } diff --git a/pkg/services/upload.go b/pkg/services/upload.go index 8f7c89b4..d707d501 100644 --- a/pkg/services/upload.go +++ b/pkg/services/upload.go @@ -66,7 +66,7 @@ func (us *UploadService) DeleteUploadFile(c *gin.Context) (*schemas.Message, *ty func (us *UploadService) GetUploadStats(userId int64, days int) ([]schemas.UploadStats, *types.AppError) { var stats []schemas.UploadStats - rows, err := us.db.Raw(` + err := us.db.Raw(` SELECT dates.upload_date::date AS upload_date, COALESCE(SUM(files.size), 0)::bigint AS total_uploaded @@ -77,25 +77,18 @@ func (us *UploadService) GetUploadStats(userId int64, days int) ([]schemas.Uploa ON dates.upload_date = DATE_TRUNC('day', files.created_at) WHERE - dates.upload_date >= CURRENT_DATE - INTERVAL '1 day' * @days and files.user_id = @userId + dates.upload_date >= CURRENT_DATE - INTERVAL '1 day' * @days and (files.type='file' or files.type is null) and (files.user_id=@userId or files.user_id is null) GROUP BY dates.upload_date ORDER BY - dates.upload_date desc - `, sql.Named("days", days-1), sql.Named("userId", userId)).Rows() + dates.upload_date + `, sql.Named("days", days-1), sql.Named("userId", userId)).Scan(&stats).Error if err != nil { return nil, &types.AppError{Error: err} } - defer rows.Close() - for rows.Next() { - var uploadDate string - var totalUploaded int64 - rows.Scan(&uploadDate, &totalUploaded) - stats = append(stats, schemas.UploadStats{UploadDate: uploadDate, TotalUploaded: totalUploaded}) - } return stats, nil }