Skip to content

Commit e430a91

Browse files
Merge pull request #12 from joshsoftware/fix/login-timestamp-type
Fix login service fail due to changed column type
2 parents 17d917d + 25d5b91 commit e430a91

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

internal/app/auth/domain.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package auth
22

3-
import "database/sql"
3+
import (
4+
"database/sql"
5+
"time"
6+
)
47

58
const (
69
LoginWithGithubFailed = "LoginWithGithubFailed"
@@ -23,9 +26,9 @@ type User struct {
2326
IsAdmin bool `json:"is_admin"`
2427
Password string `json:"password"`
2528
IsDeleted bool `json:"is_deleted"`
26-
DeletedAt sql.NullInt64 `json:"deleted_at"`
27-
CreatedAt int64 `json:"created_at"`
28-
UpdatedAt int64 `json:"updated_at"`
29+
DeletedAt sql.NullTime `json:"deleted_at"`
30+
CreatedAt time.Time `json:"created_at"`
31+
UpdatedAt time.Time `json:"updated_at"`
2932
}
3033

3134
type GithubUserResponse struct {

internal/app/user/domain.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package user
22

3-
import "database/sql"
3+
import (
4+
"database/sql"
5+
"time"
6+
)
47

58
type User struct {
69
Id int `json:"user_id"`
@@ -14,9 +17,9 @@ type User struct {
1417
IsAdmin bool `json:"is_admin"`
1518
Password string `json:"password"`
1619
IsDeleted bool `json:"is_deleted"`
17-
DeletedAt sql.NullInt64 `json:"deleted_at"`
18-
CreatedAt int64 `json:"created_at"`
19-
UpdatedAt int64 `json:"updated_at"`
20+
DeletedAt sql.NullTime `json:"deleted_at"`
21+
CreatedAt time.Time `json:"created_at"`
22+
UpdatedAt time.Time `json:"updated_at"`
2023
}
2124

2225
type CreateUserRequestBody struct {

internal/repository/domain.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package repository
22

33
import (
44
"database/sql"
5+
"time"
56
)
67

78
type User struct {
@@ -16,9 +17,9 @@ type User struct {
1617
IsAdmin bool
1718
Password string
1819
IsDeleted bool
19-
DeletedAt sql.NullInt64
20-
CreatedAt int64
21-
UpdatedAt int64
20+
DeletedAt sql.NullTime
21+
CreatedAt time.Time
22+
UpdatedAt time.Time
2223
}
2324

2425
type CreateUserRequestBody struct {

internal/repository/user.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,12 @@ const (
3939
github_id,
4040
github_username,
4141
email,
42-
avatar_url,
43-
created_at,
44-
updated_at
42+
avatar_url
4543
)
46-
VALUES ($1, $2, $3, $4, $5, $6)
44+
VALUES ($1, $2, $3, $4)
4745
RETURNING *`
4846

49-
updateEmailQuery = "UPDATE users SET email=$1 where id=$2"
47+
updateEmailQuery = "UPDATE users SET email=$1, updated_at=$2 where id=$3"
5048
)
5149

5250
func (ur *userRepository) GetUserById(ctx context.Context, tx *sqlx.Tx, userId int) (User, error) {
@@ -122,8 +120,6 @@ func (ur *userRepository) CreateUser(ctx context.Context, tx *sqlx.Tx, userInfo
122120
userInfo.GithubUsername,
123121
userInfo.Email,
124122
userInfo.AvatarUrl,
125-
time.Now().Unix(),
126-
time.Now().Unix(),
127123
).Scan(
128124
&user.Id,
129125
&user.GithubId,
@@ -149,10 +145,10 @@ func (ur *userRepository) CreateUser(ctx context.Context, tx *sqlx.Tx, userInfo
149145

150146
}
151147

152-
func (ur *userRepository) UpdateUserEmail(ctx context.Context, tx *sqlx.Tx, Id int, email string) error {
148+
func (ur *userRepository) UpdateUserEmail(ctx context.Context, tx *sqlx.Tx, userId int, email string) error {
153149
executer := ur.BaseRepository.initiateQueryExecuter(tx)
154150

155-
_, err := executer.ExecContext(ctx, updateEmailQuery, email, Id)
151+
_, err := executer.ExecContext(ctx, updateEmailQuery, email, time.Now(), userId)
156152
if err != nil {
157153
slog.Error("failed to update user email", "error", err)
158154
return apperrors.ErrInternalServer

0 commit comments

Comments
 (0)