Chapter 18: Change body of getAllHandler to return [User.Public]

When I attempt to make the change to:

return User.query(on: req).decode(data: User.Public.self).all()

I get an error that reads:
Argument labels ‘(data:)’ do not match any available overloads

Has something changed since the publication?

Thanks in advance

@0xtim Can you please help with this when you get a chance? Thank you - much appreciated! :]

I’ve managed to get the function to return [User.Public] by changing it to the following:

func list(_ req: Request) throws -> Future<[User.Public]> {
    var publicUsers = [User.Public]()
    return User.query(on: req).all()
        .map(to: [User.Public].self) { users in
            for user in users {
                publicUsers.append(user.convertToPublic())
            }
            return publicUsers
    }
}

This is obviously not nearly as nice as decoding the data returned from the query…

@axlroach Thank you for sharing your solution - much appreciated!

@axlroach

return User.query(on: req).decode(data: User.Public.self).all()

That statement works ok for me.
Take a look at your Package.swift file and see what version of fluent-postgresql.git you are using. It looks like that version of the decode function was added June 7, 2018 so you might need to update your Package.swift file and/or run “vapor update” to fetch the updated dependencies.

Have fun!

@axlroach just to confirm what @rcasey said it should definitely work with the Fluent release, make sure you dependencies are up to date and it should be good!