func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	content, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return err
	}
	glog.V(2).Infof("date create: %s", string(content))
	var f booking_date.Date
	err = json.Unmarshal(content, &f)
	if err != nil {
		return err
	}
	if len(f.UserIds) == 0 {
		return fmt.Errorf("at least one user required")
	}
	obj, err := h.create(&f)
	if err != nil {
		return err
	}
	err = h.updateDateUser(obj.Id, f.UserIds)
	if err != nil {
		return err
	}
	go h.protocol(request, "date/create", obj)
	j := json_handler.New(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
	}
	glog.V(2).Infof("shooting book: %s", string(content))
	var f booking_shooting.Shooting
	err = json.Unmarshal(content, &f)
	if err != nil {
		return err
	}
	if len(f.UserIds) == 0 {
		return fmt.Errorf("at least one user required")
	}
	obj, err := h.update(&f)
	if err != nil {
		return err
	}
	glog.V(2).Infof("update users %v of shooting %d", f.UserIds, obj.Id)
	err = h.updateShootingUser(obj.Id, f.UserIds)
	if err != nil {
		return err
	}
	go h.protocol(request, "shooting/update", obj)
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	err := request.ParseForm()
	if err != nil {
		return err
	}
	values := request.Form["Id"]
	if len(values) != 1 {
		return fmt.Errorf("param Id missing")
	}
	dateId, err := strconv.Atoi(values[0])
	if err != nil {
		return err
	}
	glog.V(2).Infof("get date with user %d", dateId)
	obj, err := h.getDate(int64(dateId))
	if err != nil {
		return err
	}
	userIds, err := h.getUserIdsForDate(int64(dateId))
	if err != nil {
		return err
	}
	if len(userIds) > 0 {
		obj.UserIds = userIds
	}
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
예제 #4
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
}
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) {
		glog.V(2).Infof("isParticipant = true")
		model, err := h.getByToken(authentication.Token)
		if err != nil {
			return err
		}
		if list, err = h.findByModelId(model.Id); err != nil {
			glog.V(2).Infof("list shootings failed: %v", err)
			return err
		}
	} else {
		glog.V(2).Infof("isParticipant = false")
		if list, err = h.list(); err != nil {
			glog.V(2).Infof("list shootings failed: %v", err)
			return err
		}
	}
	glog.V(2).Infof("found %d shootings", len(list))
	j := json_handler.New(list)
	j.ServeHTTP(responseWriter, request)
	return nil
}
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	err := request.ParseForm()
	if err != nil {
		return err
	}
	values := request.Form["Id"]
	if len(values) != 1 {
		return fmt.Errorf("param Id missing")
	}
	id, err := strconv.Atoi(values[0])
	if err != nil {
		return err
	}
	glog.V(2).Infof("get shooting with users for id: %d", id)
	obj, err := h.get(int64(id))
	if err != nil {
		return err
	}
	userIds, err := h.getUserIdForShooting(int64(id))
	if err != nil {
		return err
	}
	obj.UserIds = userIds
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
예제 #7
0
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	glog.V(2).Infof("list config")
	var err error
	var list []booking_config.Config
	if list, err = h.list(); err != nil {
		glog.V(2).Infof("list configs failed: %v", err)
		return err
	}
	glog.V(2).Infof("found %d configs", len(list))
	j := json_handler.New(list)
	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
	}
	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 {
	glog.V(2).Infof("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.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
}
예제 #11
0
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	glog.V(2).Infof("get config")
	key, err := server_idparser.ParseKeyFormRequest(request)
	if err != nil {
		return err
	}
	glog.V(2).Infof("get config %s", key)
	obj, err := h.get(key)
	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 {
	glog.V(2).Infof("delete config")
	key, err := server_idparser.ParseKeyFormRequest(request)
	if err != nil {
		return err
	}
	obj, err := h.delete(key)
	if err != nil {
		return err
	}
	go h.protocol(request, "config/delete", obj)
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
예제 #13
0
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	glog.V(2).Infof("list user")
	var err error
	var list []booking_user.User
	if list, err = h.list(); err != nil {
		glog.V(2).Infof("list users failed: %v", err)
		return err
	}

	list = removePassword(list)

	glog.V(2).Infof("found %d users", len(list))
	j := json_handler.New(list)
	j.ServeHTTP(responseWriter, request)
	return nil
}
예제 #14
0
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	var err error
	var list []booking_model.Model
	glog.V(2).Infof("model list")
	err = request.ParseForm()
	if err != nil {
		return err
	}
	if list, err = h.list(); err != nil {
		glog.V(2).Infof("list models failed: %v", err)
		return err
	}
	glog.V(2).Infof("found %d models", len(list))
	j := json_handler.New(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
	}
	glog.V(2).Infof("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.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}
예제 #16
0
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	content, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return err
	}
	glog.V(2).Infof("model update: %s", string(content))
	var f booking_model.Model
	err = json.Unmarshal(content, &f)
	if err != nil {
		return err
	}
	obj, err := h.update(&f)
	if err != nil {
		return err
	}
	go h.protocol(request, "model/update", 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
}
func (h *handler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error {
	content, err := ioutil.ReadAll(request.Body)
	if err != nil {
		return err
	}
	glog.V(2).Infof("add user to shooting %s", string(content))
	var f booking_shooting_user.ShootingUser
	err = json.Unmarshal(content, &f)
	if err != nil {
		return err
	}
	obj, err := h.addUserToShooting(&f)
	if err != nil {
		return err
	}
	go h.protocol(request, "add_user_to_shooting", obj)
	j := json_handler.New(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
	}
	glog.V(2).Infof("remove user from date %s", string(content))
	var f booking_date_user.DateUser
	err = json.Unmarshal(content, &f)
	if err != nil {
		return err
	}
	obj, err := h.removeUserToDate(&f)
	if err != nil {
		return err
	}
	go h.protocol(request, "remove_user_from_date", obj)
	j := json_handler.New(obj)
	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
	}
	glog.V(2).Infof("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.Valid && shooting.ModelId.Int64 != model.Id {
			glog.V(2).Infof("permission %d != %d", f.ModelId, model.Id)
			return fmt.Errorf("permission denied")
		}
	}
	obj, err := h.update(&f)
	if err != nil {
		return err
	}
	go h.protocol(request, "shooting/book", obj)
	j := json_handler.New(obj)
	j.ServeHTTP(responseWriter, request)
	return nil
}