Skip to content

Commit

Permalink
Fix typo in TotalUploaded field name in UploadStats struct
Browse files Browse the repository at this point in the history
  • Loading branch information
divyam234 committed Apr 18, 2024
1 parent 34a5382 commit 7cd8aac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pkg/schemas/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ type UploadPart struct {

type UploadStats struct {
UploadDate string `json:"uploadDate"`
TotalUploaded int64 `json:"totalUpladed"`
TotalUploaded int64 `json:"totalUploaded"`
}
15 changes: 4 additions & 11 deletions pkg/services/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit 7cd8aac

Please sign in to comment.