mirror of
https://github.com/unisonweb/unison.git
synced 2024-11-10 11:15:08 +03:00
json instances for DownloadEntitiesResponse
This commit is contained in:
parent
535b8589b8
commit
461ac1f992
@ -605,13 +605,25 @@ instance FromJSON DownloadEntitiesRequest where
|
|||||||
|
|
||||||
data DownloadEntitiesResponse
|
data DownloadEntitiesResponse
|
||||||
= DownloadEntitiesSuccess DownloadEntities
|
= DownloadEntitiesSuccess DownloadEntities
|
||||||
| DownloadEntitiesNoReadPermission
|
| DownloadEntitiesNoReadPermission RepoName
|
||||||
|
|
||||||
data DownloadEntities = DownloadEntities
|
data DownloadEntities = DownloadEntities
|
||||||
{ entities :: NEMap Hash (Entity Text Hash HashJWT)
|
{ entities :: NEMap Hash (Entity Text Hash HashJWT)
|
||||||
}
|
}
|
||||||
deriving stock (Show, Eq, Ord)
|
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
|
instance ToJSON DownloadEntities where
|
||||||
toJSON (DownloadEntities entities) =
|
toJSON (DownloadEntities entities) =
|
||||||
object
|
object
|
||||||
|
Loading…
Reference in New Issue
Block a user