You mention that ‘‘extension User: Parameter {}’’ should be included in the UserController.swift file.
What is the logic behind putting it there as opposed to the User.swift model file?
@kidrong that extension can actually go anywhere in that module. From a design point of view it can be helpful to put it in the file where it is required (ie where you use the parameter)
Yes it seems more powerful, but the syntax lacks simplicity. It becomes messy in no time, especially inside the put and delete handler. This should be abstracted away
Or maybe this is just because flatMap is confusing when we are used to another usage.
But once we understand the logic, it gets better.
@lashkari at the bottom of the AcronymsController.swift you should have extension Acronym: Parameter {}? If not try adding that in and see if it fixes it
in the video you said parameter call returns a future and we cannot call delete on future itself. but when i try this it works fine. Is it wrong this way ?
@maclacerda there is a better update mechanism planned at some point but for now you need another approach. You could make it optional, but you may not want this in your model. Another way to do this is to create an AcronymUpdateDate object that looks like:
struct AcronymUpdateData: Content {
let short: String?
let long: String?
}
Then you can decode it and check each thing:
let updateData = try req.content.decode(AcronymUpdateData.self)
if let newShort = udpateData.short {
existingAcronym.short = newShort
}