backend/controller/
guided_tours.rs

1//! `GuidedTours` endpoints.
2
3use actix_web::{get, patch, post, web::Json, HttpResponse, Result};
4
5use crate::config::data::SharedPool;
6use crate::{config::auth::user_info::UserInfo, model::dto::UpdateGuidedToursDto, service};
7
8/// Endpoint for setting up a [`GuidedTours`](crate::model::entity::GuidedTours) object.
9///
10/// # Errors
11/// * If the connection to the database could not be established.
12#[utoipa::path(
13    context_path = "/api/tours",
14    responses(
15        (status = 201, description = "Setup a Guided Tour status object for the requesting user", body = GuidedToursDto)
16    ),
17    security(
18        ("oauth2" = [])
19    )
20)]
21#[post("")]
22pub async fn setup(user_info: UserInfo, pool: SharedPool) -> Result<HttpResponse> {
23    let response = service::guided_tours::setup(user_info.id, &pool).await?;
24    Ok(HttpResponse::Created().json(response))
25}
26
27/// Endpoint for fetching a [`GuidedTours`](crate::model::entity::GuidedTours) object.
28///
29/// # Errors
30/// * If the connection to the database could not be established.
31#[utoipa::path(
32    context_path = "/api/tours",
33    responses(
34        (status = 200, description = "Fetch the Guided Tour status object of the requesting user", body = GuidedToursDto)
35    ),
36    security(
37        ("oauth2" = [])
38    )
39)]
40#[get("")]
41pub async fn find_by_user(user_info: UserInfo, pool: SharedPool) -> Result<HttpResponse> {
42    let response = service::guided_tours::find_by_user(user_info.id, &pool).await?;
43    Ok(HttpResponse::Ok().json(response))
44}
45
46/// Endpoint for updating a [`GuidedTours`](crate::model::entity::GuidedTours) object.
47///
48/// # Errors
49/// * If the connection to the database could not be established.
50#[utoipa::path(
51    context_path = "/api/tours",
52    request_body = UpdateGuidedToursDto,
53    responses(
54        (status = 200, description = "Update the Guided Tour status object of the requesting user", body = GuidedToursDto)
55    ),
56    security(
57        ("oauth2" = [])
58    )
59)]
60#[patch("")]
61pub async fn update(
62    status_update_json: Json<UpdateGuidedToursDto>,
63    user_info: UserInfo,
64    pool: SharedPool,
65) -> Result<HttpResponse> {
66    let response = service::guided_tours::update(status_update_json.0, user_info.id, &pool).await?;
67    Ok(HttpResponse::Ok().json(response))
68}