Add secondary check to prevent empty tags from being created
This commit is contained in:
parent
e950a33e98
commit
55a352f85a
2 changed files with 6 additions and 0 deletions
|
@ -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 *",
|
||||||
|
|
|
@ -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",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue