Skip to content

Commit

Permalink
Merge pull request #73 from teknologi-umum/ref/backend/better-formatting
Browse files Browse the repository at this point in the history
ref(backend): better formatting for list attendees
  • Loading branch information
WahidinAji authored Oct 13, 2023
2 parents 01b3acb + 016356c commit 872f0d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 10 additions & 3 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os"
"os/signal"
"strings"
"text/tabwriter"
"time"

"github.com/flowchartsman/handlebars/v3"
Expand Down Expand Up @@ -509,12 +510,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()
},
},
{
Expand Down
6 changes: 4 additions & 2 deletions backend/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/csv"
"os"
"strconv"
"time"

"github.com/getsentry/sentry-go"
"github.com/jackc/pgx/v5"
Expand Down Expand Up @@ -40,6 +41,7 @@ type User struct {
Email string
Type Type
IsProcessed bool
CreatedAt time.Time
}

func (c CreateParticipantRequest) validate() (errors []string) {
Expand Down Expand Up @@ -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,
)
Expand All @@ -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
}
Expand Down

0 comments on commit 872f0d2

Please sign in to comment.