diff --git a/crates/app/src/routes/api/v1/mod.rs b/crates/app/src/routes/api/v1/mod.rs index a980caa..3b99781 100644 --- a/crates/app/src/routes/api/v1/mod.rs +++ b/crates/app/src/routes/api/v1/mod.rs @@ -124,4 +124,5 @@ pub struct UpdateJournalEntryContext { pub struct CreateReaction { pub asset: usize, pub asset_type: AssetType, + pub is_like: bool, } diff --git a/crates/app/src/routes/api/v1/reactions.rs b/crates/app/src/routes/api/v1/reactions.rs index 9599ef8..915c972 100644 --- a/crates/app/src/routes/api/v1/reactions.rs +++ b/crates/app/src/routes/api/v1/reactions.rs @@ -37,7 +37,12 @@ pub async fn create_request( }; match data - .create_reaction(Reaction::new(user.id, req.asset, req.asset_type)) + .create_reaction(Reaction::new( + user.id, + req.asset, + req.asset_type, + req.is_like, + )) .await { Ok(_) => Json(ApiReturn { diff --git a/crates/core/src/database/drivers/sql/create_reactions.sql b/crates/core/src/database/drivers/sql/create_reactions.sql index 4b4b004..34bda2e 100644 --- a/crates/core/src/database/drivers/sql/create_reactions.sql +++ b/crates/core/src/database/drivers/sql/create_reactions.sql @@ -3,5 +3,6 @@ CREATE TABLE IF NOT EXISTS reactions ( created INTEGER NOT NULL, owner INTEGER NOT NULL, asset INTEGER NOT NULL, - asset_type TEXT NOT NULL + asset_type TEXT NOT NULL, + is_like INTEGER NOT NULL ) diff --git a/crates/core/src/database/reactions.rs b/crates/core/src/database/reactions.rs index 0345ce9..f196c51 100644 --- a/crates/core/src/database/reactions.rs +++ b/crates/core/src/database/reactions.rs @@ -22,6 +22,7 @@ impl DataManager { owner: get!(x->2(u64)) as usize, asset: get!(x->3(u64)) as usize, asset_type: serde_json::from_str(&get!(x->4(String))).unwrap(), + is_like: if get!(x->5(u8)) == 1 { true } else { false }, } } @@ -64,13 +65,14 @@ impl DataManager { let res = execute!( &conn, - "INSERT INTO reactions VALUES ($1, $2, $3, $4, $5", + "INSERT INTO reactions VALUES ($1, $2, $3, $4, $5, $6)", &[ &data.id.to_string().as_str(), &data.created.to_string().as_str(), &data.owner.to_string().as_str(), &data.asset.to_string().as_str(), &serde_json::to_string(&data.asset_type).unwrap().as_str(), + &(if data.is_like { 1 } else { 0 }).to_string().as_str() ] ); diff --git a/crates/core/src/model/reactions.rs b/crates/core/src/model/reactions.rs index 88b8b4a..697f72d 100644 --- a/crates/core/src/model/reactions.rs +++ b/crates/core/src/model/reactions.rs @@ -15,11 +15,12 @@ pub struct Reaction { pub owner: usize, pub asset: usize, pub asset_type: AssetType, + pub is_like: bool, } impl Reaction { /// Create a new [`Reaction`]. - pub fn new(owner: usize, asset: usize, asset_type: AssetType) -> Self { + pub fn new(owner: usize, asset: usize, asset_type: AssetType, is_like: bool) -> Self { Self { id: AlmostSnowflake::new(1234567890) .to_string() @@ -29,6 +30,7 @@ impl Reaction { owner, asset, asset_type, + is_like, } } }