From f9e2d36a551ffd3025d2e7e8c16a1706a7526aa7 Mon Sep 17 00:00:00 2001 From: Igson <91243660+IGSON2@users.noreply.github.com> Date: Sun, 5 May 2024 20:21:13 +0900 Subject: [PATCH] update lastaccessed at to utc --- backend/api/admin.go | 4 +++- backend/db/sqlc/transactions.go | 3 +-- backend/db/sqlc/users_test.go | 13 ++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/backend/api/admin.go b/backend/api/admin.go index 777605c..baaa067 100644 --- a/backend/api/admin.go +++ b/backend/api/admin.go @@ -5,6 +5,7 @@ import ( "fmt" "math" "strings" + "time" "github.com/gofiber/fiber/v2" ) @@ -47,7 +48,8 @@ func (s *Server) GetUsers(c *fiber.Ctx) error { Referral: user.Referral, RecomCode: user.RecommenderCode, SignUpDate: user.CreatedAt.Format("06.01.02 15:04:05"), - LastAccess: user.LastAccessedAt.Time.Format("06.01.02 15:04:05"), + // Mysql DB의 time_zone이 Asia/Seoul이여도, Default로 생성되는 값에만 적용되고 Update로 변환되는 argument에는 UTC가 적용된다. + LastAccess: user.LastAccessedAt.Time.Add(9 * time.Hour).Format("06.01.02 15:04:05"), }) } return c.Status(fiber.StatusOK).JSON(response) diff --git a/backend/db/sqlc/transactions.go b/backend/db/sqlc/transactions.go index d277f71..49d0826 100644 --- a/backend/db/sqlc/transactions.go +++ b/backend/db/sqlc/transactions.go @@ -169,8 +169,7 @@ func (store *SqlStore) CheckAttendTx(ctx context.Context, arg CheckAttendTxParam lastAccessed = user.LastAccessedAt.Time _, err = q.UpdateUserLastAccessedAt(ctx, UpdateUserLastAccessedAtParams{ - // Mysql DB의 time_zone이 Asia/Seoul이여도, Default로 생성되는 값에만 적용되고 Update로 변환되는 argument에는 UTC가 적용된다. - LastAccessedAt: sql.NullTime{Time: time.Now().Add(9 * time.Hour), Valid: true}, + LastAccessedAt: sql.NullTime{Time: time.Now(), Valid: true}, UserID: arg.UserID, }) diff --git a/backend/db/sqlc/users_test.go b/backend/db/sqlc/users_test.go index 9bdc9a1..d195910 100644 --- a/backend/db/sqlc/users_test.go +++ b/backend/db/sqlc/users_test.go @@ -2,7 +2,6 @@ package db import ( "context" - "database/sql" "testing" "time" @@ -30,15 +29,15 @@ func TestLastaccessedAt(t *testing.T) { } store := newTestStore(t) - userID := "coactadmin" + userID := "suninnaa@gmail.com" now := time.Now() - _, err := store.UpdateUserLastAccessedAt(context.Background(), UpdateUserLastAccessedAtParams{ - LastAccessedAt: sql.NullTime{Time: now, Valid: true}, - UserID: userID, - }) - require.NoError(t, err) + // _, err := store.UpdateUserLastAccessedAt(context.Background(), UpdateUserLastAccessedAtParams{ + // LastAccessedAt: sql.NullTime{Time: now, Valid: true}, + // UserID: userID, + // }) + // require.NoError(t, err) userA, err := store.GetUser(context.Background(), userID) require.NoError(t, err)