1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 21:39:21 +00:00

Can count the number of unread notifications

This commit is contained in:
Pierre HUBERT 2020-07-10 12:55:50 +02:00
parent 6b0363935e
commit 32aa7e7d1e
8 changed files with 58 additions and 3 deletions

View File

@ -38,3 +38,4 @@ pub mod comment_api;
pub mod res_create_post;
pub mod posts_targets_api;
pub mod res_create_comment;
pub mod res_number_unread_notifications;

View File

@ -0,0 +1,16 @@
//! # Number of unread notifications
//!
//! @author Pierre Hubert
use serde::Serialize;
#[derive(Serialize)]
pub struct ResNumberUnreadNotifications {
number: u64
}
impl ResNumberUnreadNotifications {
pub fn new(number: u64) -> ResNumberUnreadNotifications {
ResNumberUnreadNotifications { number }
}
}

View File

@ -52,6 +52,9 @@ pub mod database_tables_names {
/// Comments table
pub const COMMENTS_TABLE: &str = "commentaires";
/// Notifications table
pub const NOTIFICATIONS_TABLE: &str = "comunic_notifications";
}
/// The account image to show for user who do not have any

View File

@ -12,5 +12,6 @@ pub mod posts_controller;
pub mod comments_controller;
pub mod likes_controller;
pub mod surveys_controller;
pub mod notifications_controller;
pub mod movies_controller;
pub mod virtual_directory_controller;

View File

@ -0,0 +1,14 @@
//! # Notifications controller
//!
//! @author Pierre Hubert
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;
/// 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))
}

View File

@ -1,6 +1,6 @@
use std::error::Error;
use crate::controllers::{account_controller, comments_controller, conversations_controller, friends_controller, groups_controller, likes_controller, movies_controller, posts_controller, search_controller, server_controller, surveys_controller, user_controller, virtual_directory_controller};
use crate::controllers::{account_controller, comments_controller, conversations_controller, friends_controller, groups_controller, likes_controller, movies_controller, notifications_controller, posts_controller, search_controller, server_controller, surveys_controller, user_controller, virtual_directory_controller};
use crate::controllers::routes::Method::{GET, POST};
use crate::data::http_request_handler::HttpRequestHandler;
@ -244,6 +244,8 @@ pub fn get_routes() -> Vec<Route> {
Route::post("/surveys/block_new_choices_creation", Box::new(surveys_controller::block_new_choices_creation)),
// Notifications controller
Route::post("/notifications/count_unread", Box::new(notifications_controller::count_unread)),
// Movies controller
Route::post("/movies/get_list", Box::new(movies_controller::get_list)),

View File

@ -14,3 +14,4 @@ pub mod virtual_directory_helper;
pub mod movies_helper;
pub mod survey_helper;
pub mod comments_helper;
pub mod notifications_helper;

View File

@ -0,0 +1,17 @@
//! # Notifications helper
//!
//! @author Pierre Hubert
use crate::constants::database_tables_names::NOTIFICATIONS_TABLE;
use crate::data::error::ResultBoxError;
use crate::data::user::UserID;
use crate::helpers::database;
/// Count the number of unread notifications
pub fn count_unread(user_id: &UserID) -> ResultBoxError<u64> {
database::QueryInfo::new(NOTIFICATIONS_TABLE)
.cond_user_id("dest_user_id", user_id)
.cond_legacy_bool("seen", false)
.exec_count()
.map(|c| c as u64)
}