test: retrieve users
This commit is contained in:
@ -1,9 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"gitea.local/admin/hspguard/internal/repository"
|
||||
"github.com/jackc/pgx/v5"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
fmt.Println("Hello, World!")
|
||||
|
||||
conn, err := pgx.Connect(ctx, os.Getenv("DATABASE_URL"))
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
defer conn.Close(ctx)
|
||||
|
||||
repo := repository.New(conn)
|
||||
|
||||
// id, err := repo.InsertUser(ctx, repository.InsertUserParams{
|
||||
// Email: "test@test.com",
|
||||
// FullName: "Test John",
|
||||
// PasswordHash: "fjeijh3uhit5hg45bjkf4ghy8ft548",
|
||||
// IsAdmin: true,
|
||||
// })
|
||||
// if err != nil {
|
||||
// log.Fatalln("ERR: Failed to insert user:", err)
|
||||
// return
|
||||
// }
|
||||
|
||||
users, _ := repo.FindAllUsers(ctx)
|
||||
|
||||
dump, err := json.Marshal(users)
|
||||
if err != nil {
|
||||
log.Fatalln("ERR: Failed to marshal response:", err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(string(dump))
|
||||
}
|
||||
|
Reference in New Issue
Block a user