diff --git a/backend/api/admin.go b/backend/api/admin.go index 63e5b29..777605c 100644 --- a/backend/api/admin.go +++ b/backend/api/admin.go @@ -5,7 +5,6 @@ import ( "fmt" "math" "strings" - "time" "github.com/gofiber/fiber/v2" ) @@ -48,9 +47,7 @@ func (s *Server) GetUsers(c *fiber.Ctx) error { Referral: user.Referral, RecomCode: user.RecommenderCode, SignUpDate: user.CreatedAt.Format("06.01.02 15:04:05"), - // Mysql DB의 time_zone이 Asia/Seoul이여도, Default로 생성되는 값에만 적용되고 Update로 변환되는 argument에는 적용되지 않는다. - // LastAccess 필드는 Default로 생성되지 않고, update되기 때문에 client에게 제공할 때 별도의 time zone 변환이 필요하다. - LastAccess: user.LastAccessedAt.Time.In(time.Local).Format("06.01.02 15:04:05"), + LastAccess: user.LastAccessedAt.Time.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 49d0826..d277f71 100644 --- a/backend/db/sqlc/transactions.go +++ b/backend/db/sqlc/transactions.go @@ -169,7 +169,8 @@ func (store *SqlStore) CheckAttendTx(ctx context.Context, arg CheckAttendTxParam lastAccessed = user.LastAccessedAt.Time _, err = q.UpdateUserLastAccessedAt(ctx, UpdateUserLastAccessedAtParams{ - LastAccessedAt: sql.NullTime{Time: time.Now(), Valid: true}, + // Mysql DB의 time_zone이 Asia/Seoul이여도, Default로 생성되는 값에만 적용되고 Update로 변환되는 argument에는 UTC가 적용된다. + LastAccessedAt: sql.NullTime{Time: time.Now().Add(9 * time.Hour), Valid: true}, UserID: arg.UserID, }) diff --git a/backend/db/sqlc/users_test.go b/backend/db/sqlc/users_test.go index 769206e..9bdc9a1 100644 --- a/backend/db/sqlc/users_test.go +++ b/backend/db/sqlc/users_test.go @@ -31,23 +31,21 @@ func TestLastaccessedAt(t *testing.T) { store := newTestStore(t) userID := "coactadmin" - zone, err := time.LoadLocation("Asia/Seoul") - require.NoError(t, err) - // zone = time.UTC - now := time.Now().In(zone) + now := time.Now() - _, err = store.UpdateUserLastAccessedAt(context.Background(), UpdateUserLastAccessedAtParams{ - LastAccessedAt: sql.NullTime{Time: now.Add(9 * time.Hour), Valid: true}, + _, 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) - require.WithinDuration(t, now, userA.LastAccessedAt.Time, time.Second*5) - compareTime := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), time.Now().Hour()-1, 0, 0, 0, time.Local) - require.True(t, compareTime.Before(userA.LastAccessedAt.Time)) - t.Log(compareTime, userA.LastAccessedAt.Time) + crZ, _ := userA.CreatedAt.Zone() + laZ, _ := userA.LastAccessedAt.Time.Zone() + nowZ, _ := now.Zone() + t.Logf("now: %v, created_at: %v, last_accessed_at: %v", nowZ, crZ, laZ) + t.Logf("now: %v, last_accessed_at: %v", now, userA.LastAccessedAt.Time) }