app.services.user_service module¶
- class app.services.user_service.UserService(user_repository, user_points_repository, task_repository, wallet_repository, wallet_transaction_repository)[source]¶
Bases:
BaseServiceService class for managing users.
- Parameters:
user_repository (UserRepository)
user_points_repository (UserPointsRepository)
task_repository (TaskRepository)
wallet_repository (WalletRepository)
wallet_transaction_repository (WalletTransactionRepository)
- user_repository¶
Repository instance for users.
- Type:
- user_points_repository¶
Repository instance for user points.
- Type:
- task_repository¶
Repository instance for tasks.
- Type:
- wallet_repository¶
Repository instance for wallets.
- Type:
- wallet_transaction_repository¶
Repository instance for wallet transactions.
- __init__(user_repository, user_points_repository, task_repository, wallet_repository, wallet_transaction_repository)[source]¶
Initializes the UserService with the provided repositories.
- Parameters:
user_repository (UserRepository) – The user repository instance.
user_points_repository (UserPointsRepository) – The user points repository instance.
task_repository (TaskRepository) – The task repository instance.
wallet_repository (WalletRepository) – The wallet repository instance.
wallet_transaction_repository (WalletTransactionRepository) – The wallet transaction repository instance.
- Return type:
None
- async basic_engagement_points()[source]¶
- Provides a fixed number of points as a basic engagement reward for a
user’s initial actions within the gamification system.
- Returns:
int – The fixed number of basic engagement points.
- Return type:
int
- async performance_penalty_points()[source]¶
- Calculates the number of points to deduct as a penalty for performance
below a certain threshold.
- Returns:
int – The number of points to deduct.
- Return type:
int
- async performance_bonus_points()[source]¶
- Calculates the number of additional points to award for performance
above a certain threshold.
- Returns:
int – The number of bonus points to award.
- Return type:
int
- async individual_over_global_points()[source]¶
- Awards additional points for users who have improved their individual
- performance compared to their own history, even if below the global
average.
- Returns:
int – The number of additional points to award.
- Return type:
int
- async need_for_motivation_points()[source]¶
- Provides a small point incentive for users who are underperforming
both individually and globally, to motivate improvement.
- Returns:
int – The number of points to award as motivation.
- Return type:
int
- async peak_performer_bonus_points()[source]¶
- Rewards users who have exceeded both their individual performance and
the global average, standing out as peak performers in the system.
- Returns:
int – The number of bonus points for peak performers.
- Return type:
int
- async global_advantage_adjustment_points()[source]¶
- Awards additional points to users whose performance is above the
- global average but have shown a decrease in their individual
- performance. It’s designed to encourage users to strive for
- above-average performance, recognizing their effort amidst
challenges.
- Returns:
int –
- The number of adjustment points for maintaining a global
advantage.
- Return type:
int
- async individual_adjustment_points()[source]¶
- Rewards users who have improved their individual performance,
- regardless of their standing against the global average. It aims to
- acknowledge and encourage personal improvement, motivating users
to keep advancing.
- Returns:
int –
- The number of points to award for individual performance
improvement.
- Return type:
int
- async create_user(schema)[source]¶
Creates a new user using the provided schema.
- Parameters:
schema – The schema representing the user to be created.
- Returns:
object – The created user.
- Return type:
Any
- async assign_points_to_user(userId, schema, apiKey_used=None)[source]¶
Assigns points to a user based on the provided schema.
- Parameters:
userId (str) – The user ID.
schema (BaseUserPointsBaseModel) – The schema containing point assignment details.
apiKey_used (str)
- Returns:
UserPointsAssigned – The assigned points details.
- Return type:
UserPointsAssigned
- async get_wallet_by_user_id(userId)[source]¶
Retrieves the wallet associated with a user by their user ID.
- Parameters:
userId (str) – The user ID.
- Returns:
UserWallet – The wallet details.
- Return type:
UserWallet
- async get_user_by_externalUserId(externalUserId)[source]¶
Retrieves a user by their external user ID.
- Parameters:
externalUserId (str) – The external user ID.
- Returns:
object – The user details.
- Return type:
Any
- async get_wallet_by_externalUserId(externalUserId, *, api_key=None, oauth_user_id=None, is_admin=False, enforce_scope=False)[source]¶
Retrieves the wallet associated with a user by their external user ID.
- Parameters:
externalUserId (str) – The external user ID.
api_key (str)
oauth_user_id (str)
is_admin (bool)
enforce_scope (bool)
- Returns:
UserWallet – The wallet details.
- Return type:
UserWallet
- async get_points_by_user_id(userId)[source]¶
Retrieves points associated with a user by their user ID.
- Parameters:
userId (str) – The user ID.
- Returns:
UserPointsTasks – The user’s points and associated tasks.
- Return type:
UserPointsTasks
- async preview_points_to_coins_conversion(userId, points)[source]¶
Previews the conversion of points to coins for a user.
- Parameters:
userId (str) – The user ID.
points (int) – The number of points to convert.
- Returns:
dict – The conversion preview details.
- Return type:
dict[str, Any]
- async preview_points_to_coins_conversion_externalUserId(externalUserId, points)[source]¶
- Previews the conversion of points to coins for a user by their
external user ID.
- Parameters:
externalUserId (str) – The external user ID.
points (int) – The number of points to convert.
- Returns:
dict – The conversion preview details.
- Return type:
dict[str, Any]
- async convert_points_to_coins(userId, schema, api_key)[source]¶
Converts points to coins for a user based on the provided schema.
- Parameters:
userId (str) – The user ID.
schema (PostPointsConversionRequest) – The schema containing conversion details. api_key (str): The API key.
- Returns:
ResponsePointsConversion – The conversion details.
- Return type:
ResponsePointsConversion
- async convert_points_to_coins_externalUserId(externalUserId, schema, api_key=None)[source]¶
- Converts points to coins for a user by their external user ID based on
the provided schema.
- Parameters:
externalUserId (str) – The external user ID.
schema (PostPointsConversionRequest) – The schema containing conversion details.
api_key (str) – The API key.
- Returns:
ResponsePointsConversion – The conversion details.
- Return type:
ResponsePointsConversion