-
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 #1541 from betagouv/master
MEP
- Loading branch information
Showing
15 changed files
with
236 additions
and
57 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package controllers | ||
|
||
import authentication.Authenticator | ||
import cats.implicits.toTraverseOps | ||
import models.User | ||
import models.report.SocialNetworkSlug | ||
import orchestrators.socialmedia.InfluencerOrchestrator | ||
import play.api.Logger | ||
import play.api.libs.json.Json | ||
import play.api.mvc.ControllerComponents | ||
|
||
import scala.concurrent.ExecutionContext | ||
|
||
class SocialNetworkController( | ||
influencerOrchestrator: InfluencerOrchestrator, | ||
authenticator: Authenticator[User], | ||
controllerComponents: ControllerComponents | ||
)(implicit | ||
val ec: ExecutionContext | ||
) extends BaseController(authenticator, controllerComponents) { | ||
val logger: Logger = Logger(this.getClass) | ||
|
||
def get(name: String, socialNetwork: String) = Action.async { _ => | ||
SocialNetworkSlug | ||
.withNameInsensitiveOption(socialNetwork) | ||
.traverse(socialNetworkSlug => | ||
influencerOrchestrator | ||
.get(name, socialNetworkSlug) | ||
) | ||
.map(_.getOrElse(false)) | ||
.map(result => Ok(Json.toJson(result))) | ||
|
||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package models.report.socialnetwork | ||
|
||
import models.report.SocialNetworkSlug | ||
import play.api.libs.json.Json | ||
import play.api.libs.json.OFormat | ||
|
||
import java.util.UUID | ||
|
||
case class CertifiedInfluencer(id: UUID, socialNetwork: SocialNetworkSlug, name: String) | ||
|
||
object CertifiedInfluencer { | ||
implicit val format: OFormat[CertifiedInfluencer] = Json.format[CertifiedInfluencer] | ||
} |
17 changes: 17 additions & 0 deletions
17
app/orchestrators/socialmedia/InfluencerOrchestrator.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,17 @@ | ||
package orchestrators.socialmedia | ||
|
||
import models.report.SocialNetworkSlug | ||
import repositories.influencer.InfluencerRepositoryInterface | ||
|
||
import scala.concurrent.ExecutionContext | ||
import scala.concurrent.Future | ||
|
||
class InfluencerOrchestrator( | ||
influencerRepository: InfluencerRepositoryInterface | ||
)(implicit | ||
val executionContext: ExecutionContext | ||
) { | ||
|
||
def get(name: String, socialNetwork: SocialNetworkSlug): Future[Boolean] = | ||
influencerRepository.get(name, socialNetwork).map(_.nonEmpty) | ||
} |
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,31 @@ | ||
package repositories.influencer | ||
|
||
import models.report.SocialNetworkSlug | ||
import models.report.socialnetwork.CertifiedInfluencer | ||
import play.api.Logger | ||
import repositories.CRUDRepository | ||
import repositories.PostgresProfile.api._ | ||
import slick.basic.DatabaseConfig | ||
import slick.jdbc.JdbcProfile | ||
import slick.lifted.TableQuery | ||
|
||
import scala.concurrent.ExecutionContext | ||
class InfluencerRepository(override val dbConfig: DatabaseConfig[JdbcProfile])(implicit | ||
override val ec: ExecutionContext | ||
) extends CRUDRepository[InfluencerTable, CertifiedInfluencer] | ||
with InfluencerRepositoryInterface { | ||
|
||
val logger: Logger = Logger(this.getClass) | ||
val table: TableQuery[InfluencerTable] = InfluencerTable.table | ||
import dbConfig._ | ||
|
||
override def get(name: String, socialNetwork: SocialNetworkSlug) = db.run( | ||
table | ||
.filter { result => | ||
result.name.toLowerCase === (name.toLowerCase: String) | ||
} | ||
.filter(_.socialNetwork === (socialNetwork: SocialNetworkSlug)) | ||
.result | ||
) | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
app/repositories/influencer/InfluencerRepositoryInterface.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,11 @@ | ||
package repositories.influencer | ||
|
||
import models.report.SocialNetworkSlug | ||
import models.report.socialnetwork.CertifiedInfluencer | ||
import repositories.CRUDRepositoryInterface | ||
|
||
import scala.concurrent.Future | ||
|
||
trait InfluencerRepositoryInterface extends CRUDRepositoryInterface[CertifiedInfluencer] { | ||
def get(name: String, socialNetwork: SocialNetworkSlug): Future[Seq[CertifiedInfluencer]] | ||
} |
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,20 @@ | ||
package repositories.influencer | ||
|
||
import models.report.SocialNetworkSlug | ||
import models.report.socialnetwork.CertifiedInfluencer | ||
import repositories.DatabaseTable | ||
import repositories.PostgresProfile.api._ | ||
import slick.ast.TypedType | ||
|
||
class InfluencerTable(tag: Tag)(implicit tt: TypedType[SocialNetworkSlug]) | ||
extends DatabaseTable[CertifiedInfluencer](tag, "influencers") { | ||
def socialNetwork = column[SocialNetworkSlug]("social_network") | ||
|
||
def name = column[String]("name") | ||
|
||
override def * = (id, socialNetwork, name) <> ((CertifiedInfluencer.apply _).tupled, CertifiedInfluencer.unapply) | ||
} | ||
|
||
object InfluencerTable { | ||
val table = TableQuery[InfluencerTable] | ||
} |
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,5 @@ | ||
CREATE TABLE IF NOT EXISTS influencers ( | ||
id UUID NOT NULL PRIMARY KEY, | ||
name VARCHAR NOT NULL, | ||
social_network VARCHAR NOT NULL | ||
); |
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
Oops, something went wrong.