package bd import ( "context" "fmt" "git.ukamnya.ru/stulyaganov/RestApiv2/internal/bd/model" ) type Userrepo struct { db Bd } func (u *Userrepo) Create(user *model.User) error { _, err := u.db.db.Exec(context.Background(), "INSERT INTO users (login, email, password, permisionlvl) VALUES($1, $2, $3, $4)", user.Login, user.Email, user.Password, user.PermisionLVL) if err != nil { return err } return 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.PermisionLVL) if err != nil { return nil, err } return &user, nil } func (u *Userrepo) FindByLogin(login string) (*model.User, error) { var user model.User rows, err := u.db.db.Query(context.Background(), "SELECT login FROM users WHERE login = $1", login) if err != nil { return nil, err } defer rows.Close() for rows.Next() { err = rows.Scan(&user.Login) } return &user, nil } func (u *Userrepo) FindByEmail(email string) (*model.User, error) { var user model.User rows, err := u.db.db.Query(context.Background(), "SELECT email FROM users WHERE email = $1", email) if err != nil { return nil, err } defer rows.Close() for rows.Next() { err = rows.Scan(&user.Email) } return &user, nil } func (u *Userrepo) FindByAll() (*model.User, error) { return nil, nil }