use actix_web::{
get, patch, post,
web::{Data, Json},
HttpResponse, Result,
};
use crate::{
config::{auth::user_info::UserInfo, data::AppDataInner},
model::dto::UpdateGuidedToursDto,
service,
};
#[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, app_data: Data<AppDataInner>) -> Result<HttpResponse> {
let response = service::guided_tours::setup(user_info.id, &app_data).await?;
Ok(HttpResponse::Created().json(response))
}
#[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,
app_data: Data<AppDataInner>,
) -> Result<HttpResponse> {
let response = service::guided_tours::find_by_user(user_info.id, &app_data).await?;
Ok(HttpResponse::Ok().json(response))
}
#[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,
app_data: Data<AppDataInner>,
) -> Result<HttpResponse> {
let response =
service::guided_tours::update(status_update_json.0, user_info.id, &app_data).await?;
Ok(HttpResponse::Ok().json(response))
}