-
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.
Merge pull request #5 from KaioFelps/dev
Added article tags and refactored some code
- Loading branch information
Showing
62 changed files
with
1,571 additions
and
519 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,26 @@ | ||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.10 | ||
use sea_orm::entity::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)] | ||
#[sea_orm(table_name = "article_tag")] | ||
pub struct Model { | ||
#[sea_orm(primary_key)] | ||
pub id: i32, | ||
pub value: String, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] | ||
pub enum Relation { | ||
#[sea_orm(has_many = "super::article::Entity")] | ||
Article, | ||
} | ||
|
||
impl Related<super::article::Entity> for Entity { | ||
fn to() -> RelationDef { | ||
Relation::Article.def() | ||
} | ||
} | ||
|
||
impl ActiveModelBehavior for ActiveModel {} |
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
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
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
84 changes: 84 additions & 0 deletions
84
migration/src/m20240719_034959_create_article_tag_table_and_add_tag_to_article.rs
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,84 @@ | ||
use sea_orm_migration::prelude::*; | ||
|
||
#[derive(DeriveMigrationName)] | ||
pub struct Migration; | ||
|
||
#[async_trait::async_trait] | ||
impl MigrationTrait for Migration { | ||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager | ||
.create_table( | ||
Table::create() | ||
.table(ArticleTag::Table) | ||
.if_not_exists() | ||
.col( | ||
ColumnDef::new(ArticleTag::Id) | ||
.integer() | ||
.not_null() | ||
.auto_increment() | ||
.primary_key(), | ||
) | ||
.col(ColumnDef::new(ArticleTag::Value).string().not_null().unique_key()) | ||
.to_owned(), | ||
).await?; | ||
|
||
manager.alter_table( | ||
Table::alter() | ||
.table(Article::Table) | ||
.add_column( | ||
ColumnDef::new(Article::TagId) | ||
.integer() | ||
) | ||
.add_column( | ||
ColumnDef::new(Article::TagValue).string() | ||
) | ||
.add_foreign_key(TableForeignKey::new().name("fk-article-article-tag") | ||
.from_tbl(Article::Table) | ||
.from_col(Article::TagId) | ||
.to_tbl(ArticleTag::Table) | ||
.to_col(ArticleTag::Id) | ||
.on_delete(ForeignKeyAction::SetNull.to_owned() | ||
)) | ||
.to_owned() | ||
).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { | ||
manager.drop_foreign_key( | ||
ForeignKeyDropStatement::new() | ||
.table(Article::Table) | ||
.name("fk-article-article-tag") | ||
.to_owned() | ||
).await?; | ||
|
||
manager | ||
.drop_table(Table::drop().table(ArticleTag::Table).to_owned()) | ||
.await?; | ||
|
||
manager.alter_table( | ||
Table::alter() | ||
.table(Article::Table) | ||
.drop_column(Article::TagValue) | ||
.drop_column(Article::TagId) | ||
.to_owned() | ||
).await?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum ArticleTag { | ||
Table, | ||
Id, | ||
Value, | ||
} | ||
|
||
#[derive(DeriveIden)] | ||
enum Article { | ||
Table, | ||
TagId, | ||
TagValue | ||
} |
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,42 @@ | ||
pub struct DraftArticleTag { | ||
value: String | ||
} | ||
|
||
impl DraftArticleTag { | ||
pub fn new(value: String) -> Self { | ||
Self { | ||
value | ||
} | ||
} | ||
|
||
pub fn value(&self) -> &String { | ||
&self.value | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct ArticleTag { | ||
id: i32, | ||
value: String | ||
} | ||
|
||
impl ArticleTag { | ||
pub fn new_from_existing(id: i32, value: String) -> Self { | ||
Self { | ||
id, | ||
value, | ||
} | ||
} | ||
|
||
pub fn id(&self) -> i32 { | ||
self.id | ||
} | ||
|
||
pub fn value(&self) -> &String { | ||
&self.value | ||
} | ||
|
||
pub fn set_value(&mut self, value: String) -> () { | ||
self.value = value; | ||
} | ||
} |
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
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
Oops, something went wrong.