1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

Heartbeat Insertions.

Restructuring.
This commit is contained in:
Ferdinand Mütsch
2019-05-06 00:40:41 +02:00
parent 6e7f47dc79
commit 9df289b7ed
8 changed files with 110 additions and 22 deletions

34
services/user.go Normal file
View File

@ -0,0 +1,34 @@
package services
import (
"database/sql"
"fmt"
"github.com/n1try/wakapi/models"
)
const TableUser = "user"
type UserService struct {
Db *sql.DB
}
func (srv *UserService) GetUserById(userId string) (models.User, error) {
q := fmt.Sprintf("SELECT user_id, api_key FROM %+s WHERE user_id = ?;", TableUser)
u := models.User{}
err := srv.Db.QueryRow(q, userId).Scan(&u.UserId, &u.ApiKey)
if err != nil {
return u, err
}
return u, nil
}
func (srv *UserService) GetUserByKey(key string) (models.User, error) {
q := fmt.Sprintf("SELECT user_id, api_key FROM %+s WHERE api_key = ?;", TableUser)
var u models.User
err := srv.Db.QueryRow(q, key).Scan(&u.UserId, &u.ApiKey)
if err != nil {
return u, err
}
return u, nil
}