From 195fc03c2f27601ea54d540df32fab704aa4fc55 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Sun, 8 Oct 2023 20:46:28 +0700 Subject: [PATCH] ref(backend): better formatting for list attendees --- backend/main.go | 13 ++++++++++--- backend/user.go | 6 ++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/backend/main.go b/backend/main.go index 6438a86..447da09 100644 --- a/backend/main.go +++ b/backend/main.go @@ -11,6 +11,7 @@ import ( "os" "os/signal" "strings" + "text/tabwriter" "time" "github.com/flowchartsman/handlebars/v3" @@ -508,12 +509,18 @@ func App() *cli.App { return err } - log.Info().Msg("List of participants") + w := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', tabwriter.TabIndent) + w.Write([]byte("Name\tEmail\tRegistered At\t")) for _, user := range users { - log.Info().Msgf("%s - %s", user.Name, user.Email) + w.Write([]byte(fmt.Sprintf( + "%s\t%s\t%s\t", + user.Name, + user.Email, + user.CreatedAt.In(time.FixedZone("WIB", 7*60*60)).Format(time.Stamp), + ))) } - return nil + return w.Flush() }, }, { diff --git a/backend/user.go b/backend/user.go index 67362f8..cb230bf 100644 --- a/backend/user.go +++ b/backend/user.go @@ -5,6 +5,7 @@ import ( "encoding/csv" "os" "strconv" + "time" "github.com/getsentry/sentry-go" "github.com/jackc/pgx/v5" @@ -40,6 +41,7 @@ type User struct { Email string Type Type IsProcessed bool + CreatedAt time.Time } func (c CreateParticipantRequest) validate() (errors []string) { @@ -112,7 +114,7 @@ func (u *UserDomain) GetUsers(ctx context.Context, filter UserFilterRequest) ([] rows, err := c.Query( ctx, - "SELECT name, email, type, is_processed FROM users WHERE type = $1 AND is_processed = $2", + "SELECT name, email, type, is_processed, created_at FROM users WHERE type = $1 AND is_processed = $2", filter.Type, filter.IsProcessed, ) @@ -124,7 +126,7 @@ func (u *UserDomain) GetUsers(ctx context.Context, filter UserFilterRequest) ([] var users []User for rows.Next() { var user User - err := rows.Scan(&user.Name, &user.Email, &user.Type, &user.IsProcessed) + err := rows.Scan(&user.Name, &user.Email, &user.Type, &user.IsProcessed, &user.CreatedAt) if err != nil { return nil, err }