Пример #1
0
func init() {
	var err error

	con := app.GetDBConnection()
	if err != nil {
		log.Fatal(err)
	}

	ch := card.GetHandler()
	rh := result.GetHandler()
	h := SpacedRepetitionLearner{con, rh, ch}

	err = h.createSRTable()
	if err != nil {
		log.Fatal(err)
	}

	srLearner = &h
}
Пример #2
0
// SaveResult Saves the result of a recall.
func SaveResult(w rest.ResponseWriter, r *rest.Request) {
	res, err := result.New()
	if err != nil {
		log.Printf("SaveResult: Failed to save result: %s", err)
		rest.Error(w, "Failed to save result", 500)
		return
	}

	decoder := json.NewDecoder(r.Body)
	err = decoder.Decode(&res)
	if err != nil {
		log.Printf("SaveResult: Failed to decode request body: %s", err)
		rest.Error(w, "Failed to decode request body", 500)
		return
	}

	card, err := card.GetHandler().RetrieveCard(res.Cid)
	if err != nil || card == nil {
		log.Printf("SaveResult: Failed to retrieve card with cid: %s. %s", res.Cid, err)
		rest.Error(w, "Failed to save result", 500)
		return
	}

	if err := result.GetHandler().SaveResult(*res); err != nil {
		log.Printf("SaveResult: Failed to save result: %s", err)
		rest.Error(w, "Failed to save result", 500)
		return
	}

	if err := learning.SaveLearnOutcome(*res); err != nil {
		log.Printf("SaveResult: Failed to save result: %s", err)
		rest.Error(w, "Failed to save result", 500)
	}

	log.Println("SaveResult: Result save was successful")
	w.WriteJson(res)
}