async fn create(
    db: Data<PgPool>,
    _claims: TokenUserWithScope<ScopeManageImage>,
    req: Json<<endpoints::image::Create as ApiEndpoint>::Req>,
) -> Result<HttpResponse, error::CreateWithMetadata> {
    let req = req.into_inner();

    let mut txn = db.begin().await?;
    let id = db::image::create(
        &mut txn,
        &req.name,
        &req.description,
        req.is_premium,
        req.publish_at.map(DateTime::<Utc>::from),
        req.kind,
    )
    .await?;

    db::image::update_metadata(
        &mut txn,
        id,
        nul_if_empty(&req.affiliations),
        nul_if_empty(&req.age_ranges),
        nul_if_empty(&req.styles),
        nul_if_empty(&req.categories),
        nul_if_empty(&req.tags),
    )
    .await
    .map_err(handle_metadata_err)?;

    txn.commit().await?;

    Ok(HttpResponse::Created().json(CreateResponse { id }))
}
/// Create an image in the global image library.
Create an image in the global image library.
Create an image in the global image library .
async fn create(
    db: Data<PgPool>,
    _claims: TokenUserWithScope<ScopeManageImage>,
    req: Json<<endpoints::image::Create as ApiEndpoint>::Req>,
) -> Result<HttpResponse, error::CreateWithMetadata> {
    let req = req.into_inner();
    let mut txn = db.begin().await?;
    let id = db::image::create(
        &mut txn,
        &req.name,
        &req.description,
        req.is_premium,
        req.publish_at.map(DateTime::<Utc>::from),
        req.kind,
    )
    .await?;
    db::image::update_metadata(
        &mut txn,
        id,
        nul_if_empty(&req.affiliations),
        nul_if_empty(&req.age_ranges),
        nul_if_empty(&req.styles),
        nul_if_empty(&req.categories),
        nul_if_empty(&req.tags),
    )
    .await
    .map_err(handle_metadata_err)?;
    txn.commit().await?;
    Ok(HttpResponse::Created().json(CreateResponse { id }))
}
async fn create ( db : Data < PgPool > , _claims : TokenUserWithScope < ScopeManageImage > , req : Json < < endpoints :: image :: Create as ApiEndpoint > :: Req > , ) -> Result < HttpResponse , error :: CreateWithMetadata > { let req = req . into_inner ( ) ; let mut txn = db . begin ( ) . await ? ; let id = db :: image :: create ( & mut txn , & req . name , & req . description , req . is_premium , req . publish_at . map ( DateTime :: < Utc > :: from ) , req . kind , ) . await ? ; db :: image :: update_metadata ( & mut txn , id , nul_if_empty ( & req . affiliations ) , nul_if_empty ( & req . age_ranges ) , nul_if_empty ( & req . styles ) , nul_if_empty ( & req . categories ) , nul_if_empty ( & req . tags ) , ) . await . map_err ( handle_metadata_err ) ? ; txn . commit ( ) . await ? ; Ok ( HttpResponse :: Created ( ) . json ( CreateResponse { id } ) ) }
Create an image in the global image library.
Create an image in the global image library .
db
Data<PgPool>
_claims
TokenUserWithScope<ScopeManageImage>
req
Json<<endpoints::image::Create as ApiEndpoint>::Req>
db
Data<PgPool>
_claims
TokenUserWithScope<ScopeManageImage>
req
Json<<endpoints::image::Create as ApiEndpoint>::Req>