This commit is contained in:
60
internal/domain/entities/counter.go
Normal file
60
internal/domain/entities/counter.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user