mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-20 06:47:15 +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
|
||||
= 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
|
||||
|
Loading…
Reference in New Issue
Block a user