RestApiv2/internal/bd/userrepo.go

38 lines
1.0 KiB
Go

package bd
import (
"context"
"fmt"
"git.ukamnya.ru/stulyaganov/RestApi/internal/bd/model"
)
type Userrepo struct {
db Bd
}
func (u *Userrepo) Create(user *model.User) (*model.User, error) {
err := u.db.db.QueryRow(context.Background(),
"INSERT INTO users (id, login, email, password, avatar_url, token, permisionlvl) VALUES($1, $2, $3, $4, $5, $6, $7) RETURNING id, permisionlvl", user.Id, user.Login, user.Email, user.Password, user.Avatar_Url, user.Token, user.PermisionLVL).
Scan(&user.Id, &user.PermisionLVL)
if err != nil {
return nil, err
}
return user, nil
}
func (u *Userrepo) FindById(id string) (*model.User, error) {
var user model.User
query := fmt.Sprintf("SELECT * FROM users WHERE Id = %s;", id)
err := u.db.db.QueryRow(context.Background(), query).
Scan(user.Id, user.Login, user.Email, user.Password, user.Avatar_Url, user.Token, user.PermisionLVL)
if err != nil {
return nil, err
}
return &user, nil
}
func (u *Userrepo) FindByAll() (*model.User, error) {
return nil, nil
}