From 467bb05902d7327277573a3b5e73e85d8486196f Mon Sep 17 00:00:00 2001 From: Linda Vitali Date: Tue, 18 Oct 2022 11:35:20 +0200 Subject: [PATCH] feat: handle maintenance event --- .../main/scala/dev/atedeg/mdm/Actions.scala | 5 +++++ .../scala/dev/atedeg/mdm/api/Handlers.scala | 19 ++++++++++++++++++- .../main/scala/dev/atedeg/mdm/dto/DTOs.scala | 9 +++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/alerts-manager/src/main/scala/dev/atedeg/mdm/Actions.scala b/alerts-manager/src/main/scala/dev/atedeg/mdm/Actions.scala index bef0da90..ef30b7f4 100644 --- a/alerts-manager/src/main/scala/dev/atedeg/mdm/Actions.scala +++ b/alerts-manager/src/main/scala/dev/atedeg/mdm/Actions.scala @@ -31,3 +31,8 @@ def managePackagingMachineFailure(failure: PackagingMachineFailure): String = "" |BatchID: ${failure.batchID.id} |Cutter temperature: ${failure.cutterTemperature.value} """.stripMargin + +def managePackagingMachineMaintenance(maintenance: Maintenance): String = """ + |Packaging machine maintenance is needed. + |Motivation: ${maintenance.motivation} + """.stripMargin diff --git a/alerts-manager/src/main/scala/dev/atedeg/mdm/api/Handlers.scala b/alerts-manager/src/main/scala/dev/atedeg/mdm/api/Handlers.scala index c9572155..05e7fb4c 100644 --- a/alerts-manager/src/main/scala/dev/atedeg/mdm/api/Handlers.scala +++ b/alerts-manager/src/main/scala/dev/atedeg/mdm/api/Handlers.scala @@ -10,8 +10,15 @@ import cats.syntax.all.* import eu.timepit.refined.numeric.Greater import eu.timepit.refined.refineV -import dev.atedeg.mdm.{ managePackageDamage, managePackagingMachineFailure, managePhAlarm, manageTemperatureAlarm } +import dev.atedeg.mdm.{ + managePackageDamage, + managePackagingMachineFailure, + managePackagingMachineMaintenance, + managePhAlarm, + manageTemperatureAlarm, +} import dev.atedeg.mdm.IncomingEvents.* +import dev.atedeg.mdm.Maintenance import dev.atedeg.mdm.PackageDamageFailure import dev.atedeg.mdm.PackagingMachineFailure import dev.atedeg.mdm.PhFailure @@ -57,3 +64,13 @@ def handlePackageDamagedEvent[M[_]: Monad: LiftIO: CanRaise[String]](event: Pack _ <- IO.println("Sending an e-mail to the admin...").liftIO[M] _ <- IO.println(message).liftIO[M] yield () + +def handlePackagingMachineMaintenanceEvent[M[_]: Monad: LiftIO: CanRaise[String]]( + event: PackagingMachineMaintenanceDTO, +): M[Unit] = + for + r <- validate(event) + message = managePackagingMachineMaintenance(r.maintenance) + _ <- IO.println("Sending an e-mail to the admin...").liftIO[M] + _ <- IO.println(message).liftIO[M] + yield () diff --git a/alerts-manager/src/main/scala/dev/atedeg/mdm/dto/DTOs.scala b/alerts-manager/src/main/scala/dev/atedeg/mdm/dto/DTOs.scala index fbfc7d93..bee8c18b 100644 --- a/alerts-manager/src/main/scala/dev/atedeg/mdm/dto/DTOs.scala +++ b/alerts-manager/src/main/scala/dev/atedeg/mdm/dto/DTOs.scala @@ -2,6 +2,7 @@ package dev.atedeg.mdm.dto import dev.atedeg.mdm.BatchID import dev.atedeg.mdm.IncomingEvents.* +import dev.atedeg.mdm.Maintenance import dev.atedeg.mdm.Ph import dev.atedeg.mdm.Temperature import dev.atedeg.mdm.utils.serialization.DTO @@ -33,3 +34,11 @@ object PackagingMachineFailedDTO: final case class PackageDamagedDTO(batchID: String, cutterTemperature: TemperatureDTO) object PackageDamagedDTO: given DTO[PackageDamaged, PackageDamagedDTO] = productTypeDTO + +final case class MaintenanceDTO(motivation: String) +object MaintenanceDTO: + given DTO[Maintenance, MaintenanceDTO] = productTypeDTO + +final case class PackagingMachineMaintenanceDTO(maintenance: MaintenanceDTO) +object PackagingMachineMaintenanceDTO: + given DTO[PackagingMachineMaintenance, PackagingMachineMaintenanceDTO] = productTypeDTO