Skip to content

Commit

Permalink
[TRELLO-2658] Fix reports not updated when crating a website (#1757)
Browse files Browse the repository at this point in the history
  • Loading branch information
charlescd authored Oct 16, 2024
1 parent 899617e commit 38ad5c7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/WebsiteController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class WebsiteController(
errors => Future.successful(BadRequest(JsError.toJson(errors))),
websiteCreation =>
websitesOrchestrator
.create(URL(websiteCreation.host), websiteCreation.company.toCompany())
.create(URL(websiteCreation.host), websiteCreation.company.toCompany(), request.identity)
.map(website => Ok(Json.toJson(website)))
)
}
Expand Down
5 changes: 3 additions & 2 deletions app/orchestrators/ReportOrchestrator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,10 @@ class ReportOrchestrator(
reportCompany: ReportCompany,
adminUserId: UUID
) =
if (isReportTooOld(existingReport))
if (isReportTooOld(existingReport)) {
logger.debug(s"Report ${existingReport.id} is too old to be updated")
Future.unit
else
} else
updateReportCompany(existingReport, reportCompany, adminUserId).map(_ => ())

private def updateReportCompany(
Expand Down
4 changes: 3 additions & 1 deletion app/orchestrators/WebsitesOrchestrator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class WebsitesOrchestrator(

val logger: Logger = Logger(this.getClass)

def create(url: URL, company: Company): Future[Website] =
def create(url: URL, company: Company, user: User): Future[Website] =
for {
host <- url.getHost.liftTo[Future](MalformedHost(url.value))
createdCompany <- companyRepository.getOrCreate(company.siret, company)
Expand All @@ -62,6 +62,7 @@ class WebsitesOrchestrator(
identificationStatus = IdentificationStatus.Identified
)
createdWebsite <- repository.create(website)
_ <- updatePreviousReportsAssociatedToWebsite(website.host, createdCompany, user.id)
} yield createdWebsite

def searchByHost(host: String): Future[Seq[Country]] =
Expand Down Expand Up @@ -272,6 +273,7 @@ class WebsitesOrchestrator(
)
for {
reports <- reportRepository.getForWebsiteWithoutCompany(websiteHost)
_ = logger.debug(s"updatePreviousReportsAssociatedToWebsite: Found ${reports.length} reports to update")
_ <- reports.traverse(reportId =>
reportOrchestrator.updateReportCompanyForWebsite(reportId, reportCompany, userId)
)
Expand Down

0 comments on commit 38ad5c7

Please sign in to comment.