refactor: Use pagination directly as an argument

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb 2024-07-18 10:59:29 +03:00
parent d0d048c135
commit ccc0c2954b
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F

View file

@ -22,7 +22,6 @@ use salvo::{
oapi::{endpoint, extract::JsonBody}, oapi::{endpoint, extract::JsonBody},
writing::Json, writing::Json,
Depot, Depot,
Extractible,
Request, Request,
Router, Router,
Writer, Writer,
@ -88,13 +87,13 @@ pub async fn register(
tags("User"), tags("User"),
responses( responses(
(status_code = 200, description = "Returns whitelisted users", content_type = "application/json", body = Vec<WhiteListedUser>), (status_code = 200, description = "Returns whitelisted users", content_type = "application/json", body = Vec<WhiteListedUser>),
(status_code = 403, description = "Not registered user, must register first", content_type = "application/json", body = MessageSchema), (status_code = 400, description = "Wrong query parameter", content_type = "application/json", body = MessageSchema),
(status_code = 401, description = "The entered signature or public key is invalid", content_type = "application/json", body = MessageSchema), (status_code = 401, description = "The entered signature or public key is invalid", content_type = "application/json", body = MessageSchema),
(status_code = 403, description = "Not registered user, must register first", content_type = "application/json", body = MessageSchema),
(status_code = 429, description = "Too many requests", content_type = "application/json", body = MessageSchema), (status_code = 429, description = "Too many requests", content_type = "application/json", body = MessageSchema),
(status_code = 500, description = "Internal server error", content_type = "application/json", body = MessageSchema), (status_code = 500, description = "Internal server error", content_type = "application/json", body = MessageSchema),
), ),
parameters( parameters(
Pagination,
("X-OTMP-PUBLIC" = PublicKey, Header, description = "Public key of the sender"), ("X-OTMP-PUBLIC" = PublicKey, Header, description = "Public key of the sender"),
("X-OTMP-SIGNATURE" = Signature, Header, description = "Signature of the request"), ("X-OTMP-SIGNATURE" = Signature, Header, description = "Signature of the request"),
), ),
@ -102,8 +101,8 @@ pub async fn register(
async fn user_whitelist( async fn user_whitelist(
req: &mut Request, req: &mut Request,
depot: &mut Depot, depot: &mut Depot,
pagination: Pagination,
) -> ApiResult<Json<Vec<WhiteListedUser>>> { ) -> ApiResult<Json<Vec<WhiteListedUser>>> {
let pagination = Pagination::extract(req).await?;
let conn = depot.db_conn(); let conn = depot.db_conn();
let user = conn let user = conn
.get_user_by_pubk( .get_user_by_pubk(
@ -127,13 +126,13 @@ async fn user_whitelist(
tags("User"), tags("User"),
responses( responses(
(status_code = 200, description = "Returns blacklisted users", content_type = "application/json", body = Vec<BlackListedUser>), (status_code = 200, description = "Returns blacklisted users", content_type = "application/json", body = Vec<BlackListedUser>),
(status_code = 403, description = "Not registered user, must register first", content_type = "application/json", body = MessageSchema), (status_code = 400, description = "Wrong query parameter", content_type = "application/json", body = MessageSchema),
(status_code = 401, description = "The entered signature or public key is invalid", content_type = "application/json", body = MessageSchema), (status_code = 401, description = "The entered signature or public key is invalid", content_type = "application/json", body = MessageSchema),
(status_code = 403, description = "Not registered user, must register first", content_type = "application/json", body = MessageSchema),
(status_code = 429, description = "Too many requests", content_type = "application/json", body = MessageSchema), (status_code = 429, description = "Too many requests", content_type = "application/json", body = MessageSchema),
(status_code = 500, description = "Internal server error", content_type = "application/json", body = MessageSchema), (status_code = 500, description = "Internal server error", content_type = "application/json", body = MessageSchema),
), ),
parameters( parameters(
Pagination,
("X-OTMP-PUBLIC" = PublicKey, Header, description = "Public key of the sender"), ("X-OTMP-PUBLIC" = PublicKey, Header, description = "Public key of the sender"),
("X-OTMP-SIGNATURE" = Signature, Header, description = "Signature of the request"), ("X-OTMP-SIGNATURE" = Signature, Header, description = "Signature of the request"),
), ),
@ -141,8 +140,8 @@ async fn user_whitelist(
async fn user_blacklist( async fn user_blacklist(
req: &mut Request, req: &mut Request,
depot: &mut Depot, depot: &mut Depot,
pagination: Pagination,
) -> ApiResult<Json<Vec<BlackListedUser>>> { ) -> ApiResult<Json<Vec<BlackListedUser>>> {
let pagination = Pagination::extract(req).await?;
let conn = depot.db_conn(); let conn = depot.db_conn();
let user = conn let user = conn
.get_user_by_pubk( .get_user_by_pubk(