Hi,
Similar to Modeling complex JSON topic, I have the next Model on my project:
final class Colegio: Codable {
var id: UUID?
var nombre: String
var codigoMaestro: String?
var rutaLogo: String?
var logo: String
}
In my controller, I have the next struct and function, which works correctly:
// WS para devolver relación de colegios
func colegiosHandler( _ req: Request) throws → Future<[ColegiosData]> {
return Colegio.query(on: req).decode(data: ColegiosData.self).all()
}
struct ColegiosData: Content {
let id: UUID
let nombre: String
let rutaLogo: String
}
What I want is that my web service returns the “id” property, but mapped with the codigoMaestro of my Model. I mean:
nombre = “Colegio”
rutaLogo = “Ruta al logo”
id = “Código del maestro”
It is possible to do this?
Thanks in advance!
Fran