Here is the json I want to return from the vapor server:
{
“getCollectionsResult”: [ {
“__type”: “CollectionSet:#MobileServices”,
“operationSuccess”: true,
“SetName”: “Spring 2 2018”
},
{
“__type”: “CollectionSet:#MobileServices”,
“operationSuccess”: true,
“SetName”: “Summer 1 2018”
}
]
}
I tried to model using:
struct CollectionResultsResponse: Content {
var id: Int?
let getCollectionsResult: [CollectionSet]
}
final class CollectionSet: Content {
var __type: String
var operationSuccess: Bool
var SetName: String
init(__type: String, operationSuccess: Bool, SetName: String) {
self.__type = __type
self.operationSuccess = operationSuccess
self.SetName = SetName
}
}
func getResponseHandler(req: Request) throws → Future {
return try CollectionSet.query(on: req).all().flatMap { collectionSets in
return CollectionResultsResponse(from: collectionSets)
}
}
Once I get this to work, I’ll need to decide the best way to load the data in the database (or to create the records with REST and vapor code). I’m sorry I’m not giving you much to go on. I’ve done all the chapters in the tutorial and that’s woking fine, but this json is more complex. I’m just not seeing how to get started on this.