probo/pkg/models/session.go

34 lines
655 B
Go
Raw Normal View History

2023-12-11 09:32:50 +01:00
package models
2023-12-12 09:21:55 +01:00
import (
"crypto/sha256"
"encoding/json"
"fmt"
)
type Session struct {
Meta
2024-05-12 10:15:48 +02:00
Title string `json:"title"`
Description string `json:"description"`
Quizzes map[string]*Quiz `json:"quizzes"`
Answers map[string]*Answer `json:"answers"`
Exams map[string]*Exam `json:"exams"`
2023-12-12 09:21:55 +01:00
}
func (s *Session) String() string {
2024-04-22 14:24:29 +02:00
return s.Title
2023-12-12 09:21:55 +01:00
}
func (s *Session) GetHash() string {
2024-04-22 14:24:29 +02:00
return fmt.Sprintf("%x", sha256.Sum256([]byte(s.Title)))
2023-12-12 09:21:55 +01:00
}
func (s *Session) Marshal() ([]byte, error) {
return json.Marshal(s)
}
func (s *Session) Unmarshal(data []byte) error {
return json.Unmarshal(data, s)
}