backend/controller/
blossoms.rs

1//! `Blossom` endpoints.
2
3use actix_web::{post, web::Json, HttpResponse, Result};
4
5use crate::config::data::SharedPool;
6use crate::{config::auth::user_info::UserInfo, model::dto::GainedBlossomsDto, service};
7
8/// Endpoint for gaining a [`Blossom`](crate::model::entity::Blossom).
9///
10/// # Errors
11/// * If the connection to the database could not be established.
12#[utoipa::path(
13    context_path = "/api/blossoms",
14    request_body = BlossomsGainedDto,
15    responses(
16        (status = 201, description = "The user gains a Blossom", body = BlossomsGainedDto)
17    ),
18    security(
19        ("oauth2" = [])
20    )
21)]
22#[post("")]
23pub async fn gain(
24    gained_blossom_json: Json<GainedBlossomsDto>,
25    user_info: UserInfo,
26    pool: SharedPool,
27) -> Result<HttpResponse> {
28    let response = service::blossoms::gain(gained_blossom_json.0, user_info.id, &pool).await?;
29    Ok(HttpResponse::Created().json(response))
30}