Ejemplo n.º 1
0
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	glog.V(2).Infof("get model")
	authentication, err := h.httpRequestToAuthentication(request)
	if err != nil {
		return err
	}
	var model *booking_model.Model
	if h.isParticipant(authentication) {
		model, err = h.getByToken(authentication.Token)
		if err != nil {
			return err
		}
	} else {
		id, err := server_idparser.ParseIdFormRequest(request)
		if err != nil {
			return err
		}
		model, err = h.get(int64(id))
		if err != nil {
			return err
		}
	}
	j := json_handler.New(model)
	j.ServeHTTP(responseWriter, request)
	return nil
}
Ejemplo n.º 2
0
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	id, err := server_idparser.ParseIdFormRequest(request)
	if err != nil {
		return err
	}
	glog.V(2).Infof("get %v", id)
	obj, err := h.get(int64(id))
	if err != nil {
		return err
	}
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	id, err := server_idparser.ParseIdFormRequest(request)
	if err != nil {
		return err
	}
	obj, err := h.delete(int64(id))
	if err != nil {
		return err
	}
	go h.protocol(request, "shooting/delete", obj)
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	shootingId, err := server_idparser.ParseIdFormRequest(request)
	if err != nil {
		return err
	}
	var list []booking_user.User
	glog.V(2).Infof("user list")
	err = request.ParseForm()
	if err != nil {
		return err
	}
	if list, err = h.listUserOfShooting(int64(shootingId)); err != nil {
		glog.V(2).Infof("list users failed: %v", err)
		return err
	}
	glog.V(2).Infof("found %d users for shooting %d", len(list), shootingId)
	j := json_handler.New(list)
	j.ServeHTTP(responseWriter, request)
	return nil
}