feat: add rejudge function to storage & update schema

This commit is contained in:
dragonmuffin 2024-08-17 18:00:34 +05:00
parent 80df2e2820
commit 48ad3a5461
3 changed files with 41 additions and 3 deletions

View file

@ -9,5 +9,6 @@ type Solution struct {
LanguageId *int32 `db:"language_id"` LanguageId *int32 `db:"language_id"`
SolutionHash *string `db:"solution_hash"` SolutionHash *string `db:"solution_hash"`
Result *int32 `db:"result"` Result *int32 `db:"result"`
Score *int32 `db:"score"`
CreatedAt *time.Time `db:"created_at"` CreatedAt *time.Time `db:"created_at"`
} }

View file

@ -24,6 +24,10 @@ func NewSolutionStorage(db *sqlx.DB, logger *zap.Logger) *SolutionStorage {
} }
} }
//func updateResult(ctx context.Context, participant_id int32, task_id int32) error {
//
//}
func (storage *SolutionStorage) CreateSolution(ctx context.Context, solution *models.Solution) (int32, error) { func (storage *SolutionStorage) CreateSolution(ctx context.Context, solution *models.Solution) (int32, error) {
query := storage.db.Rebind(` query := storage.db.Rebind(`
INSERT INTO solutions INSERT INTO solutions
@ -65,6 +69,19 @@ func (storage *SolutionStorage) ReadSolutionById(ctx context.Context, id int32)
return &solution, nil return &solution, nil
} }
func (storage *SolutionStorage) RejudgeSolution(ctx context.Context, id int32) error {
query := storage.db.Rebind("UPDATE solutions SET result = ? WHERE id = ?")
_, err := storage.db.ExecContext(ctx, query, models.NotTested, id)
query := storage.db.Rebind("UPDATE testruns SET result = ? WHERE solution_id = ?")
_, err := storage.db.ExecContext(ctx, query, models.NotTested, id)
//FIXME: update result
if err != nil {
return storage.HandlePgErr(err)
}
return nil
}
func (storage *SolutionStorage) DeleteSolution(ctx context.Context, id int32) error { func (storage *SolutionStorage) DeleteSolution(ctx context.Context, id int32) error {
query := storage.db.Rebind("DELETE FROM solutions WHERE id=?") query := storage.db.Rebind("DELETE FROM solutions WHERE id=?")
_, err := storage.db.ExecContext(ctx, query, id) _, err := storage.db.ExecContext(ctx, query, id)

View file

@ -126,6 +126,7 @@ CREATE TABLE IF NOT EXISTS solutions
language_id INT REFERENCES languages ON DELETE CASCADE, language_id INT REFERENCES languages ON DELETE CASCADE,
solution_hash CHAR(128) NOT NULL, solution_hash CHAR(128) NOT NULL,
result INT NOT NULL, result INT NOT NULL,
score INT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY (id) PRIMARY KEY (id)
@ -152,11 +153,29 @@ CREATE INDEX ON tests USING BTREE (testgroup_id);
CREATE TABLE IF NOT EXISTS testgroupruns
(
id serial NOT NULL,
testgroup_id INT REFERENCES testgroups ON DELETE CASCADE,
solution_id INT REFERENCES solutions ON DELETE CASCADE,
result INT NOT NULL,
PRIMARY KEY (id)
);
CREATE INDEX ON testgroupruns USING BTREE (id);
CREATE INDEX ON testgroupruns USING BTREE (result);
CREATE INDEX ON testgroupruns USING BTREE (solution_id);
CREATE TABLE IF NOT EXISTS testruns CREATE TABLE IF NOT EXISTS testruns
( (
id serial NOT NULL, id serial NOT NULL,
test_id INT REFERENCES tests ON DELETE CASCADE, test_id INT REFERENCES tests ON DELETE CASCADE,
solution_id INT REFERENCES solutions ON DELETE CASCADE, --solution_id INT REFERENCES solutions ON DELETE CASCADE,
testgrouprun_id INT REFERENCES testgroupruns ON DELETE CASCADE,
result INT NOT NULL, result INT NOT NULL,
PRIMARY KEY (id) PRIMARY KEY (id)
@ -164,7 +183,7 @@ CREATE TABLE IF NOT EXISTS testruns
CREATE INDEX ON testruns USING BTREE (id); CREATE INDEX ON testruns USING BTREE (id);
CREATE INDEX ON testruns USING BTREE (result); CREATE INDEX ON testruns USING BTREE (result);
CREATE INDEX ON testruns USING BTREE (solution_id); CREATE INDEX ON testruns USING BTREE (testgrouprun_id);
@ -244,6 +263,7 @@ DROP TABLE IF EXISTS solutions CASCADE;
DROP TABLE IF EXISTS languages CASCADE; DROP TABLE IF EXISTS languages CASCADE;
DROP TABLE IF EXISTS testgroups CASCADE; DROP TABLE IF EXISTS testgroups CASCADE;
DROP TABLE IF EXISTS testruns CASCADE; DROP TABLE IF EXISTS testruns CASCADE;
DROP TABLE IF EXISTS testgroupruns CASCADE;
DROP TABLE IF EXISTS problems CASCADE; DROP TABLE IF EXISTS problems CASCADE;
DROP TABLE IF EXISTS contests CASCADE; DROP TABLE IF EXISTS contests CASCADE;
DROP TABLE IF EXISTS tasks CASCADE; DROP TABLE IF EXISTS tasks CASCADE;