2019-05-06 01:40:41 +03:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
2019-05-11 18:49:56 +03:00
|
|
|
"github.com/jinzhu/gorm"
|
2019-05-06 01:40:41 +03:00
|
|
|
"github.com/n1try/wakapi/models"
|
|
|
|
)
|
|
|
|
|
|
|
|
const TableUser = "user"
|
|
|
|
|
|
|
|
type UserService struct {
|
2019-05-11 18:49:56 +03:00
|
|
|
Db *gorm.DB
|
2019-05-06 01:40:41 +03:00
|
|
|
}
|
|
|
|
|
2019-05-11 18:49:56 +03:00
|
|
|
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 {
|
2019-05-06 01:40:41 +03:00
|
|
|
return u, err
|
|
|
|
}
|
|
|
|
return u, nil
|
|
|
|
}
|
|
|
|
|
2019-05-11 18:49:56 +03:00
|
|
|
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 {
|
2019-05-06 01:40:41 +03:00
|
|
|
return u, err
|
|
|
|
}
|
|
|
|
return u, nil
|
|
|
|
}
|