Ejemplo n.º 1
0
// HandlerAdd represents an API handler to add a new article
func HandlerAdd(req *router.Request) {
	params, ok := req.Params.(*HandlerAddParams)
	if !ok {
		req.Error(apierror.NewServerError("Couldn't cast params"))
	}

	a := &Article{
		Title:       params.Title,
		Subtitle:    params.Subtitle,
		Content:     params.Content,
		Description: params.Description,
		IsDeleted:   false,
		IsPublished: false,
	}

	if err := a.Save(); err != nil {
		req.Error(err)
	}

	req.Created(a)
}