mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-12-27 22:18:51 +00:00
Can count the number of unread notifications
This commit is contained in:
parent
6b0363935e
commit
32aa7e7d1e
@ -37,4 +37,5 @@ pub mod survey_api;
|
||||
pub mod comment_api;
|
||||
pub mod res_create_post;
|
||||
pub mod posts_targets_api;
|
||||
pub mod res_create_comment;
|
||||
pub mod res_create_comment;
|
||||
pub mod res_number_unread_notifications;
|
16
src/api_data/res_number_unread_notifications.rs
Normal file
16
src/api_data/res_number_unread_notifications.rs
Normal 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 }
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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;
|
||||
|
14
src/controllers/notifications_controller.rs
Normal file
14
src/controllers/notifications_controller.rs
Normal 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))
|
||||
}
|
@ -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)),
|
||||
|
@ -13,4 +13,5 @@ pub mod conversations_helper;
|
||||
pub mod virtual_directory_helper;
|
||||
pub mod movies_helper;
|
||||
pub mod survey_helper;
|
||||
pub mod comments_helper;
|
||||
pub mod comments_helper;
|
||||
pub mod notifications_helper;
|
17
src/helpers/notifications_helper.rs
Normal file
17
src/helpers/notifications_helper.rs
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user