Skip to content

Commit

Permalink
Supprime les antennes et les emails dupliqués (#557)
Browse files Browse the repository at this point in the history
* Supprime les antennes et les emails dupliqués

* Update app/controllers/ApiController.scala

Co-Authored-By: niladic <git@nil.choron.cc>

* Apply suggestions from code review

Co-Authored-By: niladic <git@nil.choron.cc>

Co-authored-by: niladic <git@nil.choron.cc>
  • Loading branch information
jdauphant and niladic authored Mar 26, 2020
1 parent f36fee5 commit e2598bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 59 deletions.
21 changes: 17 additions & 4 deletions app/controllers/ApiController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ case class ApiController @Inject() (

private def matchFranceServiceInstance(
franceServiceInstance: FranceServiceInstance,
groups: List[UserGroup]
groups: List[UserGroup],
doNotMatchTheseEmails: Set[String]
): Option[UserGroup] = {
def byEmail: Option[UserGroup] =
franceServiceInstance.contactMail.flatMap(email =>
groups.find(group => (group.email: Option[String]) == (Some(email): Option[String]))
if (doNotMatchTheseEmails.contains(email)) {
None
} else {
groups.find(group => (group.email: Option[String]) == (Some(email): Option[String]))
}
)
def byName: Option[UserGroup] =
groups.find(group =>
Expand Down Expand Up @@ -62,12 +67,20 @@ case class ApiController @Inject() (
val userGroups = userGroupService.allGroups.filter(
_.organisationSetOrDeducted.exists(_.id == Organisation.franceServicesId)
)
val franceServiceInstances = organisationService.franceServiceInfos.instances
val doNotMatchTheseEmails =
franceServiceInstances
.flatMap(_.contactMail)
.groupBy(identity)
.filter(_._2.length > 1)
.keys
.toSet
val matches: List[(FranceServiceInstance, Option[UserGroup], Area)] =
organisationService.franceServiceInfos.instances
franceServiceInstances
.map(instance =>
(
instance,
matchFranceServiceInstance(instance, userGroups),
matchFranceServiceInstance(instance, userGroups, doNotMatchTheseEmails),
Area.fromInseeCode(instance.departementCode.code).getOrElse(Area.notApplicable)
)
)
Expand Down
Loading

0 comments on commit e2598bd

Please sign in to comment.