Exemple #1
0
/**
 * @api {delete} /topics/{id} Deletes a topic
 * @apiName DeleteTopic
 * @apiGroup Topics
 *
 * @apiParam {Number} id The id of the topic to delete
 */
func (tc *TopicsController) Delete(c *echo.Context) error {
	resp := response.New(c)
	defer resp.Render()

	// Getting Params
	id, err := strconv.ParseInt(c.Param("id"), 10, 64)
	if err != nil {
		resp.SetResponse(http.StatusBadRequest, nil)
		return nil
	}

	// Deleting topic
	topic := new(models.Topic)
	topic.Id = id
	err = topic.Delete()
	if err != nil {
		resp.SetResponse(http.StatusNotFound, nil)
		return nil
	}

	resp.SetResponse(http.StatusOK, nil)
	return nil
}