pub struct ChallengeUseCases { /* private fields */ }Expand description
Use cases for challenge operations
Orchestrates business logic for challenge CRUD, activation/completion, and progress tracking.
Implementations§
Source§impl ChallengeUseCases
impl ChallengeUseCases
pub fn new( challenge_repo: Arc<dyn ChallengeRepository>, progress_repo: Arc<dyn ChallengeProgressRepository>, ) -> Self
Sourcepub async fn create_challenge(
&self,
dto: CreateChallengeDto,
) -> Result<ChallengeResponseDto, String>
pub async fn create_challenge( &self, dto: CreateChallengeDto, ) -> Result<ChallengeResponseDto, String>
Sourcepub async fn get_challenge(
&self,
challenge_id: Uuid,
) -> Result<ChallengeResponseDto, String>
pub async fn get_challenge( &self, challenge_id: Uuid, ) -> Result<ChallengeResponseDto, String>
Get challenge by ID
Sourcepub async fn list_challenges(
&self,
organization_id: Uuid,
) -> Result<Vec<ChallengeResponseDto>, String>
pub async fn list_challenges( &self, organization_id: Uuid, ) -> Result<Vec<ChallengeResponseDto>, String>
List all challenges for an organization
Sourcepub async fn list_challenges_by_status(
&self,
organization_id: Uuid,
status: ChallengeStatus,
) -> Result<Vec<ChallengeResponseDto>, String>
pub async fn list_challenges_by_status( &self, organization_id: Uuid, status: ChallengeStatus, ) -> Result<Vec<ChallengeResponseDto>, String>
List challenges by status
Sourcepub async fn list_building_challenges(
&self,
building_id: Uuid,
) -> Result<Vec<ChallengeResponseDto>, String>
pub async fn list_building_challenges( &self, building_id: Uuid, ) -> Result<Vec<ChallengeResponseDto>, String>
List challenges for a building
Sourcepub async fn list_active_challenges(
&self,
organization_id: Uuid,
) -> Result<Vec<ChallengeResponseDto>, String>
pub async fn list_active_challenges( &self, organization_id: Uuid, ) -> Result<Vec<ChallengeResponseDto>, String>
List active challenges (Active status + date range)
Sourcepub async fn update_challenge(
&self,
challenge_id: Uuid,
dto: UpdateChallengeDto,
) -> Result<ChallengeResponseDto, String>
pub async fn update_challenge( &self, challenge_id: Uuid, dto: UpdateChallengeDto, ) -> Result<ChallengeResponseDto, String>
Update challenge (Draft only)
§Authorization
- Only organization admins can update challenges
- Can only update Draft challenges
Sourcepub async fn activate_challenge(
&self,
challenge_id: Uuid,
) -> Result<ChallengeResponseDto, String>
pub async fn activate_challenge( &self, challenge_id: Uuid, ) -> Result<ChallengeResponseDto, String>
Sourcepub async fn complete_challenge(
&self,
challenge_id: Uuid,
) -> Result<ChallengeResponseDto, String>
pub async fn complete_challenge( &self, challenge_id: Uuid, ) -> Result<ChallengeResponseDto, String>
Complete challenge (Active → Completed)
§Authorization
- Only organization admins can complete challenges
Sourcepub async fn cancel_challenge(
&self,
challenge_id: Uuid,
) -> Result<ChallengeResponseDto, String>
pub async fn cancel_challenge( &self, challenge_id: Uuid, ) -> Result<ChallengeResponseDto, String>
Cancel challenge (Draft/Active → Cancelled)
§Authorization
- Only organization admins can cancel challenges
Sourcepub async fn delete_challenge(&self, challenge_id: Uuid) -> Result<(), String>
pub async fn delete_challenge(&self, challenge_id: Uuid) -> Result<(), String>
Delete challenge (admin only)
Sourcepub async fn get_challenge_progress(
&self,
user_id: Uuid,
challenge_id: Uuid,
) -> Result<ChallengeProgressResponseDto, String>
pub async fn get_challenge_progress( &self, user_id: Uuid, challenge_id: Uuid, ) -> Result<ChallengeProgressResponseDto, String>
Get user progress for a challenge
Sourcepub async fn list_challenge_progress(
&self,
challenge_id: Uuid,
) -> Result<Vec<ChallengeProgressResponseDto>, String>
pub async fn list_challenge_progress( &self, challenge_id: Uuid, ) -> Result<Vec<ChallengeProgressResponseDto>, String>
List all progress for a challenge
Sourcepub async fn list_user_active_progress(
&self,
user_id: Uuid,
) -> Result<Vec<ChallengeProgressResponseDto>, String>
pub async fn list_user_active_progress( &self, user_id: Uuid, ) -> Result<Vec<ChallengeProgressResponseDto>, String>
List active challenges for a user with progress
Sourcepub async fn increment_progress(
&self,
user_id: Uuid,
challenge_id: Uuid,
increment: i32,
) -> Result<ChallengeProgressResponseDto, String>
pub async fn increment_progress( &self, user_id: Uuid, challenge_id: Uuid, increment: i32, ) -> Result<ChallengeProgressResponseDto, String>
Increment user progress for a challenge
Creates progress if doesn’t exist, increments if exists. Automatically completes challenge if target reached.
Auto Trait Implementations§
impl Freeze for ChallengeUseCases
impl !RefUnwindSafe for ChallengeUseCases
impl Send for ChallengeUseCases
impl Sync for ChallengeUseCases
impl Unpin for ChallengeUseCases
impl !UnwindSafe for ChallengeUseCases
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Chain<T> for T
impl<T> Chain<T> for T
§impl<T> Fake for T
impl<T> Fake for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreCreates a shared type from an unshared type.