Skip to content

Commit

Permalink
[TRELLO-2168] Implement a better 'lifecycle' for categories
Browse files Browse the repository at this point in the history
  • Loading branch information
charlescd committed Feb 7, 2024
1 parent 03138e0 commit 6a0d68a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 23 deletions.
17 changes: 16 additions & 1 deletion app/controllers/ConstantController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
}

}
60 changes: 38 additions & 22 deletions app/models/report/ReportCategory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 6a0d68a

Please sign in to comment.