refactor: Rename in_chat_requests table to incoming_chat

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb 2024-07-28 10:36:05 +03:00
parent bc00ac08b1
commit 0274444434
Signed by: awiteb
GPG key ID: 3F6B55640AA6682F
9 changed files with 38 additions and 41 deletions

View file

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://gnu.org/licenses/agpl-3.0>. // along with this program. If not, see <https://gnu.org/licenses/agpl-3.0>.
//! Database extension for the `in_chat_requests` table. //! Database extension for the `incoming_chat` table.
use chrono::Utc; use chrono::Utc;
use oxidetalis_core::types::PublicKey; use oxidetalis_core::types::PublicKey;
@ -23,8 +23,8 @@ use sea_orm::{sea_query::OnConflict, DatabaseConnection};
use crate::errors::ServerResult; use crate::errors::ServerResult;
/// Extension trait for the `in_chat_requests` table. /// Extension trait for the `incoming_chat` table.
pub trait InChatRequestsExt { pub trait IncomingChatExt {
/// Save the chat request in the recipient table /// Save the chat request in the recipient table
async fn save_in_chat_request( async fn save_in_chat_request(
&self, &self,
@ -33,26 +33,23 @@ pub trait InChatRequestsExt {
) -> ServerResult<()>; ) -> ServerResult<()>;
} }
impl InChatRequestsExt for DatabaseConnection { impl IncomingChatExt for DatabaseConnection {
#[logcall::logcall] #[logcall::logcall]
async fn save_in_chat_request( async fn save_in_chat_request(
&self, &self,
sender: &PublicKey, sender: &PublicKey,
recipient: &UserModel, recipient: &UserModel,
) -> ServerResult<()> { ) -> ServerResult<()> {
InChatRequestsEntity::insert(InChatRequestsActiveModel { IncomingChatEntity::insert(IncomingChatActiveModel {
recipient_id: Set(recipient.id), recipient_id: Set(recipient.id),
sender: Set(*sender), sender: Set(*sender),
in_on: Set(Utc::now()), in_on: Set(Utc::now()),
..Default::default() ..Default::default()
}) })
.on_conflict( .on_conflict(
OnConflict::columns([ OnConflict::columns([IncomingChatColumn::RecipientId, IncomingChatColumn::Sender])
InChatRequestsColumn::RecipientId, .do_nothing()
InChatRequestsColumn::Sender, .to_owned(),
])
.do_nothing()
.to_owned(),
) )
.exec(self) .exec(self)
.await?; .await?;

View file

@ -16,12 +16,12 @@
//! Database trait extensions. //! Database trait extensions.
mod in_chat_requests; mod incoming_chat;
mod out_chat_requests; mod out_chat_requests;
mod user; mod user;
mod user_status; mod user_status;
pub use in_chat_requests::*; pub use incoming_chat::*;
pub use out_chat_requests::*; pub use out_chat_requests::*;
pub use user::*; pub use user::*;
pub use user_status::*; pub use user_status::*;

View file

@ -20,7 +20,7 @@ use oxidetalis_core::types::PublicKey;
use oxidetalis_entities::prelude::*; use oxidetalis_entities::prelude::*;
use sea_orm::DatabaseConnection; use sea_orm::DatabaseConnection;
use crate::database::InChatRequestsExt; use crate::database::IncomingChatExt;
use crate::errors::ServerError; use crate::errors::ServerError;
use crate::extensions::OnlineUsersExt; use crate::extensions::OnlineUsersExt;
use crate::{ use crate::{

View file

@ -19,7 +19,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
//! Entity for `in_chat_requests` table //! Entity for `incoming_chat` table
use chrono::Utc; use chrono::Utc;
use oxidetalis_core::types::PublicKey; use oxidetalis_core::types::PublicKey;
@ -28,7 +28,7 @@ use sea_orm::entity::prelude::*;
use crate::prelude::*; use crate::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "in_chat_requests")] #[sea_orm(table_name = "incoming_chat")]
pub struct Model { pub struct Model {
#[sea_orm(primary_key)] #[sea_orm(primary_key)]
pub id: UserId, pub id: UserId,

View file

@ -21,7 +21,7 @@
#![doc = include_str!("../README.md")] #![doc = include_str!("../README.md")]
pub mod incoming_chat_requests; pub mod incoming_chat;
pub mod outgoing_chat_requests; pub mod outgoing_chat_requests;
pub mod prelude; pub mod prelude;
pub mod users; pub mod users;

View file

@ -40,11 +40,11 @@ pub use sea_orm::{
/// User ID type /// User ID type
pub type UserId = i64; pub type UserId = i64;
pub use super::incoming_chat_requests::{ pub use super::incoming_chat::{
ActiveModel as InChatRequestsActiveModel, ActiveModel as IncomingChatActiveModel,
Column as InChatRequestsColumn, Column as IncomingChatColumn,
Entity as InChatRequestsEntity, Entity as IncomingChatEntity,
Model as InChatRequestsModel, Model as IncomingChatModel,
}; };
pub use super::outgoing_chat_requests::{ pub use super::outgoing_chat_requests::{
ActiveModel as OutChatRequestsActiveModel, ActiveModel as OutChatRequestsActiveModel,

View file

@ -39,17 +39,17 @@ pub struct Model {
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation { pub enum Relation {
#[sea_orm(has_many = "InChatRequestsEntity")] #[sea_orm(has_many = "IncomingChatEntity")]
InChatRequests, IncomingChat,
#[sea_orm(has_many = "OutChatRequestsEntity")] #[sea_orm(has_many = "OutChatRequestsEntity")]
OutChatRequests, OutChatRequests,
#[sea_orm(has_many = "UsersStatusEntity")] #[sea_orm(has_many = "UsersStatusEntity")]
UsersStatus, UsersStatus,
} }
impl Related<InChatRequestsEntity> for Entity { impl Related<IncomingChatEntity> for Entity {
fn to() -> RelationDef { fn to() -> RelationDef {
Relation::InChatRequests.def() Relation::IncomingChat.def()
} }
} }

View file

@ -19,8 +19,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE. // SOFTWARE.
//! Migration to create the `in_chat_requests` table, a table for incoming chat //! Migration to create the `incoming_chat` table, a table for incoming chat
//! requests from other users //! requests and responses from other users
use sea_orm_migration::prelude::*; use sea_orm_migration::prelude::*;
@ -35,31 +35,31 @@ impl MigrationTrait for Migration {
manager manager
.create_table( .create_table(
Table::create() Table::create()
.table(InChatRequests::Table) .table(IncomingChat::Table)
.if_not_exists() .if_not_exists()
.col( .col(
ColumnDef::new(InChatRequests::Id) ColumnDef::new(IncomingChat::Id)
.big_integer() .big_integer()
.not_null() .not_null()
.auto_increment() .auto_increment()
.primary_key(), .primary_key(),
) )
.col( .col(
ColumnDef::new(InChatRequests::RecipientId) ColumnDef::new(IncomingChat::RecipientId)
.big_integer() .big_integer()
.not_null(), .not_null(),
) )
.foreign_key( .foreign_key(
ForeignKey::create() ForeignKey::create()
.name("fk-in_chat_requests-users") .name("fk-incoming_chat-users")
.from(InChatRequests::Table, InChatRequests::RecipientId) .from(IncomingChat::Table, IncomingChat::RecipientId)
.to(Users::Table, Users::Id) .to(Users::Table, Users::Id)
.on_update(ForeignKeyAction::NoAction) .on_update(ForeignKeyAction::NoAction)
.on_delete(ForeignKeyAction::Cascade), .on_delete(ForeignKeyAction::Cascade),
) )
.col(ColumnDef::new(InChatRequests::Sender).binary().not_null()) .col(ColumnDef::new(IncomingChat::Sender).binary().not_null())
.col( .col(
ColumnDef::new(InChatRequests::InOn) ColumnDef::new(IncomingChat::InOn)
.timestamp_with_time_zone() .timestamp_with_time_zone()
.not_null(), .not_null(),
) )
@ -71,9 +71,9 @@ impl MigrationTrait for Migration {
Index::create() Index::create()
.if_not_exists() .if_not_exists()
.name("sep_request") .name("sep_request")
.table(InChatRequests::Table) .table(IncomingChat::Table)
.col(InChatRequests::RecipientId) .col(IncomingChat::RecipientId)
.col(InChatRequests::Sender) .col(IncomingChat::Sender)
.unique() .unique()
.to_owned(), .to_owned(),
) )
@ -82,7 +82,7 @@ impl MigrationTrait for Migration {
} }
#[derive(DeriveIden)] #[derive(DeriveIden)]
enum InChatRequests { enum IncomingChat {
Table, Table,
Id, Id,
RecipientId, RecipientId,

View file

@ -24,7 +24,7 @@
use sea_orm_migration::prelude::*; use sea_orm_migration::prelude::*;
pub use sea_orm_migration::MigratorTrait; pub use sea_orm_migration::MigratorTrait;
mod create_incoming_chat_requests_table; mod create_incoming_chat_table;
mod create_outgoing_chat_requests_table; mod create_outgoing_chat_requests_table;
mod create_users_status; mod create_users_status;
mod create_users_table; mod create_users_table;
@ -36,7 +36,7 @@ impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> { fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![ vec![
Box::new(create_users_table::Migration), Box::new(create_users_table::Migration),
Box::new(create_incoming_chat_requests_table::Migration), Box::new(create_incoming_chat_table::Migration),
Box::new(create_outgoing_chat_requests_table::Migration), Box::new(create_outgoing_chat_requests_table::Migration),
Box::new(create_users_status::Migration), Box::new(create_users_status::Migration),
] ]