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>,
 | 
			
		||||
		new_tag: &str,
 | 
			
		||||
	) -> Result<DbTag, DatabaseError> {
 | 
			
		||||
		if new_tag.len() == 0 {
 | 
			
		||||
			return Err(DatabaseError::EmptyDataInsert);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		sqlx::query_as!(
 | 
			
		||||
			DbTag,
 | 
			
		||||
			"INSERT INTO tags (tag) VALUES (?) RETURNING *",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,6 +12,7 @@ pub enum DatabaseError {
 | 
			
		|||
	InsertGetError,
 | 
			
		||||
	NotFound,
 | 
			
		||||
	Protected,
 | 
			
		||||
	EmptyDataInsert,
 | 
			
		||||
	UpdateError,
 | 
			
		||||
	UpdateGetError,
 | 
			
		||||
	MigrationError(MigrateError),
 | 
			
		||||
| 
						 | 
				
			
			@ -57,6 +58,7 @@ impl From<&DatabaseError> for String {
 | 
			
		|||
			}
 | 
			
		||||
			DatabaseError::MigrationError(_) => "error on running migrations",
 | 
			
		||||
			DatabaseError::Unknown(_) => "unknown error",
 | 
			
		||||
			DatabaseError::EmptyDataInsert => "empty data was attempted to be inserted",
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue