1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2025-06-20 16:35:17 +00:00

Add the method /notifications/count_all_news

This commit is contained in:
2020-07-10 13:31:40 +02:00
parent 32aa7e7d1e
commit 1eac896291
5 changed files with 57 additions and 2 deletions

View File

@ -2,13 +2,26 @@
//!
//! @author Pierre Hubert
use crate::api_data::res_count_all_unreads::ResCountAllUnread;
use crate::api_data::res_number_unread_notifications::ResNumberUnreadNotifications;
use crate::controllers::routes::RequestResult;
use crate::data::http_request_handler::HttpRequestHandler;
use crate::helpers::notifications_helper;
use crate::helpers::{conversations_helper, friends_helper, notifications_helper};
/// Count the number of unread notifications
pub fn count_unread(r: &mut HttpRequestHandler) -> RequestResult {
let number = notifications_helper::count_unread(r.user_id_ref()?)?;
r.set_response(ResNumberUnreadNotifications::new(number))
}
/// Count the number of unread notifications
pub fn count_all_news(r: &mut HttpRequestHandler) -> RequestResult {
let notifications = notifications_helper::count_unread(r.user_id_ref()?)?;
let conversations = conversations_helper::count_unread_for_user(r.user_id_ref()?)?;
let friends_requests = match r.post_bool_opt("friends_request", false) {
true => Some(friends_helper::count_requests(r.user_id_ref()?)?),
false => None
};
r.set_response(ResCountAllUnread::new(notifications, conversations as u64, friends_requests))
}

View File

@ -247,6 +247,8 @@ pub fn get_routes() -> Vec<Route> {
// Notifications controller
Route::post("/notifications/count_unread", Box::new(notifications_controller::count_unread)),
Route::post("/notifications/count_all_news", Box::new(notifications_controller::count_all_news)),
// Movies controller
Route::post("/movies/get_list", Box::new(movies_controller::get_list)),