From c44fedd3b1448081d3b1939378bf2906063aee38 Mon Sep 17 00:00:00 2001 From: Debjeet Biswas Date: Wed, 6 Dec 2023 14:03:28 +0530 Subject: [PATCH] chore(backend): use chrono package for time - update api keys to use chrono package for handling time - update teams to use chrono package for handling time --- measure-backend/measure-go/apiKeys.go | 8 +++---- measure-backend/measure-go/teams.go | 31 ++++++--------------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/measure-backend/measure-go/apiKeys.go b/measure-backend/measure-go/apiKeys.go index 29046c928..09a5e1d62 100644 --- a/measure-backend/measure-go/apiKeys.go +++ b/measure-backend/measure-go/apiKeys.go @@ -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 @@ -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) } diff --git a/measure-backend/measure-go/teams.go b/measure-backend/measure-go/teams.go index 0d87f4eff..f7ba7af53 100644 --- a/measure-backend/measure-go/teams.go +++ b/measure-backend/measure-go/teams.go @@ -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" @@ -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) {