mirror of
https://github.com/acaloiaro/newsbox
synced 2026-07-21 10:12:26 +00:00
58 lines
2.3 KiB
Go
58 lines
2.3 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
|
|
"github.com/gobuffalo/pop/v6"
|
|
"github.com/gobuffalo/validate/v3"
|
|
"github.com/gobuffalo/validate/v3/validators"
|
|
"github.com/gofrs/uuid"
|
|
)
|
|
|
|
// UserPreference is used by pop to map your user_preferences database table to your go code.
|
|
type UserPreference struct {
|
|
ID uuid.UUID `json:"id" db:"id"`
|
|
OwnerID uuid.UUID `json:"owner_id" db:"owner_id"`
|
|
Owner *User `json:"owner" belongs_to:"user"`
|
|
EmailHourOfDay int `json:"email_hour_of_day" db:"email_hour_of_day" form:"email_hour_of_day"` // The hour of the day that the user prefers to receive emails
|
|
TimeZoneUtcOffset int `json:"time_zone_utc_offset" db:"time_zone_utc_offset" form:"time_zone_utc_offset"` // The user's time zone, represented as a nubmer of hours (negativ or positive) relative to UTC
|
|
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
|
|
}
|
|
|
|
// String is not required by pop and may be deleted
|
|
func (u UserPreference) String() string {
|
|
ju, _ := json.Marshal(u)
|
|
return string(ju)
|
|
}
|
|
|
|
// UserPreferences is not required by pop and may be deleted
|
|
type UserPreferences []UserPreference
|
|
|
|
// String is not required by pop and may be deleted
|
|
func (u UserPreferences) String() string {
|
|
ju, _ := json.Marshal(u)
|
|
return string(ju)
|
|
}
|
|
|
|
// Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method.
|
|
// This method is not required and may be deleted.
|
|
func (u *UserPreference) Validate(tx *pop.Connection) (*validate.Errors, error) {
|
|
return validate.Validate(
|
|
&validators.IntIsPresent{Field: u.EmailHourOfDay, Name: "EmailHourOfDay"},
|
|
&validators.IntIsPresent{Field: u.TimeZoneUtcOffset, Name: "TimeZoneUtcOffset"},
|
|
), nil
|
|
}
|
|
|
|
// ValidateCreate gets run every time you call "pop.ValidateAndCreate" method.
|
|
// This method is not required and may be deleted.
|
|
func (u *UserPreference) ValidateCreate(tx *pop.Connection) (*validate.Errors, error) {
|
|
return validate.NewErrors(), nil
|
|
}
|
|
|
|
// ValidateUpdate gets run every time you call "pop.ValidateAndUpdate" method.
|
|
// This method is not required and may be deleted.
|
|
func (u *UserPreference) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error) {
|
|
return validate.NewErrors(), nil
|
|
}
|