backend/controller/
guided_tours.rs

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! `GuidedTours` endpoints.

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

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

/// Endpoint for setting up a [`GuidedTours`](crate::model::entity::GuidedTours) object.
///
/// # Errors
/// * If the connection to the database could not be established.
#[utoipa::path(
    context_path = "/api/tours",
    responses(
        (status = 201, description = "Setup a Guided Tour status object for the requesting user", body = GuidedToursDto)
    ),
    security(
        ("oauth2" = [])
    )
)]
#[post("")]
pub async fn setup(user_info: UserInfo, pool: SharedPool) -> Result<HttpResponse> {
    let response = service::guided_tours::setup(user_info.id, &pool).await?;
    Ok(HttpResponse::Created().json(response))
}

/// Endpoint for fetching a [`GuidedTours`](crate::model::entity::GuidedTours) object.
///
/// # Errors
/// * If the connection to the database could not be established.
#[utoipa::path(
    context_path = "/api/tours",
    responses(
        (status = 200, description = "Fetch the Guided Tour status object of the requesting user", body = GuidedToursDto)
    ),
    security(
        ("oauth2" = [])
    )
)]
#[get("")]
pub async fn find_by_user(user_info: UserInfo, pool: SharedPool) -> Result<HttpResponse> {
    let response = service::guided_tours::find_by_user(user_info.id, &pool).await?;
    Ok(HttpResponse::Ok().json(response))
}

/// Endpoint for updating a [`GuidedTours`](crate::model::entity::GuidedTours) object.
///
/// # Errors
/// * If the connection to the database could not be established.
#[utoipa::path(
    context_path = "/api/tours",
    request_body = UpdateGuidedToursDto,
    responses(
        (status = 200, description = "Update the Guided Tour status object of the requesting user", body = GuidedToursDto)
    ),
    security(
        ("oauth2" = [])
    )
)]
#[patch("")]
pub async fn update(
    status_update_json: Json<UpdateGuidedToursDto>,
    user_info: UserInfo,
    pool: SharedPool,
) -> Result<HttpResponse> {
    let response = service::guided_tours::update(status_update_json.0, user_info.id, &pool).await?;
    Ok(HttpResponse::Ok().json(response))
}