Skip to content

Commit

Permalink
Replaced MaybeFilter with filterOpt
Browse files Browse the repository at this point in the history
* it was introduced in Slick 3.3.X, no need for MaybeFiler anymore
  • Loading branch information
Dasiu committed Nov 6, 2019
1 parent 8163139 commit 783132c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
23 changes: 13 additions & 10 deletions app/articles/repositories/ArticleRepo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,19 @@ class ArticleRepo(userRepo: UserRepo,
.joinLeft(favoriteAssociation.query)
.on((tables, favoritedAssociationTable) => tables._1._1._1.id === favoritedAssociationTable.favoritedId)

MaybeFilter(joins)
.filter(pageRequest.author)(authorUsername => tables => getUserTable(tables).username === authorUsername)
.filter(pageRequest.tag)(tagValue => tables => getTagTable(tables).map(_.name === tagValue))
.filter(pageRequest.favorited)(favoritedUsername => tables => {
getFavoritedAssociationTable(tables).map(favoritedAssociationTable => {
val userTable = getUserTable(tables)
favoritedAssociationTable.userId === userTable.id && userTable.username === favoritedUsername
})
})
.query
joins
.filterOpt(pageRequest.author){
case (tables, authorUsername) => getUserTable(tables).username === authorUsername
}
.filterOpt(pageRequest.tag){
case (tables, tag) => getTagTable(tables).map(_.name === tag)
}
.filterOpt(pageRequest.favorited){
case (tables, favoritedUsername) => getFavoritedAssociationTable(tables).map(favoritedAssociationTable => {
val userTable = getUserTable(tables)
favoritedAssociationTable.userId === userTable.id && userTable.username === favoritedUsername
})
}
}

private def getArticleTab(tables: ((((ArticleTable, UserTable), Rep[Option[ArticleTagAssociationTable]]), Rep[Option[TagTable]]), Rep[Option[FavoriteAssociationTable]])) = {
Expand Down
12 changes: 0 additions & 12 deletions app/commons/repositories/MaybeFilter.scala

This file was deleted.

0 comments on commit 783132c

Please sign in to comment.