Skip to content

Commit

Permalink
update lastaccessed at to utc
Browse files Browse the repository at this point in the history
  • Loading branch information
IGSON2 committed May 5, 2024
1 parent 6c91a8a commit f9e2d36
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 3 additions & 1 deletion backend/api/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math"
"strings"
"time"

"github.com/gofiber/fiber/v2"
)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions backend/db/sqlc/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down
13 changes: 6 additions & 7 deletions backend/db/sqlc/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package db

import (
"context"
"database/sql"
"testing"
"time"

Expand Down Expand Up @@ -30,15 +29,15 @@ func TestLastaccessedAt(t *testing.T) {
}
store := newTestStore(t)

userID := "coactadmin"
userID := "[email protected]"

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)
Expand Down

0 comments on commit f9e2d36

Please sign in to comment.