add: store is_like on reactions

This commit is contained in:
trisua 2025-03-24 22:49:15 -04:00
parent 382e3bc7a6
commit 0ea6b25138
5 changed files with 15 additions and 4 deletions

View file

@ -124,4 +124,5 @@ pub struct UpdateJournalEntryContext {
pub struct CreateReaction { pub struct CreateReaction {
pub asset: usize, pub asset: usize,
pub asset_type: AssetType, pub asset_type: AssetType,
pub is_like: bool,
} }

View file

@ -37,7 +37,12 @@ pub async fn create_request(
}; };
match data 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 .await
{ {
Ok(_) => Json(ApiReturn { Ok(_) => Json(ApiReturn {

View file

@ -3,5 +3,6 @@ CREATE TABLE IF NOT EXISTS reactions (
created INTEGER NOT NULL, created INTEGER NOT NULL,
owner INTEGER NOT NULL, owner INTEGER NOT NULL,
asset INTEGER NOT NULL, asset INTEGER NOT NULL,
asset_type TEXT NOT NULL asset_type TEXT NOT NULL,
is_like INTEGER NOT NULL
) )

View file

@ -22,6 +22,7 @@ impl DataManager {
owner: get!(x->2(u64)) as usize, owner: get!(x->2(u64)) as usize,
asset: get!(x->3(u64)) as usize, asset: get!(x->3(u64)) as usize,
asset_type: serde_json::from_str(&get!(x->4(String))).unwrap(), 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!( let res = execute!(
&conn, &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.id.to_string().as_str(),
&data.created.to_string().as_str(), &data.created.to_string().as_str(),
&data.owner.to_string().as_str(), &data.owner.to_string().as_str(),
&data.asset.to_string().as_str(), &data.asset.to_string().as_str(),
&serde_json::to_string(&data.asset_type).unwrap().as_str(), &serde_json::to_string(&data.asset_type).unwrap().as_str(),
&(if data.is_like { 1 } else { 0 }).to_string().as_str()
] ]
); );

View file

@ -15,11 +15,12 @@ pub struct Reaction {
pub owner: usize, pub owner: usize,
pub asset: usize, pub asset: usize,
pub asset_type: AssetType, pub asset_type: AssetType,
pub is_like: bool,
} }
impl Reaction { impl Reaction {
/// Create a new [`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 { Self {
id: AlmostSnowflake::new(1234567890) id: AlmostSnowflake::new(1234567890)
.to_string() .to_string()
@ -29,6 +30,7 @@ impl Reaction {
owner, owner,
asset, asset,
asset_type, asset_type,
is_like,
} }
} }
} }