diff --git a/app/controllers/ConstantController.scala b/app/controllers/ConstantController.scala index 22dcddfb..77b501db 100644 --- a/app/controllers/ConstantController.scala +++ b/app/controllers/ConstantController.scala @@ -3,6 +3,7 @@ package controllers import authentication.Authenticator import models.User import models.report.ReportCategory +import models.report.ReportCategoryStatus import play.api.Logger import play.api.libs.json.Json import play.api.mvc.ControllerComponents @@ -21,7 +22,21 @@ class ConstantController(authenticator: Authenticator[User], controllerComponent } def getCategories = Action.async { - Future(Ok(Json.toJson(ReportCategory.values.filterNot(_.legacy)))) + Future(Ok(Json.toJson(ReportCategory.values.filter(_.status != ReportCategoryStatus.Legacy)))) + } + + def getCategoriesByStatus() = Action.async { + val legacy = ReportCategory.values.filter(_.status == ReportCategoryStatus.Legacy) + val closed = ReportCategory.values.filter(_.status == ReportCategoryStatus.Closed) + val inactive = ReportCategory.values.filter(_.status == ReportCategoryStatus.Inactive) + val active = ReportCategory.values.filter(_.status == ReportCategoryStatus.Active) + val json = Json.obj( + "active" -> active, + "inactive" -> inactive, + "legacy" -> legacy, + "closed" -> closed + ) + Future(Ok(json)) } } diff --git a/app/models/report/ReportCategory.scala b/app/models/report/ReportCategory.scala index eaf86762..9891a196 100644 --- a/app/models/report/ReportCategory.scala +++ b/app/models/report/ReportCategory.scala @@ -4,31 +4,47 @@ import controllers.error.AppError.MalformedValue import enumeratum.EnumEntry import enumeratum.PlayEnum -sealed abstract class ReportCategory(val label: String, val legacy: Boolean = false) extends EnumEntry +sealed trait ReportCategoryStatus +object ReportCategoryStatus { + case object Legacy + extends ReportCategoryStatus // it has been modified / splitted / migrated and should never come back + case object Closed extends ReportCategoryStatus // Old category, not available and no investigation + case object Inactive + extends ReportCategoryStatus // Category not available in the website, but an investigation could still happen + case object Active extends ReportCategoryStatus +} + +// Legacy means +// Active means it's an old category not up to date anymore but could come back (COVID is a good example) +sealed abstract class ReportCategory(val label: String, val status: ReportCategoryStatus = ReportCategoryStatus.Active) + extends EnumEntry object ReportCategory extends PlayEnum[ReportCategory] { - case object RetraitRappelSpecifique extends ReportCategory("Retrait-Rappel spécifique") - case object Coronavirus extends ReportCategory("COVID-19 (coronavirus)") - case object CafeRestaurant extends ReportCategory("Café / Restaurant") - case object AchatMagasinLegacy extends ReportCategory("Achat / Magasin", legacy = true) - case object AchatMagasinInternet extends ReportCategory("Achat (Magasin ou Internet)", legacy = true) - case object AchatMagasin extends ReportCategory("Achat en Magasin") - case object AchatInternet extends ReportCategory("Achat sur internet") - case object ServicesAuxParticuliers extends ReportCategory("Services aux particuliers") - case object TelEauGazElec extends ReportCategory("Téléphonie / Eau-Gaz-Electricité", legacy = true) - case object EauGazElectricite extends ReportCategory("Eau / Gaz / Electricité") - case object TelephonieFaiMedias extends ReportCategory("Téléphonie / Fournisseur d'accès internet / médias") - case object BanqueAssuranceMutuelle extends ReportCategory("Banque / Assurance / Mutuelle") - case object IntoxicationAlimentaire extends ReportCategory("Intoxication alimentaire") - case object ProduitsObjets extends ReportCategory("Produits / Objets", legacy = true) - case object Internet extends ReportCategory("Internet (hors achats)") - case object TravauxRenovations extends ReportCategory("Travaux / Rénovation") - case object VoyageLoisirs extends ReportCategory("Voyage / Loisirs") - case object Immobilier extends ReportCategory("Immobilier") - case object Sante extends ReportCategory("Secteur de la santé") - case object VoitureVehicule extends ReportCategory("Voiture / Véhicule", legacy = true) - case object Animaux extends ReportCategory("Animaux") + case object RetraitRappelSpecifique + extends ReportCategory("Retrait-Rappel spécifique", status = ReportCategoryStatus.Closed) + case object Coronavirus extends ReportCategory("COVID-19 (coronavirus)", status = ReportCategoryStatus.Closed) + case object CafeRestaurant extends ReportCategory("Café / Restaurant") + case object AchatMagasinLegacy extends ReportCategory("Achat / Magasin", status = ReportCategoryStatus.Legacy) + case object AchatMagasinInternet + extends ReportCategory("Achat (Magasin ou Internet)", status = ReportCategoryStatus.Legacy) + case object AchatMagasin extends ReportCategory("Achat en Magasin") + case object AchatInternet extends ReportCategory("Achat sur internet") + case object ServicesAuxParticuliers extends ReportCategory("Services aux particuliers") + case object TelEauGazElec + extends ReportCategory("Téléphonie / Eau-Gaz-Electricité", status = ReportCategoryStatus.Legacy) + case object EauGazElectricite extends ReportCategory("Eau / Gaz / Electricité") + case object TelephonieFaiMedias extends ReportCategory("Téléphonie / Fournisseur d'accès internet / médias") + case object BanqueAssuranceMutuelle extends ReportCategory("Banque / Assurance / Mutuelle") + case object IntoxicationAlimentaire extends ReportCategory("Intoxication alimentaire") + case object ProduitsObjets extends ReportCategory("Produits / Objets", status = ReportCategoryStatus.Legacy) + case object Internet extends ReportCategory("Internet (hors achats)") + case object TravauxRenovations extends ReportCategory("Travaux / Rénovation") + case object VoyageLoisirs extends ReportCategory("Voyage / Loisirs") + case object Immobilier extends ReportCategory("Immobilier") + case object Sante extends ReportCategory("Secteur de la santé") + case object VoitureVehicule extends ReportCategory("Voiture / Véhicule", status = ReportCategoryStatus.Legacy) + case object Animaux extends ReportCategory("Animaux") case object DemarchesAdministratives extends ReportCategory("Démarches administratives") case object VoitureVehiculeVelo extends ReportCategory("Voiture / Véhicule / Vélo") case object DemarchageAbusif extends ReportCategory("Démarchage abusif") diff --git a/conf/routes b/conf/routes index 079a3d31..895b6fc9 100644 --- a/conf/routes +++ b/conf/routes @@ -85,6 +85,7 @@ GET /api/async-files controll # Constants API GET /api/constants/countries controllers.ConstantController.getCountries() GET /api/constants/categories controllers.ConstantController.getCategories() +GET /api/constants/categoriesByStatus controllers.ConstantController.getCategoriesByStatus() # Mobile app specific API GET /api/mobileapp/requirements controllers.MobileAppController.getRequirements()