Get only the number of inbox entries
This commit is contained in:
parent
6d81ab993b
commit
cceed381bd
@ -37,6 +37,26 @@ pub async fn get_list(auth: AuthExtractor, query: web::Query<GetInboxQuery>) ->
|
|||||||
Ok(HttpResponse::Ok().json(list))
|
Ok(HttpResponse::Ok().json(list))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Serialize)]
|
||||||
|
struct InboxCount {
|
||||||
|
count: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Count the number of inbox entries
|
||||||
|
pub async fn count_entries(auth: AuthExtractor, query: web::Query<GetInboxQuery>) -> HttpResult {
|
||||||
|
let mut list = inbox_service::get_list_user(auth.user_id()).await?;
|
||||||
|
|
||||||
|
list.retain(|entry| {
|
||||||
|
if !query.include_attached && entry.movement_id().is_some() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(HttpResponse::Ok().json(InboxCount { count: list.len() }))
|
||||||
|
}
|
||||||
|
|
||||||
/// Get a single inbox entry
|
/// Get a single inbox entry
|
||||||
pub async fn get_single(entry: InboxEntryInPath) -> HttpResult {
|
pub async fn get_single(entry: InboxEntryInPath) -> HttpResult {
|
||||||
Ok(HttpResponse::Ok().json(entry.as_ref()))
|
Ok(HttpResponse::Ok().json(entry.as_ref()))
|
||||||
|
@ -158,6 +158,10 @@ async fn main() -> std::io::Result<()> {
|
|||||||
// Inbox controller
|
// Inbox controller
|
||||||
.route("/api/inbox", web::post().to(inbox_controller::create))
|
.route("/api/inbox", web::post().to(inbox_controller::create))
|
||||||
.route("/api/inbox", web::get().to(inbox_controller::get_list))
|
.route("/api/inbox", web::get().to(inbox_controller::get_list))
|
||||||
|
.route(
|
||||||
|
"/api/inbox/count",
|
||||||
|
web::get().to(inbox_controller::count_entries),
|
||||||
|
)
|
||||||
.route(
|
.route(
|
||||||
"/api/inbox/{inbox_id}",
|
"/api/inbox/{inbox_id}",
|
||||||
web::get().to(inbox_controller::get_single),
|
web::get().to(inbox_controller::get_single),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user