func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	authentication, err := h.httpRequestToAuthentication(request)
	if err != nil {
		return err
	}
	var list *[]booking_shooting.Shooting
	if h.isParticipant(authentication) {
		model, err := h.getByToken(authentication.Token)
		if err != nil {
			return err
		}
		if list, err = h.findByModelId(model.Id); err != nil {
			logger.Debugf("list shootings failed: %v", err)
			return err
		}
	} else {
		if list, err = h.list(); err != nil {
			logger.Debugf("list shootings failed: %v", err)
			return err
		}
	}
	logger.Debugf("found %d shootings", len(*list))
	j := json_handler.NewJsonHandler(*list)
	j.ServeHTTP(responseWriter, request)
	return nil
}
예제 #2
0
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	var err error
	var list *[]booking_date.Date
	if list, err = h.list(); err != nil {
		logger.Debugf("list dates failed: %v", err)
		return err
	}
	logger.Debugf("found %d dates", len(*list))
	j := json_handler.NewJsonHandler(*list)
	j.ServeHTTP(responseWriter, request)
	return nil
}
예제 #3
0
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	id, err := idparser.ParseIdFormRequest(request)
	if err != nil {
		return err
	}
	obj, err := h.get(id)
	if err != nil {
		return err
	}
	j := json_handler.NewJsonHandler(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
예제 #4
0
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	logger.Debug("get user")
	value, err := idparser.ParseIdFormRequest(request)
	if err != nil {
		return err
	}
	obj, err := h.get(value)
	if err != nil {
		return err
	}
	j := json_handler.NewJsonHandler(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	logger.Debug("get current model")
	authentication, err := h.httpRequestToAuthentication(request)
	if err != nil {
		return err
	}
	obj, err := h.getByToken(authentication.Token)
	if err != nil {
		return err
	}
	j := json_handler.NewJsonHandler(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
예제 #6
0
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	var err error
	var list *[]booking_model.Model
	logger.Debug("model list")
	err = request.ParseForm()
	if err != nil {
		return err
	}
	if list, err = h.list(); err != nil {
		logger.Debugf("list models failed: %v", err)
		return err
	}
	logger.Debugf("found %d models", len(*list))
	j := json_handler.NewJsonHandler(*list)
	j.ServeHTTP(responseWriter, request)
	return nil
}
func (h *handler) serveHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	content, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return err
	}
	var f stats_entry.Entry
	err = json.Unmarshal(content, &f)
	if err != nil {
		return err
	}
	obj, err := h.service.Create(&f)
	if err != nil {
		return err
	}
	j := json_handler.NewJsonHandler(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	content, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return err
	}
	logger.Debugf("verifylogin authentication: %v", string(content))
	var f booking_authentication.Authentication
	err = json.Unmarshal(content, &f)
	if err != nil {
		return err
	}
	obj, err := h.verifyLogin(&f)
	if err != nil {
		return err
	}
	j := json_handler.NewJsonHandler(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	content, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return err
	}
	logger.Debugf("shooting create: %s", string(content))
	var f booking_shooting.Shooting
	err = json.Unmarshal(content, &f)
	if err != nil {
		return err
	}
	obj, err := h.create(&f)
	if err != nil {
		return err
	}
	j := json_handler.NewJsonHandler(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
func (h *handler) serveHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	var err error
	var limit int
	if limit, err = strconv.Atoi(request.FormValue("limit")); err != nil {
		limit = -1
	}
	var list []stats_entry.Entry
	if limit > 0 {
		if list, err = h.service.ListLimited(limit); err != nil {
			return err
		}
	} else {
		if list, err = h.service.List(); err != nil {
			return err
		}
	}

	sort.Sort(stats_entry.EntryByTimestampDesc(list))

	j := json_handler.NewJsonHandler(list)
	j.ServeHTTP(responseWriter, request)
	return nil
}
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	authentication, err := h.httpRequestToAuthentication(request)
	if err != nil {
		return err
	}
	model, err := h.getByToken(authentication.Token)
	if err != nil {
		return err
	}
	content, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return err
	}
	logger.Debugf("shooting book: %s", string(content))
	var f booking_shooting.Shooting
	err = json.Unmarshal(content, &f)
	if err != nil {
		return err
	}
	if h.isParticipant(authentication) {
		shooting, err := h.get(f.Id)
		if err != nil {
			return err
		}
		if shooting.ModelId != model.Id {
			logger.Debugf("permission %d != %d", f.ModelId, model.Id)
			return fmt.Errorf("permission denied")
		}
	}
	obj, err := h.update(&f)
	if err != nil {
		return err
	}
	j := json_handler.NewJsonHandler(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}