backend/service/
guided_tour.rs

1//! Service layer for guided tour.
2
3use uuid::Uuid;
4
5use crate::{
6    config::data::SharedPool,
7    error::ServiceError,
8    model::{
9        dto::{CompleteGuidedTourStepDto, GuidedTourDto},
10        entity::guided_tour_impl::GuidedTour,
11    },
12};
13
14/// Get guided tour info for a user
15///
16/// # Errors
17/// If the connection to the database could not be established.
18pub async fn find_by_user(user_id: Uuid, pool: &SharedPool) -> Result<GuidedTourDto, ServiceError> {
19    let mut conn = pool.get().await?;
20    Ok(GuidedTour::find_by_user(user_id, &mut conn).await?)
21}
22
23/// Mark a step completed (idempotent)
24///
25/// # Errors
26/// If the connection to the database could not be established.
27pub async fn complete_step(
28    user_id: Uuid,
29    dto: CompleteGuidedTourStepDto,
30    pool: &SharedPool,
31) -> Result<(), ServiceError> {
32    let mut conn = pool.get().await?;
33    GuidedTour::complete_step(user_id, dto.step_key, &mut conn).await?;
34    Ok(())
35}
36
37/// Mark multiple steps completed (idempotent).
38///
39/// # Errors
40/// If the connection to the database could not be established.
41pub async fn complete_steps(
42    user_id: Uuid,
43    step_keys: Vec<String>,
44    pool: &SharedPool,
45) -> Result<(), ServiceError> {
46    let mut conn = pool.get().await?;
47    GuidedTour::complete_steps(user_id, step_keys, &mut conn).await?;
48    Ok(())
49}
50
51/// Pause the guided tour for the user
52///
53/// # Errors
54/// If the connection to the database could not be established.
55pub async fn pause(user_id: Uuid, pool: &SharedPool) -> Result<(), ServiceError> {
56    let mut conn = pool.get().await?;
57    GuidedTour::pause(user_id, &mut conn).await?;
58    Ok(())
59}