Esempio n. 1
0
func (a *ArticleApi) List(args util.MapData) (db.DataSet, error) {
	nick := args.GetString("nick")
	page := args.GetInt("page")

	q := db.NewQueryBuilder("articles").
		Page(page, 20).
		Order("id desc").
		Select("cid,title,description,status,created_at")

	if nick != "" {
		u, err := user.NewUserModel().GetByNickAllField(nick)
		if err != nil {
			return nil, err
		}
		if u.Empty() {
			return nil, gos.DoError("没有找到相应的记录", nick)
		}
		q.Where("user_id=?", u.GetInt64("id"))
	}

	ds, err := q.Query()
	return ds.Bytes2String(), err
}