Add secondary check to prevent empty tags from being created

This commit is contained in:
Tobias Reisinger 2024-04-22 04:26:25 +02:00
parent e950a33e98
commit 55a352f85a
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
2 changed files with 6 additions and 0 deletions

View file

@ -17,6 +17,10 @@ impl DbTag {
conn: &mut PoolConnection<Sqlite>, conn: &mut PoolConnection<Sqlite>,
new_tag: &str, new_tag: &str,
) -> Result<DbTag, DatabaseError> { ) -> Result<DbTag, DatabaseError> {
if new_tag.len() == 0 {
return Err(DatabaseError::EmptyDataInsert);
}
sqlx::query_as!( sqlx::query_as!(
DbTag, DbTag,
"INSERT INTO tags (tag) VALUES (?) RETURNING *", "INSERT INTO tags (tag) VALUES (?) RETURNING *",

View file

@ -12,6 +12,7 @@ pub enum DatabaseError {
InsertGetError, InsertGetError,
NotFound, NotFound,
Protected, Protected,
EmptyDataInsert,
UpdateError, UpdateError,
UpdateGetError, UpdateGetError,
MigrationError(MigrateError), MigrationError(MigrateError),
@ -57,6 +58,7 @@ impl From<&DatabaseError> for String {
} }
DatabaseError::MigrationError(_) => "error on running migrations", DatabaseError::MigrationError(_) => "error on running migrations",
DatabaseError::Unknown(_) => "unknown error", DatabaseError::Unknown(_) => "unknown error",
DatabaseError::EmptyDataInsert => "empty data was attempted to be inserted",
}) })
} }
} }