Lines
92.31 %
Functions
58.33 %
Branches
100 %
//! A stored tag as the tag-edit form holds it, with the revision digesting
//! its editable fields.
use finance::tag::Tag;
use sqlx::types::Uuid;
use crate::error::ServerError;
use crate::logical::hex_digest;
use crate::user::User;
/// The error text of a tag edit whose expected revision no longer matches.
pub const STALE_TAG: &str = "the tag changed since it was loaded; reload it";
/// Digest of the tag's name, value and description.
#[must_use]
pub fn tag_revision(tag: &Tag) -> String {
hex_digest(vec![format!(
"tag {:?}",
(&tag.tag_name, &tag.tag_value, &tag.description)
)])
}
impl User {
/// The tag, `None` when the user has no such tag.
///
/// # Errors
/// The connection or the query failing.
pub async fn find_tag(&self, id: Uuid) -> Result<Option<Tag>, ServerError> {
let mut conn = self.get_connection().await?;
sqlx::query_file_as!(Tag, "sql/select/tags/by_id.sql", id)
.fetch_optional(&mut *conn)
.await
.map_err(|err| ServerError::DB(err.into()))