json instances for DownloadEntitiesResponse

This commit is contained in:
Arya Irani 2022-05-26 19:40:30 -04:00
parent 535b8589b8
commit 461ac1f992

View File

@ -605,13 +605,25 @@ instance FromJSON DownloadEntitiesRequest where
data DownloadEntitiesResponse
= DownloadEntitiesSuccess DownloadEntities
| DownloadEntitiesNoReadPermission
| DownloadEntitiesNoReadPermission RepoName
data DownloadEntities = DownloadEntities
{ entities :: NEMap Hash (Entity Text Hash HashJWT)
}
deriving stock (Show, Eq, Ord)
instance ToJSON DownloadEntitiesResponse where
toJSON = \case
DownloadEntitiesSuccess entities -> jsonUnion "success" entities
DownloadEntitiesNoReadPermission repoName -> jsonUnion "no_read_permission" repoName
instance FromJSON DownloadEntitiesResponse where
parseJSON = Aeson.withObject "DownloadEntitiesResponse" \obj ->
obj .: "type" >>= Aeson.withText "type" \case
"success" -> DownloadEntitiesSuccess <$> obj .: "payload"
"no_read_permission" -> DownloadEntitiesNoReadPermission <$> obj .: "payload"
t -> failText $ "Unexpected DownloadEntitiesResponse type: " <> t
instance ToJSON DownloadEntities where
toJSON (DownloadEntities entities) =
object