Skip to content

Commit

Permalink
Merge pull request #1448 from betagouv/master
Browse files Browse the repository at this point in the history
[TRELLO-1999] Add country and brand to company model (#1447)
  • Loading branch information
eletallbetagouv authored Sep 19, 2023
2 parents 95cb307 + 828ecba commit 92cfa7d
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 21 deletions.
7 changes: 5 additions & 2 deletions app/controllers/AdminController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class AdminController(
details = List(toDetailInputValue("test")),
companyId = Some(UUID.randomUUID()),
companyName = Some("Dummy Inc."),
companyBrand = Some("Dummy Inc. Store"),
companyAddress = Address(Some("3 bis"), Some("Rue des exemples"), None, Some("13006"), Some("Douceville")),
companySiret = Some(SIRET("12345678912345")),
companyActivityCode = None,
Expand Down Expand Up @@ -142,12 +143,14 @@ class AdminController(
number = Some("3"),
street = Some("rue des Champs"),
postalCode = Some("75015"),
city = Some("Paris")
city = Some("Paris"),
country = None
),
activityCode = None,
isHeadOffice = true,
isOpen = true,
isPublic = true
isPublic = true,
brand = Some("une super enseigne")
)

private def genUser = User(
Expand Down
12 changes: 8 additions & 4 deletions app/models/company/Company.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ case class Company(
activityCode: Option[String],
isHeadOffice: Boolean,
isOpen: Boolean,
isPublic: Boolean
isPublic: Boolean,
brand: Option[String]
) {
def shortId = this.id.toString.substring(0, 13).toUpperCase
}
Expand All @@ -61,7 +62,7 @@ object CompanyRegisteredSearch {
departments = mapper.seq("departments"),
activityCodes = mapper.seq("activityCodes"),
emailsWithAccess = mapper.string("emailsWithAccess"),
identity = mapper.string("identity").map(SearchCompanyIdentity.fromString)
identity = mapper.nonEmptyString("identity").map(SearchCompanyIdentity.fromString)
)
}
}
Expand Down Expand Up @@ -90,7 +91,8 @@ case class CompanyCreation(
activityCode: Option[String],
isHeadOffice: Option[Boolean],
isOpen: Option[Boolean],
isPublic: Option[Boolean]
isPublic: Option[Boolean],
brand: Option[String]
) {
def toCompany(): Company = Company(
siret = siret,
Expand All @@ -99,7 +101,8 @@ case class CompanyCreation(
activityCode = activityCode,
isHeadOffice = isHeadOffice.getOrElse(false),
isOpen = isOpen.getOrElse(true),
isPublic = isPublic.getOrElse(true)
isPublic = isPublic.getOrElse(true),
brand = brand
)
}

Expand All @@ -113,6 +116,7 @@ case class CompanyWithNbReports(
siret: SIRET,
creationDate: OffsetDateTime = OffsetDateTime.now(),
name: String,
brand: Option[String],
address: Address,
activityCode: Option[String],
count: Int,
Expand Down
3 changes: 3 additions & 0 deletions app/models/report/Report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ case class Report(
influencer: Option[Influencer],
companyId: Option[UUID],
companyName: Option[String],
companyBrand: Option[String],
companyAddress: Address,
companySiret: Option[SIRET],
companyActivityCode: Option[String],
Expand Down Expand Up @@ -97,6 +98,7 @@ object Report {
"influencer" -> report.influencer,
"companyId" -> report.companyId,
"companyName" -> report.companyName,
"companyBrand" -> report.companyBrand,
"companyAddress" -> Json.toJson(report.companyAddress),
"companySiret" -> report.companySiret,
"creationDate" -> report.creationDate,
Expand Down Expand Up @@ -204,6 +206,7 @@ object DeprecatedCompanyWithNbReports {

case class ReportCompany(
name: String,
brand: Option[String],
address: Address,
siret: SIRET,
activityCode: Option[String],
Expand Down
2 changes: 2 additions & 0 deletions app/models/report/ReportDraft.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ case class ReportDraft(
details: List[DetailInputValue],
influencer: Option[Influencer],
companyName: Option[String],
companyBrand: Option[String],
companyAddress: Option[Address],
companySiret: Option[SIRET],
companyActivityCode: Option[String],
Expand Down Expand Up @@ -67,6 +68,7 @@ case class ReportDraft(
influencer = influencer,
companyId = maybeCompanyId.orElse(socialNetworkCompany.map(_.id)),
companyName = companyName.orElse(socialNetworkCompany.map(_.name)),
companyBrand = companyBrand.orElse(socialNetworkCompany.flatMap(_.brand)),
companyAddress = companyAddress.orElse(socialNetworkCompany.map(_.address)).getOrElse(Address()),
companySiret = companySiret.orElse(socialNetworkCompany.map(_.siret)),
companyActivityCode = companyActivityCode.orElse(socialNetworkCompany.flatMap(_.activityCode)),
Expand Down
9 changes: 6 additions & 3 deletions app/orchestrators/ReportOrchestrator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ class ReportOrchestrator(
logger.error(s"draftReport.companyIsPublic should not be empty, company details (siret: $siret)")
}
draftReport.companyIsPublic.getOrElse(false)
}
},
brand = draftReport.companyBrand
)
companyRepository.getOrCreate(siret, company).map { company =>
logger.debug("Company extracted from report")
Expand All @@ -389,7 +390,8 @@ class ReportOrchestrator(
activityCode = companyToCreate.activityCode,
isHeadOffice = companyToCreate.isHeadOffice,
isOpen = companyToCreate.isOpen,
isPublic = companyToCreate.isPublic
isPublic = companyToCreate.isPublic,
brand = companyToCreate.brand
)
company <- OptionT.liftF(companyRepository.getOrCreate(companyToCreate.siret, c))
} yield company).value
Expand Down Expand Up @@ -465,7 +467,8 @@ class ReportOrchestrator(
activityCode = reportCompany.activityCode,
isHeadOffice = reportCompany.isHeadOffice,
isOpen = reportCompany.isOpen,
isPublic = reportCompany.isPublic
isPublic = reportCompany.isPublic,
brand = reportCompany.brand
)
)
users <- companiesVisibilityOrchestrator.fetchUsersWithHeadOffices(company.siret)
Expand Down
3 changes: 2 additions & 1 deletion app/orchestrators/WebsitesOrchestrator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ class WebsitesOrchestrator(
activityCode = company.activityCode,
isHeadOffice = company.isHeadOffice,
isOpen = company.isOpen,
isPublic = company.isPublic
isPublic = company.isPublic,
brand = company.brand
)
for {
reportIds <- reportRepository.getForWebsiteWithoutCompany(websiteHost)
Expand Down
5 changes: 3 additions & 2 deletions app/repositories/company/CompanyRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ class CompanyRepository(override val dbConfig: DatabaseConfig[JdbcProfile])(impl
case SearchCompanyIdentityRCS(q) => query.filter(_._1.id.asColumnOf[String] like s"%${q}%")
case SearchCompanyIdentitySiret(q) => query.filter(_._1.siret === SIRET.fromUnsafe(q))
case SearchCompanyIdentitySiren(q) => query.filter(_._1.siret.asColumnOf[String] like s"${q}_____")
case SearchCompanyIdentityName(q) => query.filter(_._1.name.toLowerCase like s"%${q.toLowerCase}%")
case id: SearchCompanyIdentityId => query.filter(_._1.id === id.value)
case SearchCompanyIdentityName(q) =>
query.filter(tuple => toTsVector(tuple._1.name ++ " " ++ tuple._1.brand) @@ plainToTsQuery(q))
case id: SearchCompanyIdentityId => query.filter(_._1.id === id.value)
}
.getOrElse(query)
.filterOpt(search.emailsWithAccess) { case (table, email) =>
Expand Down
28 changes: 21 additions & 7 deletions app/repositories/company/CompanyTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import models.company.Company
import repositories.DatabaseTable
import slick.lifted.TableQuery
import utils.Constants.Departments
import utils.Country
import utils.SIRET
import repositories.PostgresProfile.api._

Expand All @@ -25,6 +26,8 @@ class CompanyTable(tag: Tag) extends DatabaseTable[Company](tag, "companies") {
def isHeadOffice = column[Boolean]("is_headoffice")
def isOpen = column[Boolean]("is_open")
def isPublic = column[Boolean]("is_public")
def brand = column[Option[String]]("brand")
def country = column[Option[String]]("country")

type CompanyTuple = (
UUID,
Expand All @@ -40,7 +43,9 @@ class CompanyTable(tag: Tag) extends DatabaseTable[Company](tag, "companies") {
Option[String],
Boolean,
Boolean,
Boolean
Boolean,
Option[String],
Option[String]
)

def constructCompany: CompanyTuple => Company = {
Expand All @@ -58,7 +63,9 @@ class CompanyTable(tag: Tag) extends DatabaseTable[Company](tag, "companies") {
activityCode,
isHeadOffice,
isOpen,
isPublic
isPublic,
brand,
country
) =>
Company(
id = id,
Expand All @@ -70,12 +77,14 @@ class CompanyTable(tag: Tag) extends DatabaseTable[Company](tag, "companies") {
street = street,
addressSupplement = addressSupplement,
postalCode = postalCode,
city = city
city = city,
country = country.map(Country.fromCode)
),
activityCode = activityCode,
isHeadOffice = isHeadOffice,
isOpen = isOpen,
isPublic = isPublic
isPublic = isPublic,
brand = brand
)
}

Expand All @@ -89,7 +98,8 @@ class CompanyTable(tag: Tag) extends DatabaseTable[Company](tag, "companies") {
activityCode,
isHeadOffice,
isOpen,
isPublic
isPublic,
brand
) =>
(
id,
Expand All @@ -105,7 +115,9 @@ class CompanyTable(tag: Tag) extends DatabaseTable[Company](tag, "companies") {
activityCode,
isHeadOffice,
isOpen,
isPublic
isPublic,
brand,
address.country.map(_.code)
)
}

Expand All @@ -123,7 +135,9 @@ class CompanyTable(tag: Tag) extends DatabaseTable[Company](tag, "companies") {
activityCode,
isHeadOffice,
isOpen,
isPublic
isPublic,
brand,
country
) <> (constructCompany, extractCompany.lift)
}

Expand Down
6 changes: 6 additions & 0 deletions app/repositories/report/ReportTable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ReportTable(tag: Tag) extends DatabaseTable[Report](tag, "reports") {
def influencerName = column[Option[String]]("influencer_name")
def companyId = column[Option[UUID]]("company_id")
def companyName = column[Option[String]]("company_name")
def companyBrand = column[Option[String]]("company_brand")
def companySiret = column[Option[SIRET]]("company_siret")
def companyStreetNumber = column[Option[String]]("company_street_number")
def companyStreet = column[Option[String]]("company_street")
Expand Down Expand Up @@ -73,6 +74,7 @@ class ReportTable(tag: Tag) extends DatabaseTable[Report](tag, "reports") {
influencerName ::
companyId ::
companyName ::
companyBrand ::
companySiret ::
companyStreetNumber ::
companyStreet ::
Expand Down Expand Up @@ -110,6 +112,7 @@ class ReportTable(tag: Tag) extends DatabaseTable[Report](tag, "reports") {
details = details.filter(_ != null).map(toDetailInputValue),
companyId = companyId,
companyName = companyName,
companyBrand = companyBrand,
companyAddress = Address(
number = companyStreetNumber,
street = companyStreet,
Expand Down Expand Up @@ -156,6 +159,7 @@ class ReportTable(tag: Tag) extends DatabaseTable[Report](tag, "reports") {
r.influencer.map(_.name) ::
r.companyId ::
r.companyName ::
r.companyBrand ::
r.companySiret ::
r.companyAddress.number ::
r.companyAddress.street ::
Expand Down Expand Up @@ -197,6 +201,7 @@ class ReportTable(tag: Tag) extends DatabaseTable[Report](tag, "reports") {
Option[String] ::
Option[UUID] ::
Option[String] ::
Option[String] ::
Option[SIRET] ::
Option[String] ::
Option[String] ::
Expand Down Expand Up @@ -237,6 +242,7 @@ class ReportTable(tag: Tag) extends DatabaseTable[Report](tag, "reports") {
influencerName ::
companyId ::
companyName ::
companyBrand ::
companySiret ::
companyStreetNumber ::
companyStreet ::
Expand Down
2 changes: 2 additions & 0 deletions app/utils/QueryStringMapper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class QueryStringMapper(q: Map[String, Seq[String]]) {

def string(k: String): Option[String] = q.get(k).flatMap(_.headOption)

def nonEmptyString(k: String): Option[String] = q.get(k).flatMap(_.headOption).filter(_.nonEmpty)

def UUID(k: String): Option[UUID] = q.get(k).flatMap(_.headOption).map(extractUUID)

def seq(k: String): Seq[String] = q.getOrElse(k, Nil)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE companies
ADD brand varchar,
ADD country varchar;

ALTER TABLE reports
ADD company_brand varchar;
3 changes: 3 additions & 0 deletions test/controllers/report/GetReportSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ trait GetReportContext extends AppSpec {
influencer = None,
companyId = Some(company.id),
companyName = Some("companyName"),
companyBrand = Some("companyBrand"),
companyAddress = company.address,
companySiret = Some(company.siret),
companyActivityCode = company.activityCode,
Expand All @@ -291,6 +292,7 @@ trait GetReportContext extends AppSpec {
influencer = None,
companyId = Some(company.id),
companyName = Some("companyName"),
companyBrand = Some("companyBrand"),
companyAddress = company.address,
companySiret = Some(company.siret),
companyActivityCode = company.activityCode,
Expand All @@ -315,6 +317,7 @@ trait GetReportContext extends AppSpec {
influencer = None,
companyId = Some(company.id),
companyName = Some("companyName"),
companyBrand = Some("companyBrand"),
companyAddress = company.address,
companySiret = Some(company.siret),
companyActivityCode = company.activityCode,
Expand Down
9 changes: 7 additions & 2 deletions test/utils/Fixtures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ object Fixtures {
val genCompany = for {
_ <- arbitrary[UUID]
name <- arbString.arbitrary
brand <- Gen.option(arbString.arbitrary)
siret <- genSiret()
address <- genAddress()
} yield Company(
Expand All @@ -92,7 +93,8 @@ object Fixtures {
activityCode = None,
isOpen = true,
isHeadOffice = false,
isPublic = true
isPublic = true,
brand = brand
)

val genInfluencer = for {
Expand Down Expand Up @@ -125,6 +127,7 @@ object Fixtures {
details = List(),
influencer = None,
companyName = Some(company.name),
companyBrand = company.brand,
companyAddress = Some(company.address),
companySiret = Some(company.siret),
companyActivityCode = None,
Expand Down Expand Up @@ -172,6 +175,7 @@ object Fixtures {
companyId = Some(company.id),
creationDate = OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS),
companyName = Some(company.name),
companyBrand = company.brand,
companyAddress = company.address,
companySiret = Some(company.siret),
companyActivityCode = company.activityCode,
Expand Down Expand Up @@ -205,9 +209,10 @@ object Fixtures {

def genReportCompany = for {
name <- arbString.arbitrary
brand <- Gen.option(arbString.arbitrary)
address <- genAddress(postalCode = Some(Gen.choose(10000, 99999).toString))
siret <- genSiret()
} yield ReportCompany(name, address, siret, None, isHeadOffice = true, isOpen = true, isPublic = true)
} yield ReportCompany(name, brand, address, siret, None, isHeadOffice = true, isOpen = true, isPublic = true)

def genEventForReport(reportId: UUID, eventType: EventTypeValue, actionEvent: ActionEventValue) = for {
id <- arbitrary[UUID]
Expand Down

0 comments on commit 92cfa7d

Please sign in to comment.