1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//! `Blossom` endpoints.

use actix_web::{post, web::Json, HttpResponse, Result};

use crate::config::data::SharedPool;
use crate::{config::auth::user_info::UserInfo, model::dto::GainedBlossomsDto, service};

/// Endpoint for gaining a [`Blossom`](crate::model::entity::Blossom).
///
/// # Errors
/// * If the connection to the database could not be established.
#[utoipa::path(
    context_path = "/api/blossoms",
    request_body = BlossomsGainedDto,
    responses(
        (status = 201, description = "The user gains a Blossom", body = BlossomsGainedDto)
    ),
    security(
        ("oauth2" = [])
    )
)]
#[post("")]
pub async fn gain(
    gained_blossom_json: Json<GainedBlossomsDto>,
    user_info: UserInfo,
    pool: SharedPool,
) -> Result<HttpResponse> {
    let response = service::blossoms::gain(gained_blossom_json.0, user_info.id, &pool).await?;
    Ok(HttpResponse::Created().json(response))
}