821537186e
- Reorganized import statements in adapter tests for better readability - Replaced or_insert_with(Vec::new) with or_default() in test closures - Updated Cargo.lock with new dependency versions and checksums - Added TLS features to tonic dependency configuration - Included sqlx, chrono, and uuid dependencies with specific features - Added jsonwebtoken and arc-swap as project dependencies - Reformatted assertion statements to comply with line length limits - Adjusted base64 import order in engine codec module - Updated protobuf include statement formatting
54 lines
1.5 KiB
Rust
54 lines
1.5 KiB
Rust
//! Sticker CRUD operations on `MessageRepo`.
|
|
|
|
use uuid::Uuid;
|
|
|
|
use crate::ImksResult;
|
|
use crate::models::message_sticker::MessageSticker;
|
|
|
|
use super::message_repo::MessageRepo;
|
|
|
|
impl MessageRepo {
|
|
/// Record a sticker used in a message.
|
|
#[allow(clippy::too_many_arguments)]
|
|
pub async fn record_sticker(
|
|
&self,
|
|
message_id: Uuid,
|
|
sticker_id: Uuid,
|
|
name: &str,
|
|
image_url: &str,
|
|
format_type: &str,
|
|
pack_name: Option<&str>,
|
|
tags: Option<&str>,
|
|
) -> ImksResult<MessageSticker> {
|
|
sqlx::query_as::<_, MessageSticker>(
|
|
r#"
|
|
INSERT INTO message_sticker (id, message_id, sticker_id, name, image_url, format_type, pack_name, tags)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
|
RETURNING *
|
|
"#,
|
|
)
|
|
.bind(Uuid::now_v7())
|
|
.bind(message_id)
|
|
.bind(sticker_id)
|
|
.bind(name)
|
|
.bind(image_url)
|
|
.bind(format_type)
|
|
.bind(pack_name)
|
|
.bind(tags)
|
|
.fetch_one(self.pool())
|
|
.await
|
|
.map_err(Into::into)
|
|
}
|
|
|
|
/// Get all stickers on a message.
|
|
pub async fn get_stickers(&self, message_id: Uuid) -> ImksResult<Vec<MessageSticker>> {
|
|
sqlx::query_as::<_, MessageSticker>(
|
|
"SELECT * FROM message_sticker WHERE message_id = $1 ORDER BY created_at",
|
|
)
|
|
.bind(message_id)
|
|
.fetch_all(self.pool())
|
|
.await
|
|
.map_err(Into::into)
|
|
}
|
|
}
|