User backend registration
This commit is contained in:
+17
-2
@@ -1,5 +1,11 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"backend/db"
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID int
|
||||
email string
|
||||
@@ -8,6 +14,15 @@ type User struct {
|
||||
createdAt string
|
||||
}
|
||||
|
||||
func Create(email string, name string, hash string) {
|
||||
// TODO: Insert user into database
|
||||
func (u *User) Create(email string, name string, hash string) error {
|
||||
// Generate background context for managing timeouts and disconnections
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
|
||||
// Build database query
|
||||
query := `INSERT INTO users (email, name, password) VALUES ($1, $2, $3)`
|
||||
_, err := db.Pool.Exec(ctx, query, email, name, hash)
|
||||
|
||||
// Return error if any
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user