feat: test add
This commit is contained in:
parent
012c76941d
commit
a5e464d4a7
2 changed files with 38 additions and 10 deletions
|
@ -12,7 +12,12 @@ const (
|
||||||
type Testgroup struct {
|
type Testgroup struct {
|
||||||
Id *int32 `db:"id"`
|
Id *int32 `db:"id"`
|
||||||
ProblemId *int32 `db:"problem_id"`
|
ProblemId *int32 `db:"problem_id"`
|
||||||
TestingStrategy *int32 `db:"testing_strategy"`
|
TestingStrategy *TestingStrategy `db:"testing_strategy"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TestgroupData struct {
|
||||||
|
Ts TestingStrategy
|
||||||
|
TestAmount int32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (TestingStrategy ts) Valid() error {
|
func (TestingStrategy ts) Valid() error {
|
||||||
|
|
|
@ -24,15 +24,15 @@ func NewProblemStorage(db *sqlx.DB, logger *zap.Logger) *ProblemStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (storage *ProblemStorage) CreateProblem(ctx context.Context, problem *models.Problem) (int32, error) {
|
func (storage *ProblemStorage) CreateProblem(ctx context.Context, problem *models.Problem, testgroupData []models.TestGroupData, testchan <-chan []byte) (int32, error) {
|
||||||
query := storage.db.Rebind(`
|
tx,err := storage.db.Begin()
|
||||||
|
query := tx.Rebind(`
|
||||||
INSERT INTO problems
|
INSERT INTO problems
|
||||||
(name,description,time_limit,memory_limit)
|
(name,description,time_limit,memory_limit)
|
||||||
VALUES (?, ?, ?, ?)
|
VALUES (?, ?, ?, ?)
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`)
|
`)
|
||||||
|
rows, err := tx.QueryxContext(
|
||||||
rows, err := storage.db.QueryxContext(
|
|
||||||
ctx,
|
ctx,
|
||||||
query,
|
query,
|
||||||
problem.Name,
|
problem.Name,
|
||||||
|
@ -40,9 +40,32 @@ RETURNING id
|
||||||
problem.TimeLimit,
|
problem.TimeLimit,
|
||||||
problem.MemoryLimit
|
problem.MemoryLimit
|
||||||
)
|
)
|
||||||
|
for _,tgd := testGroupData {
|
||||||
|
query := tx.Rebind(`
|
||||||
|
INSERT INTO testgroups
|
||||||
|
(problem_id,testing_strategy)
|
||||||
|
VALUES ((select last_value from problems_id_seq),?)
|
||||||
|
RETURNING id
|
||||||
|
`)
|
||||||
|
rows, err := tx.QueryxContext(ctx, query, tgd.Ts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, storage.HandlePgErr(err)
|
return 0, storage.HandlePgErr(err)
|
||||||
}
|
}
|
||||||
|
for i:=0;i<tgd.testAmount;i++ {
|
||||||
|
query := tx.Rebind(`
|
||||||
|
INSERT INTO tests
|
||||||
|
(testgroup_id)
|
||||||
|
VALUES ((select last_value from testgroups_id_seq))
|
||||||
|
RETURNING id
|
||||||
|
`)
|
||||||
|
rows, err := tx.QueryxContext(ctx, query, tgd.Ts)
|
||||||
|
if err != nil {
|
||||||
|
return 0, storage.HandlePgErr(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = tx.Commit()
|
||||||
|
//add test saving
|
||||||
|
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
var id int32
|
var id int32
|
||||||
|
|
Loading…
Reference in a new issue