User backend registration

This commit is contained in:
Leons Aleksandrovs
2025-07-05 22:17:14 +03:00
parent 8916f3e394
commit 66ed77e758
6 changed files with 100 additions and 13 deletions
+17 -2
View File
@@ -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
}