-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement /unwatchproduct processing with simple logging of callback …
…data
- Loading branch information
1 parent
c218d08
commit c2e8e88
Showing
10 changed files
with
108 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ru.ekuzmichev | ||
package bot | ||
|
||
import io.circe.Decoder.Result | ||
import io.circe.{Codec, DecodingFailure, HCursor, Json} | ||
|
||
sealed trait CallbackData | ||
|
||
object CallbackData: | ||
case class DeleteProduct(index: Int) extends CallbackData | ||
|
||
// TODO: Migrate to circe-generic-extras instead of manual codec when it is available for Scala 3 | ||
implicit val codec: Codec[CallbackData] = new Codec[CallbackData]: | ||
override def apply(hCursor: HCursor): Result[CallbackData] = | ||
hCursor.downField("type").as[String].flatMap { | ||
case "DeleteProduct" => | ||
hCursor.downField("index").as[Int].map(DeleteProduct.apply) | ||
case unknown => | ||
Left(DecodingFailure(s"Unknown type $unknown", hCursor.history)) | ||
} | ||
|
||
override def apply(callbackData: CallbackData): Json = callbackData match | ||
case DeleteProduct(index) => | ||
Json.obj(("type", Json.fromString("DeleteProduct")), ("index", Json.fromInt(index))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters