2024-04-19 23:54:06 +02:00
|
|
|
use crate::database::{redis_conn, redis_key};
|
2024-04-21 18:47:56 +02:00
|
|
|
use crate::model::entity::note;
|
2024-04-21 18:54:44 +02:00
|
|
|
use crate::service::stream::{publish_to_stream, Error, Stream};
|
2024-04-19 23:54:06 +02:00
|
|
|
use crate::util::id::get_timestamp;
|
|
|
|
use redis::{streams::StreamMaxlen, Commands};
|
|
|
|
|
2024-04-21 18:47:56 +02:00
|
|
|
type Note = note::Model;
|
|
|
|
|
2024-04-19 23:54:06 +02:00
|
|
|
#[crate::export]
|
2024-04-21 18:47:56 +02:00
|
|
|
pub fn add_note_to_antenna(antenna_id: String, note: &Note) -> Result<(), Error> {
|
2024-04-19 23:54:06 +02:00
|
|
|
redis_conn()?.xadd_maxlen(
|
|
|
|
redis_key(format!("antennaTimeline:{}", antenna_id)),
|
|
|
|
StreamMaxlen::Approx(200),
|
2024-04-21 18:47:56 +02:00
|
|
|
format!("{}-*", get_timestamp(¬e.id)),
|
|
|
|
&[("note", ¬e.id)],
|
2024-04-19 23:54:06 +02:00
|
|
|
)?;
|
|
|
|
|
2024-04-21 15:43:09 +02:00
|
|
|
publish_to_stream(
|
2024-04-21 17:30:59 +02:00
|
|
|
&Stream::Antenna { antenna_id },
|
2024-04-20 22:47:11 +02:00
|
|
|
Some("note"),
|
2024-04-21 18:47:56 +02:00
|
|
|
Some(serde_json::to_string(note)?),
|
2024-04-20 22:47:11 +02:00
|
|
|
)
|
2024-04-19 23:54:06 +02:00
|
|
|
}
|