From a63d66da4c41ca49c3bac046e1b06ee446f14614 Mon Sep 17 00:00:00 2001 From: Arnab Chakraborty <11457760+Rocky43007@users.noreply.github.com> Date: Fri, 24 May 2024 14:20:20 -0400 Subject: [PATCH] No Duplicating Tags (#2505) * Error when trying to make tags with same name * Formatting --- core/src/api/tags.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/src/api/tags.rs b/core/src/api/tags.rs index 73c9c90ca..df813486e 100644 --- a/core/src/api/tags.rs +++ b/core/src/api/tags.rs @@ -88,6 +88,22 @@ pub(crate) fn mount() -> AlphaRouter { .procedure("create", { R.with2(library()) .mutation(|(_, library), args: TagCreateArgs| async move { + // Check if tag with the same name already exists + let existing_tag = library + .db + .tag() + .find_many(vec![tag::name::equals(Some(args.name.clone()))]) + .select(tag::select!({ id })) + .exec() + .await?; + + if !existing_tag.is_empty() { + return Err(rspc::Error::new( + ErrorCode::Conflict, + "Tag with the same name already exists".to_string(), + )); + } + let created_tag = args.exec(&library).await?; invalidate_query!(library, "tags.list");