Skip to content

Commit eca224f

Browse files
handle time in unix
1 parent 085ae6a commit eca224f

File tree

5 files changed

+44
-36
lines changed

5 files changed

+44
-36
lines changed

internal/app/auth/domain.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ type User struct {
2323
IsAdmin bool `json:"is_admin"`
2424
Password string `json:"password"`
2525
IsDeleted bool `json:"is_deleted"`
26-
DeletedAt sql.NullTime `json:"deleted_at"`
27-
CreatedAt string `json:"created_at"`
28-
UpdatedAt string `json:"updated_at"`
26+
DeletedAt sql.NullInt64 `json:"deleted_at"`
27+
CreatedAt int64 `json:"created_at"`
28+
UpdatedAt int64 `json:"updated_at"`
2929
}
3030

3131
type GithubUserResponse struct {

internal/app/user/domain.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ type User struct {
1414
IsAdmin bool `json:"is_admin"`
1515
Password string `json:"password"`
1616
IsDeleted bool `json:"is_deleted"`
17-
DeletedAt sql.NullTime `json:"deleted_at"`
18-
CreatedAt string `json:"created_at"`
19-
UpdatedAt string `json:"updated_at"`
17+
DeletedAt sql.NullInt64 `json:"deleted_at"`
18+
CreatedAt int64 `json:"created_at"`
19+
UpdatedAt int64 `json:"updated_at"`
2020
}
2121

2222
type CreateUserRequestBody struct {

internal/migrations/000001_init.up.sql

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ CREATE TABLE "users"(
1010
"is_admin" BOOLEAN DEFAULT FALSE,
1111
"password" VARCHAR(255) DEFAULT '',
1212
"is_deleted" BOOLEAN DEFAULT FALSE,
13-
"deleted_at" TIMESTAMP(0) WITHOUT TIME ZONE,
14-
"created_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
15-
"updated_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL
13+
"deleted_at" BIGINT,
14+
"created_at" BIGINT NOT NULL,
15+
"updated_at" BIGINT NOT NULL
1616
);
1717

1818
CREATE TABLE "leaderboard_hourly"(
@@ -22,8 +22,8 @@ CREATE TABLE "leaderboard_hourly"(
2222
"avatar_url" VARCHAR(255) NOT NULL,
2323
"current_balance" BIGINT NOT NULL,
2424
"rank" BIGINT NOT NULL,
25-
"refreshed_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
26-
"created_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL
25+
"refreshed_at" BIGINT NOT NULL,
26+
"created_at" BIGINT NOT NULL
2727
);
2828

2929
CREATE TABLE "contributions"(
@@ -33,9 +33,9 @@ CREATE TABLE "contributions"(
3333
"contribution_score_id" BIGINT NOT NULL,
3434
"contribution_type" VARCHAR(255) NOT NULL,
3535
"balance_change" BIGINT NOT NULL,
36-
"contributed_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
37-
"created_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
38-
"updated_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL
36+
"contributed_at" BIGINT NOT NULL,
37+
"created_at" BIGINT NOT NULL,
38+
"updated_at" BIGINT NOT NULL
3939
);
4040

4141
CREATE TABLE "repositories"(
@@ -46,17 +46,17 @@ CREATE TABLE "repositories"(
4646
"languages_url" VARCHAR(255) NOT NULL,
4747
"repo_url" VARCHAR(255) NOT NULL,
4848
"owner_name" VARCHAR(255) NOT NULL,
49-
"update_date" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
50-
"created_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
51-
"updated_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL
49+
"update_date" BIGINT NOT NULL,
50+
"created_at" BIGINT NOT NULL,
51+
"updated_at" BIGINT NOT NULL
5252
);
5353

5454
CREATE TABLE "badges"(
5555
"id" SERIAL PRIMARY KEY,
5656
"user_id" BIGINT NOT NULL,
5757
"badge_type" VARCHAR(255) NOT NULL,
58-
"earned_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
59-
"created_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL
58+
"earned_at" BIGINT NOT NULL,
59+
"created_at" BIGINT NOT NULL
6060
);
6161

6262
CREATE TABLE "transactions"(
@@ -66,8 +66,8 @@ CREATE TABLE "transactions"(
6666
"is_redeemed" BOOLEAN NOT NULL,
6767
"is_gained" BOOLEAN NOT NULL,
6868
"transacted_balance" BIGINT NOT NULL,
69-
"transacted_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
70-
"created_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL
69+
"transacted_at" BIGINT NOT NULL,
70+
"created_at" BIGINT NOT NULL
7171
);
7272

7373
CREATE TABLE "summary"(
@@ -78,24 +78,24 @@ CREATE TABLE "summary"(
7878
"badges_count" BIGINT NOT NULL,
7979
"rank" BIGINT NOT NULL,
8080
"contribution_id" BIGINT NOT NULL,
81-
"created_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
82-
"updated_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL
81+
"created_at" BIGINT NOT NULL,
82+
"updated_at" BIGINT NOT NULL
8383
);
8484

8585
CREATE TABLE "contribution_score"(
8686
"id" SERIAL PRIMARY KEY,
8787
"admin_id" BIGINT NOT NULL,
8888
"contribution_type" VARCHAR(255) NOT NULL,
8989
"score" BIGINT NOT NULL,
90-
"created_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
91-
"updated_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL
90+
"created_at" BIGINT NOT NULL,
91+
"updated_at" BIGINT NOT NULL
9292
);
9393

9494
CREATE TABLE "goal"(
9595
"id" SERIAL PRIMARY KEY,
9696
"level" VARCHAR(255) NOT NULL,
97-
"created_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
98-
"updated_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL
97+
"created_at" BIGINT NOT NULL,
98+
"updated_at" BIGINT NOT NULL
9999
);
100100

101101
CREATE TABLE "goal_contribution"(
@@ -105,8 +105,8 @@ CREATE TABLE "goal_contribution"(
105105
"target_count" BIGINT NOT NULL,
106106
"is_custom" BOOLEAN NOT NULL,
107107
"set_by_user_id" BIGINT NOT NULL,
108-
"created_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
109-
"updated_at" TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL
108+
"created_at" BIGINT NOT NULL,
109+
"updated_at" BIGINT NOT NULL
110110
);
111111

112112
ALTER TABLE

internal/repository/domain.go

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

3-
import "database/sql"
3+
import (
4+
"database/sql"
5+
)
46

57
type User struct {
68
Id int
@@ -14,9 +16,9 @@ type User struct {
1416
IsAdmin bool
1517
Password string
1618
IsDeleted bool
17-
DeletedAt sql.NullTime
18-
CreatedAt string
19-
UpdatedAt string
19+
DeletedAt sql.NullInt64
20+
CreatedAt int64
21+
UpdatedAt int64
2022
}
2123

2224
type CreateUserRequestBody struct {

internal/repository/user.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,13 @@ func (ur *userRepository) GetUserById(ctx context.Context, tx *sqlx.Tx, userId i
5959
&user.GithubUsername,
6060
&user.AvatarUrl,
6161
&user.Email,
62+
&user.CurrentActiveGoalId,
6263
&user.CurrentBalance,
6364
&user.IsBlocked,
6465
&user.IsAdmin,
6566
&user.Password,
67+
&user.IsDeleted,
68+
&user.DeletedAt,
6669
&user.CreatedAt,
6770
&user.UpdatedAt,
6871
)
@@ -86,12 +89,15 @@ func (ur *userRepository) GetUserByGithubId(ctx context.Context, tx *sqlx.Tx, gi
8689
&user.Id,
8790
&user.GithubId,
8891
&user.GithubUsername,
89-
&user.Email,
9092
&user.AvatarUrl,
93+
&user.Email,
94+
&user.CurrentActiveGoalId,
9195
&user.CurrentBalance,
9296
&user.IsBlocked,
9397
&user.IsAdmin,
9498
&user.Password,
99+
&user.IsDeleted,
100+
&user.DeletedAt,
95101
&user.CreatedAt,
96102
&user.UpdatedAt,
97103
)
@@ -116,8 +122,8 @@ func (ur *userRepository) CreateUser(ctx context.Context, tx *sqlx.Tx, userInfo
116122
userInfo.GithubUsername,
117123
userInfo.Email,
118124
userInfo.AvatarUrl,
119-
time.Now(),
120-
time.Now(),
125+
time.Now().Unix(),
126+
time.Now().Unix(),
121127
).Scan(
122128
&user.Id,
123129
&user.GithubId,

0 commit comments

Comments
 (0)