// Create adds a new user.
Create adds a new user.
// Create adds a new user .
func (ur *UserRepository) Create(ctx context.Context, u *user.User) error {
	q := `
	INSERT INTO users (first_name, last_name, username, email, picture, password, created_at, updated_at)
		VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
		RETURNING id;
	`
	if u.Picture == "" {
		u.Picture = "https://placekitten.com/g/300/300"
	}
	if err := u.HashPassword(); err != nil {
		return err
	}
	stmt, err := ur.Data.DB.PrepareContext(ctx, q)
	if err != nil {
		return err
	}
	defer stmt.Close()
	row := stmt.QueryRowContext(ctx, u.FirstName, u.LastName, u.Username, u.Email,
		u.Picture, u.PasswordHash, time.Now(), time.Now(),
	)
	err = row.Scan(&u.ID)
	if err != nil {
		return err
	}
	return nil
}
func ( ur * UserRepository ) Create ( ctx context . Context , u * user . User ) error { q := `
	INSERT INTO users (first_name, last_name, username, email, picture, password, created_at, updated_at)
		VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
		RETURNING id;
	` if u . Picture == " " { u . Picture = " " } if err := u . HashPassword ( ) ; err != nil { return err } stmt , err := ur . Data . DB . PrepareContext ( ctx , q ) if err != nil { return err } defer stmt . Close ( ) row := stmt . QueryRowContext ( ctx , u . FirstName , u . LastName , u . Username , u . Email , u . Picture , u . PasswordHash , time . Now ( ) , time . Now ( ) , ) err = row . Scan ( & u . ID ) if err != nil { return err } return nil }
Create adds a new user.
Create adds a new user .