-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PIN-5100: add new route GET -> /events/producerKeys
- Loading branch information
1 parent
1e1fad7
commit 24514c5
Showing
8 changed files
with
144 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/scala/it/pagopa/interop/notifier/database/ProducerKeyEventRecord.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package it.pagopa.interop.notifier.database | ||
|
||
import it.pagopa.interop.notifier.service.converters.EventType | ||
import it.pagopa.interop.notifier.service.converters.EventType.EventType | ||
import slick.jdbc.GetResult | ||
|
||
final case class ProducerKeyEventRecord(eventId: Long, kid: String, eventType: EventType) | ||
|
||
object ProducerKeyEventRecord { | ||
implicit val eventResult: GetResult[ProducerKeyEventRecord] = | ||
GetResult(r => ProducerKeyEventRecord(r.<<, r.<<, EventType.withName(r.<<))) | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/scala/it/pagopa/interop/notifier/database/ProducerKeyEventsDao.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package it.pagopa.interop.notifier.database | ||
|
||
import com.typesafe.scalalogging.Logger | ||
import it.pagopa.interop.notifier.common.system.ApplicationConfiguration | ||
import it.pagopa.interop.notifier.common.system.ApplicationConfiguration.postgresProducerKeysNotificationTable | ||
import slick.jdbc.JdbcBackend.Database | ||
import slick.jdbc.PostgresProfile.api._ | ||
import slick.sql.SqlStreamingAction | ||
|
||
import scala.concurrent.Future | ||
|
||
object ProducerKeyEventsDao { | ||
|
||
private val logger: Logger = Logger(this.getClass) | ||
|
||
private final val postgresqlDB: Database = | ||
Database.forConfig(path = "notifier.postgres", config = ApplicationConfiguration.config) | ||
|
||
def select(lastEventId: Long, limit: Int): Future[Vector[ProducerKeyEventRecord]] = { | ||
logger.debug(s"Getting keys events from lastEventId ${lastEventId.toString} with limit ${limit.toString}") | ||
|
||
val statement: SqlStreamingAction[Vector[ProducerKeyEventRecord], ProducerKeyEventRecord, Effect] = | ||
sql"SELECT event_id, kid, event_type FROM #$postgresProducerKeysNotificationTable WHERE event_id > $lastEventId ORDER BY event_id ASC LIMIT $limit" | ||
.as[ProducerKeyEventRecord] | ||
postgresqlDB.run(statement) | ||
} | ||
|
||
} |