Skip to content

Commit

Permalink
chore(backend): use chrono package for time
Browse files Browse the repository at this point in the history
- update api keys to use chrono package for handling time
- update teams to use chrono package for handling time
  • Loading branch information
detj committed Dec 6, 2023
1 parent 2391526 commit c44fedd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 28 deletions.
8 changes: 4 additions & 4 deletions measure-backend/measure-go/apiKeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
"fmt"
"time"

"measure-backend/measure-go/chrono"

"github.com/google/uuid"
"github.com/jackc/pgx/v5"
)

const ISOFormatJS = "2006-01-02T15:04:05Z"

type APIKey struct {
appId uuid.UUID
keyPrefix string
Expand All @@ -30,11 +30,11 @@ func (a APIKey) MarshalJSON() ([]byte, error) {

apiMap["key"] = a.String()
apiMap["revoked"] = a.revoked
apiMap["created_at"] = a.createdAt.Format(ISOFormatJS)
apiMap["created_at"] = a.createdAt.Format(chrono.ISOFormatJS)
if a.lastSeen.IsZero() {
apiMap["last_seen"] = nil
} else {
apiMap["last_seen"] = a.lastSeen.Format(ISOFormatJS)
apiMap["last_seen"] = a.lastSeen.Format(chrono.ISOFormatJS)
}
return json.Marshal(apiMap)
}
Expand Down
31 changes: 7 additions & 24 deletions measure-backend/measure-go/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package main

import (
"context"
"encoding/json"
"fmt"
"net/http"
"slices"
"time"

"measure-backend/measure-go/chrono"
"measure-backend/measure-go/cipher"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -58,29 +58,12 @@ type Invitee struct {
}

type Member struct {
ID *uuid.UUID `json:"id"`
Name *string `json:"name"`
Email *string `json:"email"`
Role *string `json:"role"`
LastSignInAt *ISOTime `json:"last_sign_in_at"`
CreatedAt *ISOTime `json:"created_at"`
}

type ISOTime time.Time

func (t *ISOTime) MarshalJSON() ([]byte, error) {
time := time.Time(*t).Format(ISOFormatJS)
return json.Marshal(time)
}

func (i *ISOTime) Scan(src interface{}) error {
switch t := src.(type) {
case time.Time:
*i = ISOTime(t)
return nil
default:
return fmt.Errorf("failed to convert to ISOTime type from %T", t)
}
ID *uuid.UUID `json:"id"`
Name *string `json:"name"`
Email *string `json:"email"`
Role *string `json:"role"`
LastSignInAt *chrono.ISOTime `json:"last_sign_in_at"`
CreatedAt *chrono.ISOTime `json:"created_at"`
}

func (t *Team) getApps() ([]App, error) {
Expand Down

0 comments on commit c44fedd

Please sign in to comment.