Lines
100 %
Functions
15.89 %
Branches
//! Tag rows as the tag forms and natives edit them, over the `User` tag API.
use sqlx::types::Uuid;
use supp_macro::command;
use super::{CmdError, CmdResult, FinanceEntity};
use crate::error::ServerError;
use crate::tag_state::STALE_TAG;
use crate::user::User;
command! {
CreateTag {
#[required]
user_id: Uuid,
name: String,
value: String,
#[optional]
description: String,
} => {
let id = User { id: user_id }
.create_tag(name, value, description)
.await?;
Ok(Some(CmdResult::Uuid(id)))
}
EditTag {
tag_id: Uuid,
revision: String,
let updated = User { id: user_id }
.update_tag(tag_id, &revision, name, value, description)
.await;
match updated {
Err(ServerError::StaleTag) => Err(CmdError::Args(STALE_TAG.to_string())),
other => other.map(|()| Some(CmdResult::Uuid(tag_id))).map_err(Into::into),
DeleteTag {
match (User { id: user_id }).delete_tag(tag_id).await? {
true => Ok(Some(CmdResult::Bool(true))),
false => Err(CmdError::NotFound(format!("no tag {tag_id}"))),
ListTags {
let tags = User { id: user_id }.list_tags().await?;
Ok(Some(CmdResult::Entities(
tags.into_iter().map(FinanceEntity::Tag).collect(),
)))