feat: add rejudge function to storage & update schema
This commit is contained in:
parent
80df2e2820
commit
48ad3a5461
3 changed files with 41 additions and 3 deletions
|
@ -9,5 +9,6 @@ type Solution struct {
|
|||
LanguageId *int32 `db:"language_id"`
|
||||
SolutionHash *string `db:"solution_hash"`
|
||||
Result *int32 `db:"result"`
|
||||
Score *int32 `db:"score"`
|
||||
CreatedAt *time.Time `db:"created_at"`
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
query := storage.db.Rebind(`
|
||||
INSERT INTO solutions
|
||||
|
@ -65,6 +69,19 @@ func (storage *SolutionStorage) ReadSolutionById(ctx context.Context, id int32)
|
|||
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 {
|
||||
query := storage.db.Rebind("DELETE FROM solutions WHERE id=?")
|
||||
_, err := storage.db.ExecContext(ctx, query, id)
|
||||
|
|
|
@ -126,6 +126,7 @@ CREATE TABLE IF NOT EXISTS solutions
|
|||
language_id INT REFERENCES languages ON DELETE CASCADE,
|
||||
solution_hash CHAR(128) NOT NULL,
|
||||
result INT NOT NULL,
|
||||
score INT NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
|
||||
PRIMARY KEY (id)
|
||||
|
@ -152,19 +153,37 @@ CREATE INDEX ON tests USING BTREE (testgroup_id);
|
|||
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS testruns
|
||||
CREATE TABLE IF NOT EXISTS testgroupruns
|
||||
(
|
||||
id serial NOT NULL,
|
||||
test_id INT REFERENCES tests ON DELETE CASCADE,
|
||||
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
|
||||
(
|
||||
id serial NOT NULL,
|
||||
test_id INT REFERENCES tests ON DELETE CASCADE,
|
||||
--solution_id INT REFERENCES solutions ON DELETE CASCADE,
|
||||
testgrouprun_id INT REFERENCES testgroupruns ON DELETE CASCADE,
|
||||
result INT NOT NULL,
|
||||
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE INDEX ON testruns USING BTREE (id);
|
||||
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 testgroups CASCADE;
|
||||
DROP TABLE IF EXISTS testruns CASCADE;
|
||||
DROP TABLE IF EXISTS testgroupruns CASCADE;
|
||||
DROP TABLE IF EXISTS problems CASCADE;
|
||||
DROP TABLE IF EXISTS contests CASCADE;
|
||||
DROP TABLE IF EXISTS tasks CASCADE;
|
||||
|
|
Loading…
Reference in a new issue