Skip to content

Commit

Permalink
Small fix for previous commit :)
Browse files Browse the repository at this point in the history
  • Loading branch information
jveski committed Oct 1, 2023
1 parent 146db9d commit e00874f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion keycloak/keycloak.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (k *Keycloak) ensureToken(ctx context.Context) (*gocloak.JWT, error) {
}

type AccessUser struct {
UUID string
UUID, Name string
KeyfobNumber int
}

Expand All @@ -146,6 +146,7 @@ func newAccessUser(kcuser *gocloak.User) *AccessUser {

return &AccessUser{
UUID: *kcuser.ID,
Name: fmt.Sprintf("%s %s", gocloak.PString(kcuser.FirstName), gocloak.PString(kcuser.LastName)),
KeyfobNumber: fobID,
}
}
Expand Down
9 changes: 8 additions & 1 deletion reporting/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ func (c *Controller) scrape(ctx context.Context) error {
}

fn := func(swipe *client.CardSwipe) error {
_, err := c.db.Exec("INSERT INTO swipes (id, cardID, doorID, time, name) VALUES ($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING", swipe.ID, swipe.CardID, swipe.DoorID, swipe.Time, usersByUUID[swipe.Name])
var name string
if user := usersByUUID[swipe.Name]; user != nil {
name = user.Name
} else {
name = swipe.Name // fall back to UUID
}

_, err := c.db.Exec("INSERT INTO swipes (id, cardID, doorID, time, name) VALUES ($1, $2, $3, $4, $5) ON CONFLICT DO NOTHING", swipe.ID, swipe.CardID, swipe.DoorID, swipe.Time, name)
if err != nil {
return fmt.Errorf("inserting swipe %d into database: %s", swipe.ID, err)
}
Expand Down

0 comments on commit e00874f

Please sign in to comment.