Get only the number of inbox entries
This commit is contained in:
		@@ -37,6 +37,26 @@ pub async fn get_list(auth: AuthExtractor, query: web::Query<GetInboxQuery>) ->
 | 
			
		||||
    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
 | 
			
		||||
pub async fn get_single(entry: InboxEntryInPath) -> HttpResult {
 | 
			
		||||
    Ok(HttpResponse::Ok().json(entry.as_ref()))
 | 
			
		||||
 
 | 
			
		||||
@@ -158,6 +158,10 @@ async fn main() -> std::io::Result<()> {
 | 
			
		||||
            // Inbox controller
 | 
			
		||||
            .route("/api/inbox", web::post().to(inbox_controller::create))
 | 
			
		||||
            .route("/api/inbox", web::get().to(inbox_controller::get_list))
 | 
			
		||||
            .route(
 | 
			
		||||
                "/api/inbox/count",
 | 
			
		||||
                web::get().to(inbox_controller::count_entries),
 | 
			
		||||
            )
 | 
			
		||||
            .route(
 | 
			
		||||
                "/api/inbox/{inbox_id}",
 | 
			
		||||
                web::get().to(inbox_controller::get_single),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user