Ejemplo n.º 1
0
// RetrieveTagcollection calls the RetrieveCollection method from Contacts via RPC (Tag client). Returns results via jsonapi.
func RetrieveTagCollection(w http.ResponseWriter, r *http.Request) {
	var (
		contactClient = rpcClient(r, "ContactClient")
		args          = models.TagArgs{GroupID: router.Context(r).Env["GroupID"].(uint)}
		reply         = models.TagReply{}
	)

	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)

	err = contactClient.Call("Tag.RetrieveCollection", args, &reply)
	if err != nil {
		Error(w, r, err.Error(), http.StatusInternalServerError)
		return
	}

	if reply.Tags == nil {
		reply.Tags = make([]models.Tag, 0)
	}

	Success(w, r, views.Tags{Tags: reply.Tags}, http.StatusOK)
}
Ejemplo n.º 2
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)
}
Ejemplo n.º 3
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)
}