1use finance::tag::Tag;
5use sqlx::types::Uuid;
6
7use crate::error::ServerError;
8use crate::logical::hex_digest;
9use crate::user::User;
10
11pub const STALE_TAG: &str = "the tag changed since it was loaded; reload it";
13
14#[must_use]
16pub fn tag_revision(tag: &Tag) -> String {
17 hex_digest(vec![format!(
18 "tag {:?}",
19 (&tag.tag_name, &tag.tag_value, &tag.description)
20 )])
21}
22
23impl User {
24 pub async fn find_tag(&self, id: Uuid) -> Result<Option<Tag>, ServerError> {
29 let mut conn = self.get_connection().await?;
30 sqlx::query_file_as!(Tag, "sql/select/tags/by_id.sql", id)
31 .fetch_optional(&mut *conn)
32 .await
33 .map_err(|err| ServerError::DB(err.into()))
34 }
35}