backend/controller/
guided_tours.rs1use 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#[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#[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#[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}