diff --git a/app/daos/OauthClientDao.scala b/app/daos/OauthClientDao.scala index 7a7b9262..00b9f20a 100644 --- a/app/daos/OauthClientDao.scala +++ b/app/daos/OauthClientDao.scala @@ -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. @@ -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) @@ -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(_)) + } } diff --git a/app/models/converter/OauthClientConverter.scala b/app/models/converter/OauthClientConverter.scala new file mode 100644 index 00000000..fe6fd9ce --- /dev/null +++ b/app/models/converter/OauthClientConverter.scala @@ -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 + } +}