diff --git a/config/config.yaml b/config/config.yaml index bd76c32..11ba045 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -1,17 +1,12 @@ # Database configuration database: # Database driver: "sqlite" or "postgres" - driver: sqlite - - # SQLite configuration - name: paste69.db # Database file path for SQLite - - # # PostgreSQL configuration (ignored for SQLite) - # host: localhost - # port: 5432 - # user: paste69 - # password: paste69 - # sslmode: disable # Options: disable, require, verify-ca, verify-full + driver: postgres + host: localhost + port: 5432 + user: postgres + name: paste69 + sslmode: disable # Options: disable, require, verify-ca, verify-full # Storage configuration storage: diff --git a/internal/database/database.go b/internal/database/database.go index 1aac5f4..c7ece16 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -19,11 +19,11 @@ func New(config *config.Config, gormConfig *gorm.Config) (*Database, error) { switch config.Database.Driver { case "postgres": dsn := fmt.Sprintf( - "host=%s port=%d user=%s password=%s dbname=%s sslmode=%s", + "host=%s user=%s password=%s port=%d dbname=%s sslmode=%s", config.Database.Host, - config.Database.Port, config.Database.User, config.Database.Password, + config.Database.Port, config.Database.Name, config.Database.SSLMode, ) diff --git a/internal/server/services/analytics.go b/internal/server/services/analytics.go index 1702401..01bcecd 100644 --- a/internal/server/services/analytics.go +++ b/internal/server/services/analytics.go @@ -167,7 +167,7 @@ func (s *AnalyticsService) GetStatsHistory(days int) (*StatsHistory, error) { } // Calculate date range - endDate := time.Now() + endDate := time.Now().AddDate(0, 0, 1) startDate := endDate.AddDate(0, 0, -days) // Get paste counts by day @@ -232,21 +232,24 @@ func (s *AnalyticsService) GetStatsHistory(days int) (*StatsHistory, error) { // Update with actual values if available for _, pc := range pasteCounts { - if pc.DateStr == dateStr { + pcTime, err := time.Parse(time.RFC3339, pc.DateStr) + if err == nil && pcTime.Format("2006-01-02") == dateStr { history.Pastes[i].Value = pc.Count break } } for _, uc := range urlCounts { - if uc.DateStr == dateStr { + ucTime, err := time.Parse(time.RFC3339, uc.DateStr) + if err == nil && ucTime.Format("2006-01-02") == dateStr { history.URLs[i].Value = uc.Count break } } for _, sc := range storageCounts { - if sc.DateStr == dateStr { + scTime, err := time.Parse(time.RFC3339, sc.DateStr) + if err == nil && scTime.Format("2006-01-02") == dateStr { history.Storage[i].Value = sc.Size if sc.Count > 0 { history.AvgSize[i].Value = float64(sc.Size) / float64(sc.Count) @@ -256,7 +259,8 @@ func (s *AnalyticsService) GetStatsHistory(days int) (*StatsHistory, error) { } for _, ac := range apiKeyCounts { - if ac.DateStr == dateStr { + acTime, err := time.Parse(time.RFC3339, ac.DateStr) + if err == nil && acTime.Format("2006-01-02") == dateStr { history.APIKeys[i].Value = ac.Count break }