Implementing GET users
Now, let's implement get_users()
. Here is a quick reminder of what the function looked like in the previous chapter:
#[get("/users?<_pagination>", format = "text/html")]
pub async fn get_users(
mut _db: Connection<DBConnection>,
_pagination: Option<Pagination>,
) -> HtmlResponse {
todo!("will implement later")
}
As before, we should prepare the routines we're going to use:
- In
src/models/user.rs
, create a method calledfind_all
, as in the following:use super::pagination::{Pagination}; use crate::fairings::db::DBConnection; use rocket_db_pools::Connection; use rocket_db_pools::sqlx::{Acquire, FromRow, PgConnection}; ... impl User { ... pub async fn find_all( db: &mut Connection<DBConnection>, &...