Exemplo n.º 1
0
Arquivo: user.go Projeto: ngthorg/grox
func (this *UserCtrl) Delete(w http.ResponseWriter, r *http.Request) {
	if err := this.userStore.Delete(xhttp.GetContext(r).Params.ByName("id")); err != nil {
		xhttp.ResponseJson(w, 500, M{
			"error": err.Error(),
		})
		return
	}
	xhttp.ResponseJson(w, 200, M{"message": "deleted"})
}
Exemplo n.º 2
0
Arquivo: user.go Projeto: ngthorg/grox
func (this *UserCtrl) List(w http.ResponseWriter, r *http.Request) {
	users, err := this.userStore.List()
	if err != nil {
		xhttp.ResponseJson(w, 500, M{
			"error": err.Error(),
		})
		return
	}
	xhttp.ResponseJson(w, 200, users)
}
Exemplo n.º 3
0
Arquivo: user.go Projeto: ngthorg/grox
func (this *UserCtrl) Get(w http.ResponseWriter, r *http.Request) {
	user, err := this.userStore.Get(xhttp.GetContext(r).Params.ByName("id"))
	if err != nil {
		xhttp.ResponseJson(w, 500, M{
			"error": err.Error(),
		})
		return
	}
	xhttp.ResponseJson(w, 200, user)
}
Exemplo n.º 4
0
func (this *StoryHandler) Create(w http.ResponseWriter, r *http.Request) {
	var story domain.Story
	if err := xhttp.BindJSON(r, &story); err != nil {
		xhttp.ResponseJson(w, 500, map[string]interface{}{
			"message": err.Error(),
		})
		return
	}
	xhttp.ResponseJson(w, 200, map[string]interface{}{
		"message": "ok",
	})
}
Exemplo n.º 5
0
func (this *StoryHandler) Get(w http.ResponseWriter, r *http.Request) {
	ctx := xhttp.GetContext(r)
	id := ctx.Params.ByName("id")
	xhttp.ResponseJson(w, 200, map[string]interface{}{
		"id": id,
	})
}
Exemplo n.º 6
0
Arquivo: user.go Projeto: ngthorg/grox
func (this *UserCtrl) Create(w http.ResponseWriter, r *http.Request) {
	var user = domain.User{}

	if err := xhttp.BindJSON(r, &user); err != nil {
		xhttp.ResponseJson(w, 500, M{
			"error": err.Error(),
		})
		return
	}

	if err := this.userStore.Create(&user); err != nil {
		xhttp.ResponseJson(w, 200, M{
			"error": err.Error(),
		})
		return
	}
	xhttp.ResponseJson(w, 200, user)

}
Exemplo n.º 7
0
Arquivo: user.go Projeto: ngthorg/grox
func (this *UserCtrl) Update(w http.ResponseWriter, r *http.Request) {
	type updateUserData struct {
		Name string `json:"name",gorethink:"name"`
	}
	var data updateUserData
	if err := xhttp.BindJSON(r, &data); err != nil {
		xhttp.ResponseJson(w, 500, M{
			"error": err.Error(),
		})
		return
	}

	if err := this.userStore.Update(xhttp.GetContext(r).Params.ByName("id"), M{"name": data.Name}); err != nil {
		xhttp.ResponseJson(w, 500, M{
			"error": err.Error(),
		})
		return
	}
	xhttp.ResponseJson(w, 200, M{"message": "updated"})
}