|
@ -33,6 +33,7 @@ type User struct { |
|
|
LastUpdated time.Time |
|
|
LastUpdated time.Time |
|
|
db *database.Db |
|
|
db *database.Db |
|
|
Resources Resources |
|
|
Resources Resources |
|
|
|
|
|
Planets []bson.ObjectId |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NewUser(db *database.Db, name, password, email string) (*User, error) { |
|
|
func NewUser(db *database.Db, name, password, email string) (*User, error) { |
|
@ -64,17 +65,16 @@ func UserDbToUser(db *database.Db, u UserDb) *User { |
|
|
LastUpdated: u.LastUpdated, |
|
|
LastUpdated: u.LastUpdated, |
|
|
db: db, |
|
|
db: db, |
|
|
Resources: u.Resources, |
|
|
Resources: u.Resources, |
|
|
|
|
|
Planets: u.Planets, |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (u *User) StoreInDb() error { |
|
|
func (u *User) StoreInDb() error { |
|
|
userDb := UserDb{ |
|
|
|
|
|
Id: u.Id, |
|
|
|
|
|
Name: u.Name, |
|
|
|
|
|
LastUpdated: time.Now(), |
|
|
|
|
|
Resources: u.Resources, |
|
|
|
|
|
} |
|
|
|
|
|
err := u.db.Users.Update(bson.M{"_id": u.Id}, userDb) |
|
|
|
|
|
|
|
|
err := u.db.Users.Update(bson.M{"_id": u.Id}, bson.M{"$set": bson.M{ |
|
|
|
|
|
"lastupdated": time.Now(), |
|
|
|
|
|
"resources": u.Resources, |
|
|
|
|
|
"planets": u.Planets, |
|
|
|
|
|
}}) |
|
|
return err |
|
|
return err |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|