chore (backend-rs): publish -> publish_to_stream

This commit is contained in:
naskya 2024-04-21 22:43:09 +09:00
parent 9b91035a79
commit ec940bb068
No known key found for this signature in database
GPG Key ID: 712D413B3A9FED5C
2 changed files with 8 additions and 4 deletions

View File

@ -1,5 +1,5 @@
use crate::database::{redis_conn, redis_key}; use crate::database::{redis_conn, redis_key};
use crate::service::stream::{publish, Error, Stream}; use crate::service::stream::{publish_to_stream, Error, Stream};
use crate::util::id::get_timestamp; use crate::util::id::get_timestamp;
use redis::{streams::StreamMaxlen, Commands}; use redis::{streams::StreamMaxlen, Commands};
@ -15,7 +15,7 @@ pub fn add_note_to_antenna(antenna_id: &str, note_id: &str) -> Result<(), Error>
let stream = Stream::Antenna { let stream = Stream::Antenna {
id: antenna_id.to_string(), id: antenna_id.to_string(),
}; };
publish( publish_to_stream(
&stream, &stream,
Some("note"), Some("note"),
Some(format!("{{ \"id\": \"{}\" }}", note_id)), Some(format!("{{ \"id\": \"{}\" }}", note_id)),

View File

@ -42,7 +42,11 @@ pub enum Error {
ValueError(String), ValueError(String),
} }
pub fn publish(channel: &Stream, kind: Option<&str>, value: Option<String>) -> Result<(), Error> { pub fn publish_to_stream(
stream: &Stream,
kind: Option<&str>,
value: Option<String>,
) -> Result<(), Error> {
let message = if let Some(kind) = kind { let message = if let Some(kind) = kind {
format!( format!(
"{{ \"type\": \"{}\", \"body\": {} }}", "{{ \"type\": \"{}\", \"body\": {} }}",
@ -60,7 +64,7 @@ pub fn publish(channel: &Stream, kind: Option<&str>, value: Option<String>) -> R
&CONFIG.host, &CONFIG.host,
format!( format!(
"{{ \"channel\": \"{}\", \"message\": {} }}", "{{ \"channel\": \"{}\", \"message\": {} }}",
channel, message, stream, message,
), ),
)?; )?;