Exemple #1
0
// DeleteTag calls the Delete method from Contacts via RPC (Tag client). Returns results via jsonapi.
func DeleteTag(w http.ResponseWriter, r *http.Request) {
	TID, err := strconv.Atoi(router.Context(r).Param("tag_id"))
	if err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"tag_id": "not integer"}, http.StatusBadRequest)
		return
	}
	id, err := strconv.Atoi(router.Context(r).Param("id"))
	if err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"id": "not integer"}, http.StatusBadRequest)
		return
	}

	var (
		contactClient = rpcClient(r, "ContactClient")
		args          = models.TagArgs{GroupID: router.Context(r).Env["GroupID"].(uint)}
		reply         = models.TagReply{}
	)
	args.Tag = new(models.Tag)
	args.Tag.ID = uint(TID)
	args.ContactID = uint(id)
	err = contactClient.Call("Tag.Delete", args, &reply)
	if err != nil {
		Error(w, r, err.Error(), http.StatusInternalServerError)
		return
	}

	Success(w, r, nil, http.StatusNoContent)
}
Exemple #2
0
// CreateTag calls the Create method from Contacts via RPC (Tag client). Returns results via jsonapi.
func CreateTag(w http.ResponseWriter, r *http.Request) {
	var (
		args = models.TagArgs{GroupID: router.Context(r).Env["GroupID"].(uint)}
	)
	args.Tag = new(models.Tag)
	CID, err := strconv.Atoi(router.Context(r).Param("id"))
	if err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"id": "not integer"}, http.StatusBadRequest)
		return
	}
	args.ContactID = uint(CID)

	if err := Request(&views.Tag{Tag: args.Tag}, r); err != nil {
		logs.Debug(err)
		Fail(w, r, map[string]interface{}{"tag": err.Error()}, http.StatusBadRequest)
		return
	}

	var (
		contactClient = rpcClient(r, "ContactClient")
		reply         = models.TagReply{}
	)
	err = contactClient.Call("Tag.Create", args, &reply)
	if err != nil {
		Error(w, r, err.Error(), http.StatusInternalServerError)
		return
	}

	Success(w, r, views.Tag{Tag: reply.Tag}, http.StatusOK)
}