probo/models/exam.go
2023-12-05 22:11:08 +01:00

32 lines
582 B
Go

package models
import (
"crypto/sha256"
"encoding/json"
"fmt"
"strings"
)
type Exam struct {
Meta
Name 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 {
return fmt.Sprintf("%x", sha256.Sum256([]byte(strings.Join([]string{e.Name, e.Participant.GetHash()}, ""))))
}
func (e *Exam) Marshal() ([]byte, error) {
return json.Marshal(e)
}
func (e *Exam) Unmarshal(data []byte) error {
return json.Unmarshal(data, e)
}