37 lines
658 B
Go
37 lines
658 B
Go
package models
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type Exam struct {
|
|
Meta
|
|
|
|
SessionID string
|
|
Participant *Participant
|
|
Quizzes []*Quiz
|
|
}
|
|
|
|
func (e *Exam) String() string {
|
|
return fmt.Sprintf("Exam ID %v with %v quizzes.", e.ID, len(e.Quizzes))
|
|
}
|
|
|
|
func (e *Exam) GetHash() string {
|
|
qHashes := ""
|
|
for _, q := range e.Quizzes {
|
|
qHashes += q.GetHash()
|
|
}
|
|
return fmt.Sprintf("%x", sha256.Sum256([]byte(strings.Join([]string{e.Participant.GetHash(), qHashes}, ""))))
|
|
}
|
|
|
|
func (e *Exam) Marshal() ([]byte, error) {
|
|
return json.Marshal(e)
|
|
|
|
}
|
|
|
|
func (e *Exam) Unmarshal(data []byte) error {
|
|
return json.Unmarshal(data, e)
|
|
}
|