Add creat user in database
This commit is contained in:
		
							parent
							
								
									25fcffc259
								
							
						
					
					
						commit
						88ae5fa188
					
				@ -13,8 +13,8 @@ type Userrepo struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (u *Userrepo) Create(user *model.User) (*model.User, error) {
 | 
					func (u *Userrepo) Create(user *model.User) (*model.User, error) {
 | 
				
			||||||
	err := u.db.db.QueryRow(context.Background(),
 | 
						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)").
 | 
							"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.Login, user.Email, user.Password, user.Avatar_Url, user.Token, user.PermisionLVL)
 | 
							Scan(&user.Id, &user.PermisionLVL)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,8 +1,9 @@
 | 
				
			|||||||
package restserver
 | 
					package restserver
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
	"fmt"
 | 
					 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"git.ukamnya.ru/stulyaganov/RestApi/internal/bd/model"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (r *RestServer) configureRouterUser() {
 | 
					func (r *RestServer) configureRouterUser() {
 | 
				
			||||||
@ -11,17 +12,25 @@ func (r *RestServer) configureRouterUser() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (r *RestServer) HandleFuncRegUser() http.HandlerFunc {
 | 
					func (r *RestServer) HandleFuncRegUser() http.HandlerFunc {
 | 
				
			||||||
	return func(w http.ResponseWriter, res *http.Request) {
 | 
						return func(w http.ResponseWriter, res *http.Request) {
 | 
				
			||||||
 | 
							user := model.User{}
 | 
				
			||||||
		err := res.ParseForm()
 | 
							err := res.ParseForm()
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			r.logger.Error(err)
 | 
								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")
 | 
							RetUser, err := r.db.User().Create(&user)
 | 
				
			||||||
		password := res.Form.Get("password")
 | 
							if err != nil {
 | 
				
			||||||
		mail := res.Form.Get("email")
 | 
								r.logger.Errorln(err)
 | 
				
			||||||
		borndata := res.Form.Get("born")
 | 
							}
 | 
				
			||||||
 | 
							if RetUser != nil {
 | 
				
			||||||
		fmt.Println(user, password, mail, borndata)
 | 
								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,
 | 
					    id INTEGER NOT NULL,
 | 
				
			||||||
    login VARCHAR(25)  not NULL,
 | 
					    login VARCHAR(25)  not NULL,
 | 
				
			||||||
    email VARCHAR(255) NOT NULL,
 | 
					    email VARCHAR(255) NOT NULL,
 | 
				
			||||||
    password VARCHAR() NOT NULL,
 | 
					    password VARCHAR(2500) NOT NULL,
 | 
				
			||||||
    avatar_url VARCHAR(),
 | 
					    avatar_url VARCHAR(2500),
 | 
				
			||||||
    token VARCHAR() NOT NULL,
 | 
					    token VARCHAR(2500) NOT NULL,
 | 
				
			||||||
    permisionLVL INTEGER NOT NULL
 | 
					    permisionLVL INTEGER NOT NULL,
 | 
				
			||||||
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    PRIMARY KEY(id)
 | 
					    PRIMARY KEY(id)
 | 
				
			||||||
    PRIMARY KEY(email)
 | 
					 | 
				
			||||||
    PRIMARY KEY(login)
 | 
					 | 
				
			||||||
    PRIMARY KEY(token)
 | 
					 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user