Esempio n. 1
0
// list articles
//
//  in  : *ArticleListOption
//  out : {
//          "articles":[]*Article,
//          "pager":*utils.Pager
//        }
//
func (_ *ArticleApi) List(v interface{}) *Res {
	opt, ok := v.(*ArticleListOption)
	if !ok {
		return Fail(paramTypeError(new(ArticleListOption)))
	}
	opt = prepareArticleListOption(opt)

	if opt.Status != "" {
		articles, err := model.ListStatusArticle(opt.Status, opt.Page, opt.Size, opt.Order)
		if err != nil {
			return Fail(err)
		}
		count, err := model.CountStatusArticle(opt.Status)
		if err != nil {
			return Fail(err)
		}
		return Success(map[string]interface{}{
			"articles": articles,
			"pager":    utils.CreatePager(opt.Page, opt.Size, count),
		})
	}

	articles, err := model.ListGeneralArticle(opt.Page, opt.Size, opt.Order)
	if err != nil {
		return Fail(err)
	}
	count, err := model.CountGeneralArticle()
	if err != nil {
		return Fail(err)
	}
	return Success(map[string]interface{}{
		"articles": articles,
		"pager":    utils.CreatePager(opt.Page, opt.Size, count),
	})
}
Esempio n. 2
0
// list media data
//
//  in  : *MediaListOption
//  out : {
//          "media":[]*Media,
//          "pager":*utils.Pager
//        }
//
func (_ *MediaApi) List(v interface{}) *Res {
	opt, ok := v.(*MediaListOption)
	if !ok {
		return Fail(paramTypeError(opt))
	}
	media, err := model.ListMedia(opt.Page, opt.Size)
	if err != nil {
		return Fail(err)
	}
	count, err := model.CountMedia()
	if err != nil {
		return Fail(err)
	}
	return Success(map[string]interface{}{
		"media": media,
		"pager": utils.CreatePager(opt.Page, opt.Size, count),
	})
}