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 {
|
2023-11-01 22:40:50 -04:00
|
|
|
*CommonFields `bson:"obj_info"`
|
2023-11-16 20:45:48 -05:00
|
|
|
Id primitive.ObjectID `bson:"_id"`
|
2023-11-01 22:40:50 -04:00
|
|
|
Email string `bson:"email,omitempty"`
|
|
|
|
PassowrdHash string `bson:"password_hash,omitempty"`
|
2023-10-28 14:42:29 -04:00
|
|
|
}
|
|
|
|
|
2023-11-01 22:40:50 -04:00
|
|
|
func (user *User) MongoId() primitive.ObjectID {
|
2023-10-28 14:42:29 -04:00
|
|
|
|
2023-11-03 01:01:33 -04:00
|
|
|
if user.Id.IsZero() {
|
2023-10-28 14:42:29 -04:00
|
|
|
now := time.Now()
|
2023-11-03 01:01:33 -04:00
|
|
|
|
|
|
|
user.Id = primitive.NewObjectIDFromTimestamp(now)
|
2023-10-28 14:42:29 -04:00
|
|
|
}
|
|
|
|
|
2023-11-03 01:01:33 -04:00
|
|
|
return user.Id
|
2023-10-28 14:42:29 -04:00
|
|
|
}
|
|
|
|
|
2023-11-01 22:40:50 -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
|
|
|
}
|
2023-11-01 22:40:50 -04:00
|
|
|
user.UpdatedAt = now
|
2023-10-28 14:42:29 -04:00
|
|
|
}
|