pub struct Challenge {Show 15 fields
pub id: Uuid,
pub organization_id: Uuid,
pub building_id: Option<Uuid>,
pub challenge_type: ChallengeType,
pub status: ChallengeStatus,
pub title: String,
pub description: String,
pub icon: String,
pub start_date: DateTime<Utc>,
pub end_date: DateTime<Utc>,
pub target_metric: String,
pub target_value: i32,
pub reward_points: i32,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}Expand description
Challenge entity - Time-bound goals to encourage community engagement
Represents a specific challenge or contest with a defined timeframe. Challenges motivate participation through gamification.
§Belgian Context
- Encourages active copropriété community participation
- Promotes use of platform features (SEL, bookings, etc.)
- Builds community spirit through shared goals
§Business Rules
- title must be 3-100 characters
- description must be 10-1000 characters
- start_date must be < end_date
- target_value must be > 0
- reward_points must be 0-10000
Fields§
§id: Uuid§organization_id: Uuid§building_id: Option<Uuid>§challenge_type: ChallengeType§status: ChallengeStatus§title: String§description: String§icon: String§start_date: DateTime<Utc>§end_date: DateTime<Utc>§target_metric: String§target_value: i32§reward_points: i32§created_at: DateTime<Utc>§updated_at: DateTime<Utc>Implementations§
Source§impl Challenge
impl Challenge
Sourcepub const MIN_TITLE_LENGTH: usize = 3usize
pub const MIN_TITLE_LENGTH: usize = 3usize
Minimum title length
Sourcepub const MAX_TITLE_LENGTH: usize = 100usize
pub const MAX_TITLE_LENGTH: usize = 100usize
Maximum title length
Sourcepub const MIN_DESCRIPTION_LENGTH: usize = 10usize
pub const MIN_DESCRIPTION_LENGTH: usize = 10usize
Minimum description length
Sourcepub const MAX_DESCRIPTION_LENGTH: usize = 1_000usize
pub const MAX_DESCRIPTION_LENGTH: usize = 1_000usize
Maximum description length
Sourcepub const MAX_REWARD_POINTS: i32 = 10_000i32
pub const MAX_REWARD_POINTS: i32 = 10_000i32
Maximum reward points
Sourcepub fn new(
organization_id: Uuid,
building_id: Option<Uuid>,
challenge_type: ChallengeType,
title: String,
description: String,
icon: String,
start_date: DateTime<Utc>,
end_date: DateTime<Utc>,
target_metric: String,
target_value: i32,
reward_points: i32,
) -> Result<Self, String>
pub fn new( organization_id: Uuid, building_id: Option<Uuid>, challenge_type: ChallengeType, title: String, description: String, icon: String, start_date: DateTime<Utc>, end_date: DateTime<Utc>, target_metric: String, target_value: i32, reward_points: i32, ) -> Result<Self, String>
Create a new challenge
§Validation
- title must be 3-100 characters
- description must be 10-1000 characters
- start_date must be < end_date
- start_date must be in the future
- target_value must be > 0
- reward_points must be 0-10000
- icon must not be empty
Sourcepub fn is_currently_active(&self) -> bool
pub fn is_currently_active(&self) -> bool
Check if challenge is currently active (now >= start_date AND now < end_date AND status = Active)
Sourcepub fn duration_days(&self) -> i64
pub fn duration_days(&self) -> i64
Calculate duration in days
Sourcepub fn update(
&mut self,
title: Option<String>,
description: Option<String>,
icon: Option<String>,
start_date: Option<DateTime<Utc>>,
end_date: Option<DateTime<Utc>>,
target_value: Option<i32>,
reward_points: Option<i32>,
) -> Result<(), String>
pub fn update( &mut self, title: Option<String>, description: Option<String>, icon: Option<String>, start_date: Option<DateTime<Utc>>, end_date: Option<DateTime<Utc>>, target_value: Option<i32>, reward_points: Option<i32>, ) -> Result<(), String>
Update challenge details (only allowed for Draft challenges)
Sourcepub fn update_description(&mut self, description: String) -> Result<(), String>
pub fn update_description(&mut self, description: String) -> Result<(), String>
Update challenge description
Sourcepub fn update_start_date(
&mut self,
start_date: DateTime<Utc>,
) -> Result<(), String>
pub fn update_start_date( &mut self, start_date: DateTime<Utc>, ) -> Result<(), String>
Update challenge start date
Sourcepub fn update_end_date(&mut self, end_date: DateTime<Utc>) -> Result<(), String>
pub fn update_end_date(&mut self, end_date: DateTime<Utc>) -> Result<(), String>
Update challenge end date
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Challenge
impl<'de> Deserialize<'de> for Challenge
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<Challenge> for ChallengeResponseDto
impl From<Challenge> for ChallengeResponseDto
Auto Trait Implementations§
impl Freeze for Challenge
impl RefUnwindSafe for Challenge
impl Send for Challenge
impl Sync for Challenge
impl Unpin for Challenge
impl UnwindSafe for Challenge
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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.