-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use candid::Principal; | ||
use ic_cdk::{caller, query}; | ||
|
||
use crate::{ | ||
repositories::{ChatSessionRepositoryImpl, FilesystemRepositoryImpl}, | ||
services::{ | ||
AdminService, AdminServiceImpl, ChatSessionService, ChatSessionServiceImpl, | ||
FilesystemServiceImpl, | ||
}, | ||
}; | ||
|
||
#[query] | ||
fn get_chat_sessions_count() -> u32 { | ||
let calling_principal = caller(); | ||
|
||
ChatSessionController::default().get_chat_sessions_count(calling_principal) | ||
} | ||
|
||
struct ChatSessionController<A: AdminService, C: ChatSessionService> { | ||
admin_service: A, | ||
chat_session_service: C, | ||
} | ||
|
||
impl Default | ||
for ChatSessionController< | ||
AdminServiceImpl, | ||
ChatSessionServiceImpl< | ||
ChatSessionRepositoryImpl, | ||
FilesystemServiceImpl<FilesystemRepositoryImpl>, | ||
>, | ||
> | ||
{ | ||
fn default() -> Self { | ||
Self::new( | ||
AdminServiceImpl::default(), | ||
ChatSessionServiceImpl::default(), | ||
) | ||
} | ||
} | ||
|
||
impl<A: AdminService, C: ChatSessionService> ChatSessionController<A, C> { | ||
fn new(admin_service: A, chat_session_service: C) -> Self { | ||
Self { | ||
admin_service, | ||
chat_session_service, | ||
} | ||
} | ||
|
||
fn get_chat_sessions_count(&self, calling_principal: Principal) -> u32 { | ||
self.admin_service | ||
.asset_caller_is_controller(&calling_principal); | ||
|
||
self.chat_session_service.get_chat_sessions_count() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
mod chat_session; | ||
mod http; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use candid::Principal; | ||
use ic_cdk::{api::is_controller, trap}; | ||
|
||
pub trait AdminService { | ||
fn asset_caller_is_controller(&self, calling_principal: &Principal); | ||
} | ||
|
||
pub struct AdminServiceImpl {} | ||
|
||
impl Default for AdminServiceImpl { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl AdminService for AdminServiceImpl { | ||
fn asset_caller_is_controller(&self, calling_principal: &Principal) { | ||
if !is_controller(calling_principal) { | ||
trap("caller is not a controller"); | ||
} | ||
} | ||
} | ||
|
||
impl AdminServiceImpl { | ||
fn new() -> Self { | ||
Self {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
mod admin_service; | ||
mod chat_session_service; | ||
mod filesystem_service; | ||
|
||
pub use admin_service::*; | ||
pub use chat_session_service::*; | ||
pub use filesystem_service::*; |