mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
7d36c4e111
Add build script.
40 lines
816 B
Go
40 lines
816 B
Go
package services
|
|
|
|
import (
|
|
"github.com/jinzhu/gorm"
|
|
"github.com/muety/wakapi/models"
|
|
)
|
|
|
|
type UserService struct {
|
|
Config *models.Config
|
|
Db *gorm.DB
|
|
}
|
|
|
|
func (srv *UserService) Init() {}
|
|
|
|
func (srv *UserService) GetUserById(userId string) (*models.User, error) {
|
|
u := &models.User{}
|
|
if err := srv.Db.Where(&models.User{ID: userId}).First(u).Error; err != nil {
|
|
return u, err
|
|
}
|
|
return u, nil
|
|
}
|
|
|
|
func (srv *UserService) GetUserByKey(key string) (*models.User, error) {
|
|
u := &models.User{}
|
|
if err := srv.Db.Where(&models.User{ApiKey: key}).First(u).Error; err != nil {
|
|
return u, err
|
|
}
|
|
return u, nil
|
|
}
|
|
|
|
func (srv *UserService) GetAll() ([]*models.User, error) {
|
|
var users []*models.User
|
|
if err := srv.Db.
|
|
Table("users").
|
|
Find(&users).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return users, nil
|
|
}
|