Capstone/ui/db/models/user.go

38 lines
717 B
Go
Raw Normal View History

2023-10-28 14:42:29 -04:00
package models
import (
"time"
"go.mongodb.org/mongo-driver/bson/primitive"
)
const USER_TYPE string = "user"
type User struct {
*CommonFields `bson:"obj_info"`
Id primitive.ObjectID `bson:"_id"`
Email string `bson:"email,omitempty"`
PassowrdHash string `bson:"password_hash,omitempty"`
2023-10-28 14:42:29 -04:00
}
func (user *User) MongoId() primitive.ObjectID {
2023-10-28 14:42:29 -04:00
if user.Id.IsZero() {
2023-10-28 14:42:29 -04:00
now := time.Now()
user.Id = primitive.NewObjectIDFromTimestamp(now)
2023-10-28 14:42:29 -04:00
}
return user.Id
2023-10-28 14:42:29 -04:00
}
func (user *User) UpdateObjectInfo() {
now := time.Now()
if user.CommonFields == nil {
user.CommonFields = new(CommonFields)
user.EntityType = USER_TYPE
user.CreatedAt = now
2023-10-28 14:42:29 -04:00
}
user.UpdatedAt = now
2023-10-28 14:42:29 -04:00
}