refactor
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
aovantsev
2025-10-10 19:56:06 +03:00
parent f081c9d947
commit 73ed514a34
30 changed files with 1728 additions and 1020 deletions

View File

@@ -0,0 +1,60 @@
package entities
import "time"
// Counter represents a counter entity
type Counter struct {
ID int `json:"id" db:"id"`
UserID int `json:"user_id" db:"user_id"`
Name string `json:"name" db:"name"`
Description string `json:"description" db:"description"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}
// CounterEntry represents a single increment/decrement entry
type CounterEntry struct {
ID int `json:"id" db:"id"`
CounterID int `json:"counter_id" db:"counter_id"`
Value int `json:"value" db:"value"` // +1 for increment, -1 for decrement
Date time.Time `json:"date" db:"date"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
}
// CounterWithStats represents a counter with aggregated statistics
type CounterWithStats struct {
Counter
TotalValue int `json:"total_value"`
TodayValue int `json:"today_value"`
WeekValue int `json:"week_value"`
MonthValue int `json:"month_value"`
EntryCount int `json:"entry_count"`
}
// DailyStat represents daily statistics for a counter
type DailyStat struct {
Date time.Time `json:"date"`
Total int `json:"total"`
}
// Validate validates counter data
func (c *Counter) Validate() error {
if c.Name == "" {
return ErrInvalidCounterName
}
if c.UserID <= 0 {
return ErrInvalidUserID
}
return nil
}
// Validate validates counter entry data
func (ce *CounterEntry) Validate() error {
if ce.CounterID <= 0 {
return ErrInvalidCounterID
}
if ce.Value == 0 {
return ErrInvalidEntryValue
}
return nil
}