package storage import ( "context" "errors" "git.sch9.ru/new_gate/ms-auth/internal/lib" "git.sch9.ru/new_gate/ms-auth/internal/models" "github.com/jackc/pgerrcode" "github.com/jackc/pgx/v5/pgconn" "github.com/jmoiron/sqlx" "go.uber.org/zap" "time" ) type ProblemStorage struct { db *sqlx.DB logger *zap.Logger } func NewProblemStorage(db *sqlx.DB, logger *zap.Logger) *ProblemStorage { return &ProblemStorage{ db: db, logger: logger, } } 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 := tx.QueryxContext( ctx, query, problem.Name, problem.Description, problem.TimeLimit, problem.MemoryLimit ) if err != nil { return 0, storage.HandlePgErr(err) } 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