-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
417304e
commit e45afd7
Showing
7 changed files
with
98 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
use async_trait::async_trait; | ||
use sea_orm::DbErr; | ||
|
||
pub type Collaboration = crate::domain::collaboration::model::Model; | ||
|
||
pub struct NewCollaboration { | ||
pub task_id: i32, | ||
pub user_id: i32 | ||
} | ||
|
||
#[async_trait] | ||
pub trait CollaborationRepository { | ||
fn find_task_collaborators(task_id: i32) -> Vec<Collaboration>; | ||
fn find_user_collaborations(user_id: i32) -> Vec<Collaboration>; | ||
fn add(collaboration: NewCollaboration) -> Collaboration; | ||
fn remove(collaboration_id: i32) -> bool; | ||
fn find_task_collaborators(&self, task_id: i32) -> Result<Vec<Collaboration>, DbErr>; | ||
fn find_user_collaborations(&self, user_id: i32) -> Result<Vec<Collaboration>, DbErr>; | ||
fn add(&self, collaboration: NewCollaboration) -> Result<Collaboration, DbErr>; | ||
fn remove(&self, collaboration_id: i32) -> Result<bool, DbErr>; | ||
} |
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,14 +1,10 @@ | ||
pub type Notification = crate::domain::notification::model::Model; | ||
|
||
pub struct NewNotification { | ||
pub user_id: Option<i32>, | ||
pub task_id: Option<i32>, | ||
pub message: String, | ||
pub read: bool, | ||
} | ||
use async_trait::async_trait; | ||
use sea_orm::DbErr; | ||
use super::model::{ Model as Notification }; | ||
|
||
#[async_trait] | ||
pub trait NotificationRepository { | ||
fn find_notifications(user_id: i32, page_number: u8) -> Vec<Notification>; | ||
fn create_notification(notification: NewNotification) -> Notification; | ||
fn mark_notification_as_read(notification_id: i32) -> bool; | ||
} | ||
async fn find_notifications(&self, user_id: i32, page_number: u8) -> Result<Vec<Notification>, DbErr>; | ||
async fn create_notification(&self, notification: Notification) -> Result<Notification, DbErr>; | ||
async fn mark_notification_as_read(&self, notification_id: i32) -> Result<Notification, DbErr>; | ||
} |
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,34 @@ | ||
use sea_orm::DatabaseConnection; | ||
use async_trait::async_trait; | ||
use sea_orm::DbErr; | ||
use crate::domain::collaboration::repository::Collaboration; | ||
use crate::domain::collaboration::repository::CollaborationRepository; | ||
|
||
pub struct CollaborationRepo { | ||
db: DatabaseConnection | ||
} | ||
|
||
impl CollaborationRepo { | ||
fn _new(db: DatabaseConnection) -> Self { | ||
Self { db } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl CollaborationRepository for CollaborationRepo { | ||
fn find_task_collaborators(&self, task_id: i32) -> Result<Vec<Collaboration>, DbErr> { | ||
todo!() | ||
} | ||
|
||
fn find_user_collaborations(&self, user_id: i32) -> Result<Vec<Collaboration>, DbErr> { | ||
todo!() | ||
} | ||
|
||
fn add(&self, collaboration: crate::domain::collaboration::repository::NewCollaboration) -> Result<Collaboration, DbErr> { | ||
todo!() | ||
} | ||
|
||
fn remove(&self, collaboration_id: i32) -> Result<bool, DbErr> { | ||
todo!() | ||
} | ||
} |
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,45 @@ | ||
use sea_orm::{ActiveModelTrait, ColumnTrait, DatabaseConnection, DbErr, EntityTrait, PaginatorTrait, QueryFilter, Set}; | ||
use async_trait::async_trait; | ||
use crate::domain::notification::model::{Entity as NotificationEntity, Model as Notification, Column, ActiveModel}; | ||
use crate::domain::notification::repository::NotificationRepository; | ||
|
||
pub struct NotificationRepo { | ||
db: DatabaseConnection, | ||
} | ||
|
||
impl NotificationRepo { | ||
pub fn _new(db: DatabaseConnection) -> Self { | ||
Self { db } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl NotificationRepository for NotificationRepo { | ||
async fn find_notifications(&self, user_id: i32, page_number: u8) -> Result<Vec<crate::domain::notification::model::Model>, sea_orm::DbErr> { | ||
NotificationEntity::find() | ||
.filter(Column::UserId.eq(user_id)) | ||
.paginate(&self.db, page_number as u64) | ||
.fetch() | ||
.await | ||
} | ||
|
||
async fn create_notification(&self, notification: Notification) -> Result<crate::domain::notification::model::Model, sea_orm::DbErr> { | ||
let new_notification = ActiveModel { | ||
user_id: Set(notification.user_id), | ||
task_id: Set(notification.task_id), | ||
message: Set(notification.message), | ||
..Default::default() | ||
}; | ||
new_notification.insert(&self.db).await | ||
} | ||
|
||
async fn mark_notification_as_read(&self, notification_id: i32) -> Result<Notification, sea_orm::DbErr> { | ||
let notification_record = NotificationEntity::find_by_id(notification_id).one(&self.db).await?; | ||
let mut notification: ActiveModel = notification_record.ok_or(DbErr::RecordNotFound("No Such a Notification".to_string()))?.into(); | ||
|
||
notification.read = Set(true); | ||
|
||
notification.update(&self.db).await | ||
|
||
} | ||
} |
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