package model import ( "electricity_bill_calc/types" "time" "github.com/shopspring/decimal" ) const ( USER_TYPE_ENT int16 = iota USER_TYPE_SUP USER_TYPE_OPS ) type ManagementAccountCreationForm struct { Id *string `json:"id"` Username string `json:"username"` Name string `json:"name"` Contact *string `json:"contact"` Phone *string `json:"phone"` Type int16 `json:"type"` Enabled bool `json:"enabled"` Expires types.Date `json:"expires"` } func (m ManagementAccountCreationForm) IntoUser() *User { return &User{ Id: *m.Id, Username: m.Username, Password: "", ResetNeeded: false, UserType: m.Type, Enabled: m.Enabled, CreatedAt: nil, } } func (m ManagementAccountCreationForm) IntoUserDetail() *UserDetail { return &UserDetail{ Id: *m.Id, Name: &m.Name, Abbr: nil, Region: nil, Address: nil, Contact: m.Contact, Phone: m.Phone, UnitServiceFee: decimal.Zero, ServiceExpiration: m.Expires, CreatedAt: time.Now(), CreatedBy: nil, LastModifiedAt: time.Now(), LastModifiedBy: nil, DeletedAt: nil, DeletedBy: nil, } } type UserModificationForm struct { Name string `json:"name"` Region *string `json:"region"` Address *string `json:"address"` Contact *string `json:"contact"` Phone *string `json:"phone"` UnitServiceFee *decimal.Decimal `json:"unitServiceFee"` } type User struct { Id string `json:"id"` Username string `json:"username"` Password string `json:"password"` ResetNeeded bool `json:"resetNeeded"` UserType int16 `db:"type"` Enabled bool `json:"enabled"` CreatedAt *time.Time `json:"createdAt"` } type UserDetail struct { Id string `json:"id"` Name *string `json:"name"` Abbr *string `json:"abbr"` Region *string `json:"region"` Address *string `json:"address"` Contact *string `json:"contact"` Phone *string `json:"phone"` UnitServiceFee decimal.Decimal `db:"unit_service_fee" json:"unitServiceFee"` ServiceExpiration types.Date `json:"serviceExpiration"` CreatedAt time.Time `json:"createdAt"` CreatedBy *string `json:"createdBy"` LastModifiedAt time.Time `json:"lastModifiedAt"` LastModifiedBy *string `json:"lastModifiedBy"` DeletedAt *time.Time `json:"deletedAt"` DeletedBy *string `json:"deletedBy"` } type UserWithDetail struct { Id string `json:"id"` Username string `json:"username"` ResetNeeded bool `json:"resetNeeded"` UserType int16 `db:"type" json:"type"` Enabled bool `json:"enabled"` Name *string `json:"name"` Abbr *string `json:"abbr"` Region *string `json:"region"` Address *string `json:"address"` Contact *string `json:"contact"` Phone *string `json:"phone"` UnitServiceFee decimal.Decimal `db:"unit_service_fee" json:"unitServiceFee"` ServiceExpiration types.Date `json:"serviceExpiration"` CreatedAt time.Time `json:"createdAt"` CreatedBy *string `json:"createdBy"` LastModifiedAt time.Time `json:"lastModifiedAt"` LastModifiedBy *string `json:"lastModifiedBy"` }