26 lines
1.1 KiB
Go
26 lines
1.1 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/prabhupadasays/spsays-bff/internal/model"
|
|
)
|
|
|
|
// ListShortURLs pages the shortened-URL table for the admin panel.
|
|
func (s *AdminService) ListShortURLs(ctx context.Context, q string, limit, offset int) ([]model.AdminShortURL, int, error) {
|
|
return s.repo.ListShortURLs(ctx, q, limit, offset)
|
|
}
|
|
|
|
// ShortURLStats computes the today / this-week / this-month / all-time short-URL
|
|
// summary (and an optional custom range). The fixed windows are UTC-calendar
|
|
// based: today from 00:00 UTC, week from Monday 00:00 UTC, month from the 1st.
|
|
func (s *AdminService) ShortURLStats(ctx context.Context, from, to *time.Time) (*model.ShortURLStats, error) {
|
|
now := time.Now().UTC()
|
|
todayStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC)
|
|
// Monday as the first day of the week (Weekday: Sun=0 … Sat=6).
|
|
weekStart := todayStart.AddDate(0, 0, -((int(now.Weekday()) + 6) % 7))
|
|
monthStart := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.UTC)
|
|
return s.repo.ShortURLStats(ctx, todayStart, weekStart, monthStart, from, to)
|
|
}
|