backend/pkg/member/domain/entity/account_uid_table.go

57 lines
1.3 KiB
Go
Raw Normal View History

2025-10-01 16:30:27 +00:00
package entity
import (
"errors"
"time"
"backend/pkg/member/domain/member"
2025-10-01 16:30:27 +00:00
"go.mongodb.org/mongo-driver/v2/bson"
)
type AccountUID struct {
ID bson.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
LoginID string `bson:"login_id"`
UID string `bson:"uid"`
2025-10-01 16:30:27 +00:00
Type member.AccountType `bson:"type"`
UpdateAt *int64 `bson:"update_at,omitempty" json:"update_at,omitempty"`
CreateAt *int64 `bson:"create_at,omitempty" json:"create_at,omitempty"`
2025-10-01 16:30:27 +00:00
}
func (a *AccountUID) CollectionName() string {
return "account_uid_binding"
}
// Validate validates the AccountUID entity
func (a *AccountUID) Validate() error {
if a.LoginID == "" {
return errors.New("login_id is required")
}
if a.UID == "" {
return errors.New("uid is required")
}
if !a.Type.IsValid() {
return errors.New("invalid account type")
}
return nil
}
// SetTimestamps sets the create and update timestamps
func (a *AccountUID) SetTimestamps() {
now := time.Now().UTC().UnixNano()
if a.CreateAt == nil {
a.CreateAt = &now
}
a.UpdateAt = &now
}
// IsNew returns true if this is a new binding (no ID set)
func (a *AccountUID) IsNew() bool {
return a.ID.IsZero()
}
// GetIDString returns the ID as a hex string
func (a *AccountUID) GetIDString() string {
return a.ID.Hex()
}