aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-08-08 20:33:40 +0900
committernsfisis <nsfisis@gmail.com>2024-08-08 20:38:08 +0900
commitd94c9eb68e65d53f09bf3dd26ec4d61d245882ad (patch)
treeb759cf59afb9e1203e4b0e1f2aa81996cd8681d1 /backend
parentbb62b6ff19d9f8008458d1c0ad0b8b76090f091e (diff)
downloadiosdc-japan-2025-albatross-d94c9eb68e65d53f09bf3dd26ec4d61d245882ad.tar.gz
iosdc-japan-2025-albatross-d94c9eb68e65d53f09bf3dd26ec4d61d245882ad.tar.zst
iosdc-japan-2025-albatross-d94c9eb68e65d53f09bf3dd26ec4d61d245882ad.zip
feat(backend): add `code_hash` to `submissions` table
Diffstat (limited to 'backend')
-rw-r--r--backend/api/handler_wrapper.go28
-rw-r--r--backend/db/models.go1
-rw-r--r--backend/db/query.sql.go6
-rw-r--r--backend/query.sql4
-rw-r--r--backend/schema.sql1
5 files changed, 22 insertions, 18 deletions
diff --git a/backend/api/handler_wrapper.go b/backend/api/handler_wrapper.go
index 69b9baa..9f524e9 100644
--- a/backend/api/handler_wrapper.go
+++ b/backend/api/handler_wrapper.go
@@ -11,15 +11,15 @@ import (
"github.com/nsfisis/iosdc-japan-2024-albatross/backend/db"
)
-var _ StrictServerInterface = (*ApiHandlerWrapper)(nil)
+var _ StrictServerInterface = (*HandlerWrapper)(nil)
-type ApiHandlerWrapper struct {
- innerHandler Handler
+type HandlerWrapper struct {
+ impl Handler
}
-func NewHandler(queries *db.Queries, hubs GameHubsInterface) *ApiHandlerWrapper {
- return &ApiHandlerWrapper{
- innerHandler: Handler{
+func NewHandler(queries *db.Queries, hubs GameHubsInterface) *HandlerWrapper {
+ return &HandlerWrapper{
+ impl: Handler{
q: queries,
hubs: hubs,
},
@@ -39,7 +39,7 @@ func parseJWTClaimsFromAuthorizationHeader(authorization string) (*auth.JWTClaim
return claims, nil
}
-func (h *ApiHandlerWrapper) GetGame(ctx context.Context, request GetGameRequestObject) (GetGameResponseObject, error) {
+func (h *HandlerWrapper) GetGame(ctx context.Context, request GetGameRequestObject) (GetGameResponseObject, error) {
user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization)
if err != nil {
return GetGame401JSONResponse{
@@ -48,10 +48,10 @@ func (h *ApiHandlerWrapper) GetGame(ctx context.Context, request GetGameRequestO
},
}, nil
}
- return h.innerHandler.GetGame(ctx, request, user)
+ return h.impl.GetGame(ctx, request, user)
}
-func (h *ApiHandlerWrapper) GetGames(ctx context.Context, request GetGamesRequestObject) (GetGamesResponseObject, error) {
+func (h *HandlerWrapper) GetGames(ctx context.Context, request GetGamesRequestObject) (GetGamesResponseObject, error) {
user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization)
if err != nil {
return GetGames401JSONResponse{
@@ -60,10 +60,10 @@ func (h *ApiHandlerWrapper) GetGames(ctx context.Context, request GetGamesReques
},
}, nil
}
- return h.innerHandler.GetGames(ctx, request, user)
+ return h.impl.GetGames(ctx, request, user)
}
-func (h *ApiHandlerWrapper) GetToken(ctx context.Context, request GetTokenRequestObject) (GetTokenResponseObject, error) {
+func (h *HandlerWrapper) GetToken(ctx context.Context, request GetTokenRequestObject) (GetTokenResponseObject, error) {
user, err := parseJWTClaimsFromAuthorizationHeader(request.Params.Authorization)
if err != nil {
return GetToken401JSONResponse{
@@ -72,9 +72,9 @@ func (h *ApiHandlerWrapper) GetToken(ctx context.Context, request GetTokenReques
},
}, nil
}
- return h.innerHandler.GetToken(ctx, request, user)
+ return h.impl.GetToken(ctx, request, user)
}
-func (h *ApiHandlerWrapper) PostLogin(ctx context.Context, request PostLoginRequestObject) (PostLoginResponseObject, error) {
- return h.innerHandler.PostLogin(ctx, request)
+func (h *HandlerWrapper) PostLogin(ctx context.Context, request PostLoginRequestObject) (PostLoginResponseObject, error) {
+ return h.impl.PostLogin(ctx, request)
}
diff --git a/backend/db/models.go b/backend/db/models.go
index d4cf98b..5bca7b7 100644
--- a/backend/db/models.go
+++ b/backend/db/models.go
@@ -36,6 +36,7 @@ type Submission struct {
UserID int32
Code string
CodeSize int32
+ CodeHash string
CreatedAt pgtype.Timestamp
}
diff --git a/backend/db/query.sql.go b/backend/db/query.sql.go
index 5475067..dc87602 100644
--- a/backend/db/query.sql.go
+++ b/backend/db/query.sql.go
@@ -34,8 +34,8 @@ func (q *Queries) AggregateTestcaseResults(ctx context.Context, submissionID int
}
const createSubmission = `-- name: CreateSubmission :one
-INSERT INTO submissions (game_id, user_id, code, code_size)
-VALUES ($1, $2, $3, $4)
+INSERT INTO submissions (game_id, user_id, code, code_size, code_hash)
+VALUES ($1, $2, $3, $4, $5)
RETURNING submission_id
`
@@ -44,6 +44,7 @@ type CreateSubmissionParams struct {
UserID int32
Code string
CodeSize int32
+ CodeHash string
}
func (q *Queries) CreateSubmission(ctx context.Context, arg CreateSubmissionParams) (int32, error) {
@@ -52,6 +53,7 @@ func (q *Queries) CreateSubmission(ctx context.Context, arg CreateSubmissionPara
arg.UserID,
arg.Code,
arg.CodeSize,
+ arg.CodeHash,
)
var submission_id int32
err := row.Scan(&submission_id)
diff --git a/backend/query.sql b/backend/query.sql
index e767746..f0e4034 100644
--- a/backend/query.sql
+++ b/backend/query.sql
@@ -59,8 +59,8 @@ SET
WHERE game_id = $1;
-- name: CreateSubmission :one
-INSERT INTO submissions (game_id, user_id, code, code_size)
-VALUES ($1, $2, $3, $4)
+INSERT INTO submissions (game_id, user_id, code, code_size, code_hash)
+VALUES ($1, $2, $3, $4, $5)
RETURNING submission_id;
-- name: ListTestcasesByGameID :many
diff --git a/backend/schema.sql b/backend/schema.sql
index 74d1202..64642bc 100644
--- a/backend/schema.sql
+++ b/backend/schema.sql
@@ -59,6 +59,7 @@ CREATE TABLE submissions (
user_id INT NOT NULL,
code TEXT NOT NULL,
code_size INT NOT NULL,
+ code_hash CHAR(32) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
CONSTRAINT fk_game_id FOREIGN KEY(game_id) REFERENCES games(game_id),
CONSTRAINT fk_user_id FOREIGN KEY(user_id) REFERENCES users(user_id)