/// Handler for delete custom spu request
Handler for delete custom spu request
Handler for delete custom spu request
pub async fn handle_delete_custom_spus_request<C>(
    request: RequestMessage<FlvDeleteCustomSpusRequest>,
    ctx: &PublicContext<C>,
) -> Result<ResponseMessage<FlvDeleteCustomSpusResponse>, Error>
where
    C: MetadataClient,
{
    let mut response = FlvDeleteCustomSpusResponse::default();
    let mut results: Vec<FlvResponseMessage> = vec![];
    // look-up custom spus based on their names or ids
    for custom_spu in &request.request.custom_spus {
        let result = match custom_spu {
            FlvCustomSpu::Name(spu_name) => {
                debug!("api request: delete custom-spu with name '{}'", spu_name);
                // spu-name must exist
                if let Some(spu) = &ctx.metadata().spus().spu(spu_name) {
                    delete_custom_spu(ctx, spu).await?
                } else {
                    // spu does not exist
                    FlvResponseMessage::new(
                        spu_name.clone(),
                        FlvErrorCode::SpuNotFound,
                        Some("not found".to_owned()),
                    )
                }
            }
            FlvCustomSpu::Id(spu_id) => {
                debug!("api request: delete custom-spu with id '{}'", spu_id);
                // spu-id must exist
                if let Some(spu) = &ctx.metadata().spus().get_by_id(spu_id) {
                    delete_custom_spu(ctx, spu).await?
                } else {
                    // spu does not exist
                    FlvResponseMessage::new(
                        format!("spu-{}", spu_id),
                        FlvErrorCode::SpuNotFound,
                        Some("not found".to_owned()),
                    )
                }
            }
        };
        // save result
        results.push(result);
    }
    // update response
    response.results = results;
    trace!("flv delete custom-spus resp {:#?}", response);
    Ok(request.new_response(response))
}
pub async fn handle_delete_custom_spus_request < C > ( request : RequestMessage < FlvDeleteCustomSpusRequest > , ctx : & PublicContext < C > , ) -> Result < ResponseMessage < FlvDeleteCustomSpusResponse > , Error > where C : MetadataClient , { let mut response = FlvDeleteCustomSpusResponse :: default ( ) ; let mut results : Vec < FlvResponseMessage > = vec ! [ ] ; // look-up custom spus based on their names or ids for custom_spu in & request . request . custom_spus { let result = match custom_spu { FlvCustomSpu :: Name ( spu_name ) => { debug ! ( " " spu_name ) ; // spu-name must exist if let Some ( spu ) = & ctx . metadata ( ) . spus ( ) . spu ( spu_name ) { delete_custom_spu ( ctx , spu ) . await ? } else { // spu does not exist FlvResponseMessage :: new ( spu_name . clone ( ) , FlvErrorCode :: SpuNotFound , Some ( " " . to_owned ( ) ) , ) } } FlvCustomSpu :: Id ( spu_id ) => { debug ! ( " " spu_id ) ; // spu-id must exist if let Some ( spu ) = & ctx . metadata ( ) . spus ( ) . get_by_id ( spu_id ) { delete_custom_spu ( ctx , spu ) . await ? } else { // spu does not exist FlvResponseMessage :: new ( format ! ( " " spu_id ) , FlvErrorCode :: SpuNotFound , Some ( " " . to_owned ( ) ) , ) } } } ; // save result results . push ( result ) ; } // update response response . results = results ; trace ! ( " " response ) ; Ok ( request . new_response ( response ) ) }
Handler for delete custom spu request
Handler for delete custom spu request
request
RequestMessage<FlvDeleteCustomSpusRequest>
ctx
&PublicContext<C>