Add creat user in database
parent
25fcffc259
commit
88ae5fa188
|
@ -13,8 +13,8 @@ type Userrepo struct {
|
|||
|
||||
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, permissionLVL) VALUES($1, $2, $3, $4, $5, $6, $7)").
|
||||
Scan(user.Id, user.Login, user.Email, user.Password, user.Avatar_Url, user.Token, user.PermisionLVL)
|
||||
"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
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package restserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"git.ukamnya.ru/stulyaganov/RestApi/internal/bd/model"
|
||||
)
|
||||
|
||||
func (r *RestServer) configureRouterUser() {
|
||||
|
@ -11,17 +12,25 @@ func (r *RestServer) configureRouterUser() {
|
|||
|
||||
func (r *RestServer) HandleFuncRegUser() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, res *http.Request) {
|
||||
user := model.User{}
|
||||
err := res.ParseForm()
|
||||
if err != nil {
|
||||
r.logger.Error(err)
|
||||
}
|
||||
user.Id = 1
|
||||
user.Login = res.Form.Get("user")
|
||||
user.Password = res.Form.Get("password")
|
||||
user.Email = res.Form.Get("email")
|
||||
user.PermisionLVL = 1
|
||||
user.Token = "dasf2!23sfafaQWerq"
|
||||
|
||||
user := res.Form.Get("user")
|
||||
password := res.Form.Get("password")
|
||||
mail := res.Form.Get("email")
|
||||
borndata := res.Form.Get("born")
|
||||
|
||||
fmt.Println(user, password, mail, borndata)
|
||||
RetUser, err := r.db.User().Create(&user)
|
||||
if err != nil {
|
||||
r.logger.Errorln(err)
|
||||
}
|
||||
if RetUser != nil {
|
||||
r.logger.Infoln("Create new user with id = ", RetUser.Id, " and with permissionLvl = ", RetUser.Id)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,15 +2,9 @@ CREATE TABLE users (
|
|||
id INTEGER NOT NULL,
|
||||
login VARCHAR(25) not NULL,
|
||||
email VARCHAR(255) NOT NULL,
|
||||
password VARCHAR() NOT NULL,
|
||||
avatar_url VARCHAR(),
|
||||
token VARCHAR() NOT NULL,
|
||||
permisionLVL INTEGER NOT NULL
|
||||
|
||||
|
||||
|
||||
password VARCHAR(2500) NOT NULL,
|
||||
avatar_url VARCHAR(2500),
|
||||
token VARCHAR(2500) NOT NULL,
|
||||
permisionLVL INTEGER NOT NULL,
|
||||
PRIMARY KEY(id)
|
||||
PRIMARY KEY(email)
|
||||
PRIMARY KEY(login)
|
||||
PRIMARY KEY(token)
|
||||
);
|
Loading…
Reference in New Issue