Skip to content

Commit

Permalink
feat: handle maintenance event
Browse files Browse the repository at this point in the history
  • Loading branch information
vitlinda authored and nicolasfara committed Oct 18, 2022
1 parent d768bd6 commit 467bb05
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions alerts-manager/src/main/scala/dev/atedeg/mdm/Actions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 18 additions & 1 deletion alerts-manager/src/main/scala/dev/atedeg/mdm/api/Handlers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ()
9 changes: 9 additions & 0 deletions alerts-manager/src/main/scala/dev/atedeg/mdm/dto/DTOs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 467bb05

Please sign in to comment.