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 {
|
||||
Id *int32 `db:"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 {
|
||||
|
|
|
@ -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) {
|
||||
query := storage.db.Rebind(`
|
||||
func (storage *ProblemStorage) CreateProblem(ctx context.Context, problem *models.Problem, testgroupData []models.TestGroupData, testchan <-chan []byte) (int32, error) {
|
||||
tx,err := storage.db.Begin()
|
||||
query := tx.Rebind(`
|
||||
INSERT INTO problems
|
||||
(name,description,time_limit,memory_limit)
|
||||
VALUES (?, ?, ?, ?)
|
||||
RETURNING id
|
||||
`)
|
||||
|
||||
rows, err := storage.db.QueryxContext(
|
||||
rows, err := tx.QueryxContext(
|
||||
ctx,
|
||||
query,
|
||||
problem.Name,
|
||||
|
@ -40,9 +40,32 @@ RETURNING id
|
|||
problem.TimeLimit,
|
||||
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 {
|
||||
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()
|
||||
var id int32
|
||||
|
|
Loading…
Reference in a new issue