Exemple #1
0
// HandlerList represents a API handler to get a list of articles
func HandlerList(req *router.Request) {
	arts := []*Article{}

	if err := Query().Find(defaultSearch).Sort("-createdAt").All(&arts); err != nil {
		req.Error(err)
		return
	}

	req.Ok(NewPayloadFromModels(arts))
}
Exemple #2
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)
}