예제 #1
0
파일: article.go 프로젝트: RavenB/readeef
func (sa *ScoredArticle) Scores() (asc content.ArticleScores) {
	asc = sa.Repo().ArticleScores()
	if sa.HasErr() {
		asc.Err(sa.Err())
		return
	}

	id := sa.Data().Id
	if id == 0 {
		sa.Err(content.NewValidationError(errors.New("Invalid article id")))
		return
	}

	sa.logger.Infof("Getting article '%d' scores\n", id)

	var i data.ArticleScores
	if err := sa.db.Get(&i, sa.db.SQL("get_article_scores"), id); err != nil {
		if err == sql.ErrNoRows {
			err = content.ErrNoContent
		}
		asc.Err(err)
	}

	i.ArticleId = id
	asc.Data(i)

	return
}
예제 #2
0
파일: article.go 프로젝트: urandom/readeef
func (a *Article) Scores() (as content.ArticleScores) {
	as = a.Repo().ArticleScores()
	if a.HasErr() {
		as.Err(a.Err())
		return
	}

	id := a.Data().Id
	if id == 0 {
		a.Err(content.NewValidationError(errors.New("Invalid article id")))
		return
	}

	a.logger.Infof("Getting article '%d' scores\n", id)

	var i data.ArticleScores
	if err := a.db.Get(&i, a.db.SQL().Article.GetScores, id); err != nil {
		if err == sql.ErrNoRows {
			err = content.ErrNoContent
		}
		as.Err(err)
	}

	i.ArticleId = id
	as.Data(i)

	return
}