コード例 #1
0
ファイル: stations.go プロジェクト: tstranex/carpcomm
func editStationPOST(sdb *db.StationDB, s *pb.Station,
	w http.ResponseWriter, r *http.Request, user userView) {
	if err := r.ParseForm(); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	log.Print(r.Form)

	s.Name = proto.String(r.Form.Get("name"))
	s.Notes = proto.String(r.Form.Get("notes"))
	setOptionalFloat(r.Form.Get("latitude"), &s.Lat)
	setOptionalFloat(r.Form.Get("longitude"), &s.Lng)
	setOptionalFloat(r.Form.Get("elevation"), &s.Elevation)

	if r.Form["has_vhf"] == nil {
		s.Capabilities.VhfLimits = nil
	} else {
		vhf := &pb.AzElLimits{}
		s.Capabilities.VhfLimits = vhf
		setOptionalFloat(r.Form.Get("vhf_min_azimuth"),
			&vhf.MinAzimuthDegrees)
		setOptionalFloat(r.Form.Get("vhf_max_azimuth"),
			&vhf.MaxAzimuthDegrees)
		setOptionalFloat(r.Form.Get("vhf_min_elevation"),
			&vhf.MinElevationDegrees)
		setOptionalFloat(r.Form.Get("vhf_max_elevation"),
			&vhf.MaxElevationDegrees)
	}

	if r.Form["has_uhf"] == nil {
		s.Capabilities.UhfLimits = nil
	} else {
		uhf := &pb.AzElLimits{}
		s.Capabilities.UhfLimits = uhf
		setOptionalFloat(r.Form.Get("uhf_min_azimuth"),
			&uhf.MinAzimuthDegrees)
		setOptionalFloat(r.Form.Get("uhf_max_azimuth"),
			&uhf.MaxAzimuthDegrees)
		setOptionalFloat(r.Form.Get("uhf_min_elevation"),
			&uhf.MinElevationDegrees)
		setOptionalFloat(r.Form.Get("uhf_max_elevation"),
			&uhf.MaxElevationDegrees)
	}

	if r.Form["scheduler_enabled"] == nil {
		s.SchedulerEnabled = nil
	} else {
		s.SchedulerEnabled = proto.Bool(true)
	}

	err := sdb.Store(s)
	if err != nil {
		log.Printf("Station DB store error: %s", err.Error())
		http.Error(w, "", http.StatusInternalServerError)
		return
	}

	redirect := stationUrl("/station", *s.Id)
	http.Redirect(w, r, redirect, http.StatusFound)
}