Skip to content

Commit

Permalink
handle not logged users in article usecases
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu Jacquot committed Aug 5, 2018
1 parent 3a4daff commit e3cbcb8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion implem/gin.server/article.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (rH RouterHandler) articlePut(c *gin.Context) {
func (rH RouterHandler) articleGet(c *gin.Context) {
log := rH.log(rH.MethodAndPath(c))

user, article, err := rH.ucHandler.ArticleGet(rH.getUserName(c), c.Param("slug")) // todo add requesting username here
user, article, err := rH.ucHandler.ArticleGet(rH.getUserName(c), c.Param("slug"))
if err != nil {
log(err)
c.Status(http.StatusUnprocessableEntity)
Expand Down
10 changes: 7 additions & 3 deletions uc/article.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ func (i interactor) ArticlePut(username string, slug string, reqArticle domain.A
}

func (i interactor) ArticleGet(username, slug string) (*domain.User, *domain.Article, error) {
user, err := i.userRW.GetByName(username)
if err != nil {
return nil, nil, err
var user *domain.User
if username != "" {
var errGet error
user, errGet = i.userRW.GetByName(username)
if errGet != nil {
return nil, nil, errGet
}
}

article, err := i.articleRW.GetBySlug(slug)
Expand Down
10 changes: 7 additions & 3 deletions uc/articlesFeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ func (i interactor) ArticlesFeed(username string, limit, offset int) (*domain.Us
return nil, domain.ArticleCollection{}, 0, nil
}

user, err := i.userRW.GetByName(username)
if err != nil {
return nil, nil, 0, err
var user *domain.User
if username != "" {
var errGet error
user, errGet = i.userRW.GetByName(username)
if errGet != nil {
return nil, nil, 0, errGet
}
}
articles, err := i.articleRW.GetByAuthorsNameOrderedByMostRecentAsc(user.FollowIDs)
if err != nil {
Expand Down
10 changes: 7 additions & 3 deletions uc/articlesRecent.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ func (i interactor) GetArticles(username string, limit, offset int, filters []do
return nil, nil, 0, err
}

user, err := i.userRW.GetByName(username)
if err != nil {
return nil, nil, 0, err
var user *domain.User
if username != "" {
var errGet error
user, errGet = i.userRW.GetByName(username)
if errGet != nil {
return nil, nil, 0, errGet
}
}

return user, domain.ArticleCollection(articles).ApplyLimitAndOffset(limit, offset), len(articles), nil
Expand Down

0 comments on commit e3cbcb8

Please sign in to comment.