pub async fn create_poll_option(pool: &DBPool, poll_id: i32, value: String) -> Result<PollOption> {
        let num_poll_options = get_num_poll_options(pool, poll_id).await?;

        if num_poll_options >= NUM_POLL_OPTIONS {
            generic_err!("Maximum number of poll options has been reached")
        } else if value.len() < 1 || value.len() > 255 {
            generic_err!("Option value must be between 1 and 255 characters")
        } else {
            let mut res = generic_service_err!(
                sqlx::query_file_as!(PollOption, "sql/poll_option/create_poll_option.sql", poll_id, value)
                .fetch_all(pool).await,
                "Failed to create new poll option");

            Ok(res.remove(0))
        }
    }
/// Creates a poll option and returns the resulting record
/// 
/// # Arguments
/// 
/// * `pool` - The database pool
/// * `poll_id` - The ID of the poll
/// * `value` - The text representing the poll option
Creates a poll option and returns the resulting record
Creates a poll option and returns the resulting record
pub async fn create_poll_option(pool: &DBPool, poll_id: i32, value: String) -> Result<PollOption> {
        let num_poll_options = get_num_poll_options(pool, poll_id).await?;
        if num_poll_options >= NUM_POLL_OPTIONS {
            generic_err!("Maximum number of poll options has been reached")
        } else if value.len() < 1 || value.len() > 255 {
            generic_err!("Option value must be between 1 and 255 characters")
        } else {
            let mut res = generic_service_err!(
                sqlx::query_file_as!(PollOption, "sql/poll_option/create_poll_option.sql", poll_id, value)
                .fetch_all(pool).await,
                "Failed to create new poll option");
            Ok(res.remove(0))
        }
    }
pub async fn create_poll_option ( pool : & DBPool , poll_id : i32 , value : String ) -> Result < PollOption > { let num_poll_options = get_num_poll_options ( pool , poll_id ) . await ? ; if num_poll_options >= NUM_POLL_OPTIONS { generic_err ! ( " " ) } else if value . len ( ) < 1 || value . len ( ) > 255 { generic_err ! ( " " ) } else { let mut res = generic_service_err ! ( sqlx query_file_as ( PollOption " " poll_id value ) fetch_all ( pool ) await " " ) ; Ok ( res . remove ( 0 ) ) } }
Creates a poll option and returns the resulting record
Creates a poll option and returns the resulting record
pool
&DBPool
poll_id
i32
value
String
pool
&DBPool
poll_id
i32
value
String