1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00
wakapi/services/user.go
2019-05-16 22:53:03 +02:00

30 lines
607 B
Go

package services
import (
"github.com/jinzhu/gorm"
"github.com/n1try/wakapi/models"
)
const TableUser = "user"
type UserService struct {
Config *models.Config
Db *gorm.DB
}
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
}