probo/pkg/models/response.go

37 lines
706 B
Go
Raw Normal View History

2023-12-11 09:32:50 +01:00
package models
import (
"encoding/json"
"fmt"
)
2024-05-12 10:15:48 +02:00
type ParticipantAnswer struct {
Quiz *Quiz `json:"question"`
Answer *Answer `json:"answer"`
Correct bool `json:"correct"`
}
2023-12-11 09:32:50 +01:00
type Response struct {
Meta
2023-12-17 18:56:20 +01:00
2024-05-12 10:15:48 +02:00
SessionID string `json:"session_id"`
Answers []*ParticipantAnswer `json:"answers"`
2023-12-11 09:32:50 +01:00
}
func (r *Response) String() string {
2024-05-12 10:15:48 +02:00
return fmt.Sprintf("Questions/Answers: %v", r.Answers)
2023-12-11 09:32:50 +01:00
}
func (r *Response) GetHash() string {
2023-12-17 18:56:20 +01:00
// return fmt.Sprintf("%x", sha256.Sum256([]byte(r.QuestionID+r.AnswerID)))
return ""
2023-12-11 09:32:50 +01:00
}
func (r *Response) Marshal() ([]byte, error) {
return json.Marshal(r)
}
func (r *Response) Unmarshal(data []byte) error {
return json.Unmarshal(data, r)
}