-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1858 from betagouv/master
MEP
- Loading branch information
Showing
22 changed files
with
531 additions
and
45 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
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
48 changes: 48 additions & 0 deletions
48
app/repositories/siretextraction/SiretExtractionRepository.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,48 @@ | ||
package repositories.siretextraction | ||
|
||
import models.website.IdentificationStatus | ||
import models.website.Website | ||
import slick.basic.DatabaseConfig | ||
import slick.jdbc.JdbcProfile | ||
import repositories.PostgresProfile.api._ | ||
import repositories.website.WebsiteColumnType._ | ||
import repositories.website.WebsiteTable | ||
import tasks.website.ExtractionResultApi | ||
|
||
import scala.concurrent.ExecutionContext | ||
import scala.concurrent.Future | ||
|
||
trait SiretExtractionRepositoryInterface { | ||
def getByHost(host: String): Future[Option[ExtractionResultApi]] | ||
def listUnextractedWebsiteHosts(n: Int): Future[List[Website]] | ||
def insertOrReplace(extraction: ExtractionResultApi): Future[Unit] | ||
} | ||
|
||
class SiretExtractionRepository(dbConfig: DatabaseConfig[JdbcProfile])(implicit ec: ExecutionContext) | ||
extends SiretExtractionRepositoryInterface { | ||
|
||
val table = SiretExtractionTable.table | ||
|
||
import dbConfig._ | ||
|
||
override def getByHost(host: String): Future[Option[ExtractionResultApi]] = db.run( | ||
table.filter(_.host === host).to[List].result.headOption | ||
) | ||
|
||
def listUnextractedWebsiteHosts(n: Int): Future[List[Website]] = db.run( | ||
WebsiteTable.table | ||
.joinLeft(table) | ||
.on(_.host === _.host) | ||
.filter(_._1.identificationStatus === (IdentificationStatus.NotIdentified: IdentificationStatus)) | ||
.filter(_._2.isEmpty) | ||
.map(_._1) | ||
.distinctOn(_.host) | ||
.take(n) | ||
.to[List] | ||
.result | ||
) | ||
|
||
override def insertOrReplace(extraction: ExtractionResultApi): Future[Unit] = db.run( | ||
table.insertOrUpdate(extraction).map(_ => ()) | ||
) | ||
} |
Oops, something went wrong.