Skip to content

Commit

Permalink
TRELLO-2840 improve "Sites web" bloc
Browse files Browse the repository at this point in the history
  • Loading branch information
eletallbetagouv committed Jan 8, 2025
1 parent 21187e6 commit c1c4c88
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/orchestrators/CompanyOrchestrator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class CompanyOrchestrator(
companyRepository
.getOrCreate(companyCreation.siret, companyCreation.toCompany())

def fetchHosts(companyId: UUID): Future[Seq[String]] =
def fetchHosts(companyId: UUID): Future[Seq[(String, Int)]] =
reportRepository.getHostsByCompany(companyId)

def searchRegisteredById(
Expand Down
11 changes: 6 additions & 5 deletions app/repositories/report/ReportRepository.scala
Original file line number Diff line number Diff line change
Expand Up @@ -342,21 +342,22 @@ class ReportRepository(override val dbConfig: DatabaseConfig[JdbcProfile])(impli
.table(Some(user))
.filterOpt(companyId)(_.companyId === _)
.groupBy(_.tags)
.map { case (status, report) => (status, report.size) }
.map { case (tags, report) => (tags, report.size) }
.sortBy(_._2.desc)
.result
).map(spreadListOfTags)
}

def getHostsByCompany(companyId: UUID): Future[Seq[String]] =
def getHostsByCompany(companyId: UUID): Future[Seq[(String, Int)]] =
db.run(
table
.filter(_.companyId === companyId)
.filter(_.host.isDefined)
.map(_.host)
.distinct
.groupBy(_.host)
.map { case (host, rowsGroup) => (host, rowsGroup.size) }
.sortBy(_._2.desc)
.result
).map(_.map(_.getOrElse("")))
).map(_.map { case (maybeHost, nb) => (maybeHost.getOrElse(""), nb) })

def getReportsWithFiles(
user: Option[User],
Expand Down
2 changes: 1 addition & 1 deletion app/repositories/report/ReportRepositoryInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ trait ReportRepositoryInterface extends CRUDRepositoryInterface[Report] {
def getAcceptedResponsesDistribution(companyId: UUID, user: User): Future[Map[ExistingResponseDetails, Int]]
def getReportsTagsDistribution(companyId: Option[UUID], user: User): Future[Map[ReportTag, Int]]

def getHostsByCompany(companyId: UUID): Future[Seq[String]]
def getHostsByCompany(companyId: UUID): Future[Seq[(String, Int)]]

def getReportsWithFiles(user: Option[User], filter: ReportFilter): Future[SortedMap[Report, List[ReportFile]]]

Expand Down
2 changes: 1 addition & 1 deletion test/controllers/report/ReportRepositoryMock.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ReportRepositoryMock(database: mutable.Map[UUID, Report] = mutable.Map.emp
override def getReportsTagsDistribution(companyId: Option[UUID], user: User): Future[Map[ReportTag, Int]] =
???

override def getHostsByCompany(companyId: UUID): Future[Seq[String]] = ???
override def getHostsByCompany(companyId: UUID): Future[Seq[(String, Int)]] = ???

override def getReportsWithFiles(
user: Option[User],
Expand Down

0 comments on commit c1c4c88

Please sign in to comment.