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");