feat: add update score function & update schema
This commit is contained in:
parent
7dad23c066
commit
65a5488726
3 changed files with 32 additions and 21 deletions
|
@ -24,9 +24,18 @@ func NewSolutionStorage(db *sqlx.DB, logger *zap.Logger) *SolutionStorage {
|
|||
}
|
||||
}
|
||||
|
||||
//func updateResult(ctx context.Context, participant_id int32, task_id int32) error {
|
||||
//
|
||||
//}
|
||||
func updateResult(ctx context.Context, participantId int32, taskId int32) error {
|
||||
tx,err := storage.db.Begin()
|
||||
if err != nil {
|
||||
return storage.HandlePgErr(err)
|
||||
}
|
||||
tx.Exec("UPDATE participant_subtask AS ps SET best_score = (SELECT COALESCE(max(score),0) FROM subtaskruns WHERE subtask_id = ps.subtask_id AND solution_id IN (SELECT id FROM solutions WHERE participant_id=ps.participant_id)) WHERE participant_id = 2 AND subtask_id IN (SELECT id FROM subtasks WHERE task_id = 2)",participantId,taskId)
|
||||
tx.Exec("UPDATE participant_task SET best_score = (select max(best_score) from participant_subtask WHERE participant_id = ? AND subtask_id IN (SELECT id FROM subtask WHERE task_id = ?)) WHERE participant_id = ? AND task_id = ?",participantId,taskId,participantId,taskId)
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
return storage.HandlePgErr(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (storage *SolutionStorage) CreateSolution(ctx context.Context, solution *models.Solution) (int32, error) {
|
||||
query := storage.db.Rebind(`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue