Skip to content

Commit

Permalink
add for list and extend the dao with function
Browse files Browse the repository at this point in the history
  • Loading branch information
deinelieblings committed Nov 7, 2018
1 parent d4577bd commit 6313b8e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/daos/OauthClientDao.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import slick.driver.JdbcProfile
import slick.lifted.TableQuery
import slick.driver.MySQLDriver.api._
import play.api.db.slick.DatabaseConfigProvider

import slick.jdbc.{GetResult, PositionedParameters, SQLActionBuilder, SetParameter}
import models.converter.OauthClientConverter

/**
* Created by johann on 24.11.16.
Expand Down Expand Up @@ -75,6 +76,8 @@ class MariadbOauthClientDao extends OauthClientDao {
val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)
val oauthClients = TableQuery[OauthClientTableDef]

implicit val getOauthClient = GetResult(r => OauthClientDB(r.nextString, r.nextString, r.nextStringOption, r.nextString))

override def find(id: String) : Future[Option[OauthClient]] = {
dbConfig.db.run(oauthClients.filter(_.id === id).result).map(oauthClient => {
oauthClient.headOption.map(_.toOauthClient)
Expand Down Expand Up @@ -119,4 +122,9 @@ class MariadbOauthClientDao extends OauthClientDao {
case _ => Future.successful(true)
}
}

def list_with_statement(statement : SQLActionBuilder) : Future[List[OauthClient]] = {
var sql_action = statement.as[(OauthClientDB)]
dbConfig.db.run(sql_action).map(OauthClientConverter.buildListFromResult(_))
}
}
15 changes: 15 additions & 0 deletions app/models/converter/OauthClientConverter.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package models.converter

import models.{OauthClient}
import models.database.{OauthClientDB}

object OauthClientConverter {

def buildListFromResult(result : Seq[(OauthClientDB)]) : List[OauthClient] = {
val oauthClientList = result.seq.foldLeft[List[OauthClient]](Nil)((oauthClientList, dbEntry) => {
val oauthClient = dbEntry
oauthClientList ++ List(oauthClient.toOauthClient)
})
oauthClientList
}
}

0 comments on commit 6313b8e

Please sign in to comment.