statping/database/user.go

33 lines
744 B
Go
Raw Normal View History

2020-02-24 16:26:01 +00:00
package database
import "github.com/hunterlong/statping/types"
type UserObj struct {
*types.User
2020-02-25 07:41:28 +00:00
o *Object
2020-02-24 16:26:01 +00:00
}
2020-02-25 07:41:28 +00:00
func User(id int64) (*UserObj, error) {
var user types.User
query := database.Users().Where("id = ?", id)
finder := query.First(&user)
return &UserObj{User: &user, o: wrapObject(id, &user, query)}, finder.Error()
2020-02-24 16:26:01 +00:00
}
2020-02-25 07:41:28 +00:00
func UserByUsername(username string) (*UserObj, error) {
2020-02-24 16:26:01 +00:00
var user types.User
2020-02-25 07:41:28 +00:00
query := database.Users().Where("username = ?", username)
finder := query.First(&user)
return &UserObj{User: &user, o: wrapObject(user.Id, &user, query)}, finder.Error()
}
2020-02-25 17:39:38 +00:00
func AllUsers() []*types.User {
var users []*types.User
database.Users().Find(&users)
return users
2020-02-25 07:41:28 +00:00
}
func (u *UserObj) object() *Object {
return u.o
2020-02-24 16:26:01 +00:00
}