Example #1
0
File: main.go Project: cycps/addie
func newXP(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {

	user, err := getUser(r)
	if err != nil {
		w.WriteHeader(401)
		return
	}

	msg := new(protocol.NewXP)
	err = protocol.Unpack(r, &msg)
	if err != nil {
		log.Printf("error unpacking newXP message")
		log.Println(err)
		w.WriteHeader(400)
		return
	}

	log.Printf("Creating xp '%s` for user `%s`", msg.Name, user)

	err = db.CreateDesign(msg.Name, user)
	if err != nil {
		log.Println(err)
		log.Printf("[newXP] error creating design entry db")
		w.WriteHeader(500)
		return
	}

	design_key, err := db.ReadDesignKey(msg.Name, user)
	if err != nil {
		log.Println(err)
		log.Printf("[newXP] error reading design key")
		w.WriteHeader(500)
		return
	}

	//use the default sim settings to begin with
	s := addie.SimSettings{}
	s.Begin = 0
	s.End = 10
	s.MaxStep = 1e-3

	err = db.CreateSimSettings(s, design_key)
	if err != nil {
		log.Println(err)
		log.Println("[newXP] error creating default sim settings")
		w.WriteHeader(500)
		return
	}

	w.WriteHeader(200)
}
Example #2
0
File: main.go Project: cycps/addie
func updateSimSettings(s addie.SimSettings) {

	design_key, err := db.ReadDesignKey(design.Name, user)
	if err != nil {
		log.Println(err)
		log.Printf("[updateSimSettings] error reading design key")
		return
	}

	err = db.UpdateSimSettings(s, design_key)
	if err != nil {
		log.Println("[updateSimSettings] error updating sim settings")
		log.Println(err)
		return
	}

	simSettings = s
}
Example #3
0
File: main.go Project: cycps/addie
func doRead() error {

	dsg, err := db.ReadDesign(design.Name, user)
	if err != nil {
		log.Println(err)
		return fmt.Errorf("Failed to read design")
	}

	design = *dsg

	mls, err := db.ReadUserModels(user)
	if err != nil {
		log.Println(err)
		return fmt.Errorf("failed to read user models")
	}

	userModels = make(map[string]addie.Model)

	for _, v := range mls {
		userModels[v.Name] = v
	}

	design_key, err := db.ReadDesignKey(dsg.Name, user)
	if err != nil {
		log.Println(err)
		return fmt.Errorf("error reading design key")
	}

	ss, err := db.ReadSimSettingsByDesignId(design_key)
	if err != nil {
		log.Println(err)
		return fmt.Errorf("could not read simulation settings")
	}

	simSettings = *ss

	return nil
}