Skip to content

Refactor services and enhance user activity logging#123

Merged
gitnasr merged 2 commits intodevfrom
user-activity
Jul 8, 2025
Merged

Refactor services and enhance user activity logging#123
gitnasr merged 2 commits intodevfrom
user-activity

Conversation

@gitnasr
Copy link
Copy Markdown
Contributor

@gitnasr gitnasr commented Jul 8, 2025

  • Removed GetSubmittedReviews from IReviewService and UpdateUserVerificationState from IVerificationService.
  • Updated role parsing in AuthService to ensure correct user role retrieval.
  • Corrected spelling of "Lockdout" to "Lockedout" in user activity logging.
  • Added user activity logging for registration, email verification, password reset, order actions, and QA interactions.
  • Refactored VerificationService for improved constructor handling and removed unnecessary methods.
  • Updated UserActivityService to set a default fingerprint token.
  • Enhanced UserActivities enum with new activity types and corrected spelling errors.

Summary by CodeRabbit

  • New Features

    • Expanded user activity tracking to include actions such as answering or asking questions, reviewing orders, creating withdrawal requests, registering, and requesting password resets.
    • User activities are now logged for order placement, cancellation, registration, email verification, password reset, and withdrawal requests.
  • Improvements

    • Enhanced accuracy in user activity logs by correcting and updating activity types.
    • Improved handling of user roles and activity tracking during authentication and order processes.
  • Bug Fixes

    • Corrected a typo in the user activity type for locked-out accounts.
  • Removals

    • Removed outdated or redundant review and verification update features.
    • Cleaned up unused or obsolete user activity types.
    • Removed endpoints for fetching submitted and received reviews from the user interface.

- Removed `GetSubmittedReviews` from `IReviewService` and `UpdateUserVerificationState` from `IVerificationService`.
- Updated role parsing in `AuthService` to ensure correct user role retrieval.
- Corrected spelling of "Lockdout" to "Lockedout" in user activity logging.
- Added user activity logging for registration, email verification, password reset, order actions, and QA interactions.
- Refactored `VerificationService` for improved constructor handling and removed unnecessary methods.
- Updated `UserActivityService` to set a default fingerprint token.
- Enhanced `UserActivities` enum with new activity types and corrected spelling errors.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 8, 2025

Walkthrough

This change removes specific methods from the IReviewService and IVerificationService interfaces, eliminates related implementations and controller endpoints, and expands user activity tracking across multiple services by injecting and invoking IUserActivityService. The UserActivities enum is updated with new activity types and corrections. Several constructors are updated to accept the new service dependency.

Changes

Files/Paths Change Summary
Dentizone.Application/Interfaces/IReviewService.cs, Dentizone.Application/Interfaces/IVerificationService.cs Removed GetSubmittedReviews and UpdateUserVerificationState methods from interfaces.
Dentizone.Presentaion/Controllers/ReviewController.cs Removed GetSubmittedReviews and GetReceivedReviews HTTP GET endpoints.
Dentizone.Application/Services/Authentication/AuthService.cs Updated role parsing logic, fixed enum typo, and added user activity logging for several actions.
Dentizone.Application/Services/Authentication/VerificationService.cs Added IUserActivityService to constructor, removed status mapping/update methods, refactored usage.
Dentizone.Application/Services/OrderService.cs, Dentizone.Application/Services/QAService.cs, Dentizone.Application/Services/ReviewService.cs, Dentizone.Application/Services/WithdrawalService.cs Injected IUserActivityService and added activity logging for order, QA, review, and withdrawal actions.
Dentizone.Application/Services/UserActivityService.cs Hardcoded fingerprint token to "NON" instead of retrieving dynamically.
Dentizone.Domain/Enums/UserActivity.cs Updated enum: removed, renamed, and added several user activity types.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Service (Order/QA/Review/Withdrawal)
    participant UserActivityService

    User->>Service: Perform Action (e.g., Place Order, Ask Question)
    Service->>UserActivityService: CreateAsync(activityType, timestamp, userId)
    UserActivityService-->>Service: Log Activity
    Service-->>User: Return Result
Loading

Possibly related PRs

Poem

A bunny hopped through code so wide,
Adding logs for every stride.
Activities tracked, enums anew,
Old methods gone, the list grew.
With every hop and every run,
The audit trail has just begun!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd4d23d and 6be348f.

📒 Files selected for processing (2)
  • Dentizone.Application/Services/OrderService.cs (3 hunks)
  • Dentizone.Presentaion/Controllers/ReviewController.cs (0 hunks)
💤 Files with no reviewable changes (1)
  • Dentizone.Presentaion/Controllers/ReviewController.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • Dentizone.Application/Services/OrderService.cs
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🔭 Outside diff range comments (2)
Dentizone.Domain/Enums/UserActivity.cs (1)

6-20: Remove unused Register enum; retain distinct password-reset events

  • UserActivities.Register isn’t referenced anywhere in the codebase and can be removed to avoid dead code.
  • UserActivities.Registered is used by AuthService to log completed registrations—keep it.
  • Both PasswordReset (when the reset actually occurs) and PasswordResetRequested (when the reset email is sent) are used in different contexts—retain both.

Proposed diff:

--- a/Dentizone.Domain/Enums/UserActivity.cs
+++ b/Dentizone.Domain/Enums/UserActivity.cs
@@ enum UserActivities
-        Register,
         Logout,
         PasswordReset,
         OrderPlaced,
         OrderCancelled,
         AccountVerified,
         Lockedout,
         EmailConfirmed,
         AnsweredQuestion,
         AskedQuestion,
         ReviewedOrder,
         WithdrawalRequestCreated,
         Registered,
         EmailVerificationSent,
         PasswordResetRequested
Dentizone.Application/Services/Authentication/VerificationService.cs (1)

27-74: Consider logging user activity for verification session creation.

The method creates a verification session but doesn't log this important user activity. Given the PR's focus on enhancing user activity logging, this would be a good candidate for activity tracking.

Add user activity logging at the end of the method:

    var session = await diditApi.CreateSessionAsync(request, secretService.GetSecret("DiditApi"));
    await userService.SetKycStatusAsync(userId, KycStatus.NotSubmitted);
+   await userActivityService.LogAsync(userId, UserActivities.VerificationStarted, "KYC verification session created");
    
    await mailService.Send(user.Email!, "Dentizone: Verification Started",
        // ... rest of email sending
    );
🧹 Nitpick comments (1)
Dentizone.Application/Services/Authentication/VerificationService.cs (1)

76-79: Consider adding user activity logging for verification status checks.

This method retrieves verification status, which could be valuable to track for audit purposes and user activity monitoring.

Add logging before returning the result:

public async Task<SessionDecisionResponse> GetVerificationStatusAsync(string sessionId)
{
    var result = await diditApi.GetSessionDecisionAsync(sessionId, secretService.GetSecret("DiditApi"));
+   // Note: You may need to extract userId from sessionId or pass it as parameter
+   // await userActivityService.LogAsync(userId, UserActivities.VerificationStatusChecked, "Verification status checked");
    return result;
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3a70c7 and cd4d23d.

📒 Files selected for processing (10)
  • Dentizone.Application/Interfaces/IReviewService.cs (0 hunks)
  • Dentizone.Application/Interfaces/IVerificationService.cs (0 hunks)
  • Dentizone.Application/Services/Authentication/AuthService.cs (7 hunks)
  • Dentizone.Application/Services/Authentication/VerificationService.cs (3 hunks)
  • Dentizone.Application/Services/OrderService.cs (3 hunks)
  • Dentizone.Application/Services/QAService.cs (4 hunks)
  • Dentizone.Application/Services/ReviewService.cs (3 hunks)
  • Dentizone.Application/Services/UserActivityService.cs (1 hunks)
  • Dentizone.Application/Services/WithdrawalService.cs (2 hunks)
  • Dentizone.Domain/Enums/UserActivity.cs (1 hunks)
💤 Files with no reviewable changes (2)
  • Dentizone.Application/Interfaces/IReviewService.cs
  • Dentizone.Application/Interfaces/IVerificationService.cs
🧰 Additional context used
🧠 Learnings (2)
Dentizone.Application/Services/ReviewService.cs (3)
Learnt from: gitnasr
PR: dentizone/api#104
File: Dentizone.Presentaion/Controllers/ReviewController.cs:24-24
Timestamp: 2025-06-29T09:03:23.566Z
Learning: In the Dentizone application, users cannot edit reviews once they are submitted. Only admins can update or delete reviews, likely for moderation purposes. This means review updates and deletions should be restricted to admin-only authorization rather than ownership-based authorization.
Learnt from: gitnasr
PR: dentizone/api#104
File: Dentizone.Presentaion/Controllers/PostsController.cs:60-61
Timestamp: 2025-06-29T09:04:16.858Z
Learning: The Dentizone application uses global middleware to handle exceptions, which means controller methods don't need individual try-catch blocks. Service layer exceptions are centrally caught and translated to appropriate HTTP responses through this middleware.
Learnt from: gitnasr
PR: dentizone/api#16
File: Dentizone.Infrastructure/Persistence/Configurations/OrderConfiguration.cs:1-1
Timestamp: 2025-05-28T11:22:49.051Z
Learning: In the Dentizone.Infrastructure project, the IsDeleted property from IBaseEntity is handled through Entity Framework interceptors rather than explicit configuration in individual entity configuration files. This means entity configurations don't need to explicitly configure the IsDeleted property.
Dentizone.Application/Services/Authentication/AuthService.cs (1)
Learnt from: gitnasr
PR: dentizone/api#104
File: Dentizone.Presentaion/Controllers/ReviewController.cs:24-24
Timestamp: 2025-06-29T09:03:23.566Z
Learning: In the Dentizone application, users cannot edit reviews once they are submitted. Only admins can update or delete reviews, likely for moderation purposes. This means review updates and deletions should be restricted to admin-only authorization rather than ownership-based authorization.
🧬 Code Graph Analysis (1)
Dentizone.Application/Services/ReviewService.cs (1)
Dentizone.Application/Services/BaseService.cs (1)
  • BaseService (10-72)
🔇 Additional comments (18)
Dentizone.Domain/Enums/UserActivity.cs (1)

12-12: Good spelling correction.

The typo fix from "Lockdout" to "Lockedout" improves code quality and consistency.

Dentizone.Application/Services/Authentication/VerificationService.cs (1)

19-25: Primary constructor syntax is supported in net9.0
All project files target <TargetFramework>net9.0</TargetFramework>, which defaults to C# 12 (and even C# 13) without an explicit <LangVersion>. The primary‐constructor syntax in VerificationService is therefore valid—no changes needed.

Dentizone.Application/Services/UserActivityService.cs (1)

23-23: Verify the rationale for hardcoding the fingerprint token.

The fingerprint token is now hardcoded to "NON" instead of being retrieved from the request context service. This change should be verified to ensure it's intentional and aligns with the application's security and tracking requirements.

Consider whether this is:

  • A temporary workaround that should be documented
  • A permanent change due to fingerprint tracking being disabled
  • A default value for scenarios where fingerprint retrieval fails

If this is temporary, consider adding a TODO comment to track the intended future implementation.

Dentizone.Application/Services/WithdrawalService.cs (2)

20-20: LGTM: Proper dependency injection for user activity service.

The constructor correctly includes the IUserActivityService dependency to enable activity logging.


50-51: LGTM: Appropriate user activity logging for withdrawal requests.

The user activity logging is correctly placed after successful withdrawal request creation and uses the appropriate enum value with proper parameters.

Dentizone.Application/Services/ReviewService.cs (3)

6-6: LGTM: Necessary using statement for UserActivities enum.

The using statement is properly added to access the UserActivities enum used in the activity logging.


20-20: LGTM: Proper dependency injection for user activity service.

The constructor correctly includes the IUserActivityService dependency to enable activity logging.


41-41: LGTM: Appropriate user activity logging for order reviews.

The user activity logging is correctly placed after successful review creation and uses the appropriate enum value with proper parameters.

Dentizone.Application/Services/OrderService.cs (1)

29-29: LGTM: Proper dependency injection for user activity service.

The constructor correctly includes the IUserActivityService dependency to enable activity logging.

Dentizone.Application/Services/Authentication/AuthService.cs (7)

39-39: Verify safety of role parsing change.

The change from FirstOrDefault() to First() removes the null-coalescing fallback. While there's a null/empty check above (lines 34-37), ensure this change doesn't introduce potential exceptions if the collection state changes unexpectedly.

The null/empty check above should prevent issues, but verify that all code paths leading to this method maintain this invariant.


74-74: LGTM: Typo correction and proper user activity logging.

The typo "Lockdout" has been corrected to "Lockedout" and the user activity logging is properly implemented for lockout events.


114-114: Verify safety of role parsing change.

The change from LastOrDefault() to Last() removes the null-coalescing fallback. While there's a null/empty check above (lines 95-98), ensure this change doesn't introduce potential exceptions if the collection state changes unexpectedly.

The null/empty check above should prevent issues, but verify that all code paths leading to this method maintain this invariant.


148-148: LGTM: Proper user activity logging for registration.

The user activity logging is correctly placed after successful user registration and uses the appropriate enum value with proper parameters.


205-206: LGTM: Improved email formatting and user activity logging.

The email link formatting has been improved and user activity logging is properly implemented for email verification events.


223-224: LGTM: Improved email formatting and user activity logging.

The email link formatting has been improved and user activity logging is properly implemented for password reset request events.


256-256: LGTM: Proper user activity logging for password reset.

The user activity logging is correctly placed after successful password reset and uses the appropriate enum value with proper parameters.

Dentizone.Application/Services/QAService.cs (2)

15-21: LGTM: Constructor properly updated with new dependency.

The constructor correctly accepts the new IUserActivityService dependency, maintaining the primary constructor pattern used in the class.


113-120: LGTM: Formatting improvements maintain functionality.

The formatting changes to the includes array and FindAllBy method call improve readability without affecting the logic.

Comment on lines +13 to +20
EmailConfirmed,
AnsweredQuestion,
AskedQuestion,
ReviewedOrder,
WithdrawalRequestCreated,
Registered,
EmailVerificationSent,
PasswordResetRequested
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Address naming inconsistencies and potential duplicates.

The new activity additions are valuable for comprehensive user tracking, but there are some naming concerns:

  1. Potential duplicates:

    • Register (line 6) vs Registered (line 18) - these appear to represent the same user registration activity
    • PasswordReset (line 8) vs PasswordResetRequested (line 20) - these might also be duplicates
  2. Naming convention inconsistency:

    • Mix of past tense (EmailConfirmed, AnsweredQuestion), present tense (Register), and descriptive forms (WithdrawalRequestCreated)

Consider standardizing the naming convention and removing duplicates to improve API clarity.

public enum UserActivities
{
    Login,
-   Register,
    Logout,
-   PasswordReset,
    OrderPlaced,
    OrderCancelled,
    AccountVerified,
    Lockedout,
    EmailConfirmed,
    AnsweredQuestion,
    AskedQuestion,
    ReviewedOrder,
    WithdrawalRequestCreated,
    Registered,
    EmailVerificationSent,
    PasswordResetRequested
}
🤖 Prompt for AI Agents
In Dentizone.Domain/Enums/UserActivity.cs around lines 6 to 20, there are
duplicate enum entries for user registration and password reset activities, and
inconsistent naming conventions mixing past tense, present tense, and
descriptive forms. To fix this, remove the duplicate entries by choosing either
Register or Registered and either PasswordReset or PasswordResetRequested, then
standardize all enum names to use a consistent tense and style, preferably past
tense for completed actions, to improve clarity and maintainability.

Comment on lines 82 to 86
public async Task<UserView> UpdateUserNationalId(string userId, string nationalId)
{
var output = await _userService.SetNationalId(userId, nationalId);
var output = await userService.SetNationalId(userId, nationalId);
return output;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add user activity logging for national ID updates.

Updating a user's national ID is a significant action that should be logged for security and audit purposes.

Add activity logging after the successful update:

public async Task<UserView> UpdateUserNationalId(string userId, string nationalId)
{
    var output = await userService.SetNationalId(userId, nationalId);
+   await userActivityService.LogAsync(userId, UserActivities.NationalIdUpdated, "National ID updated");
    return output;
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public async Task<UserView> UpdateUserNationalId(string userId, string nationalId)
{
var output = await _userService.SetNationalId(userId, nationalId);
var output = await userService.SetNationalId(userId, nationalId);
return output;
}
public async Task<UserView> UpdateUserNationalId(string userId, string nationalId)
{
var output = await userService.SetNationalId(userId, nationalId);
await userActivityService.LogAsync(userId, UserActivities.NationalIdUpdated, "National ID updated");
return output;
}
🤖 Prompt for AI Agents
In Dentizone.Application/Services/Authentication/VerificationService.cs around
lines 82 to 86, the UpdateUserNationalId method updates the user's national ID
but lacks logging of this significant action. After successfully updating the
national ID, add a call to the user activity logging service to record this
event, including relevant details such as userId and the action performed, to
ensure proper security and audit tracking.

Comment on lines +19 to +25
public class VerificationService(
IDiditApi diditApi,
ISecretService secretService,
IAuthService authService,
IUserService userService,
IUserActivityService userActivityService,
IMailService mailService) : IVerificationService
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Unused dependency injection detected.

The IUserActivityService userActivityService is injected in the constructor but never used in any of the methods. This suggests either incomplete implementation or dead code.

Based on the PR objectives to "enhance user activity logging," this service should likely be used to log verification-related activities such as session starts, verification status checks, and national ID updates.

Consider adding user activity logging in the relevant methods:

public async Task<CreateSessionResponse> StartSessionAsync(string userId)
{
    var user = await authService.GetById(userId);
    var domainUser = await userService.GetByIdAsync(userId);
    
+   await userActivityService.LogAsync(userId, UserActivities.VerificationStarted, "KYC verification session started");
    
    // ... rest of the method
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public class VerificationService(
IDiditApi diditApi,
ISecretService secretService,
IAuthService authService,
IUserService userService,
IUserActivityService userActivityService,
IMailService mailService) : IVerificationService
public async Task<CreateSessionResponse> StartSessionAsync(string userId)
{
var user = await authService.GetById(userId);
var domainUser = await userService.GetByIdAsync(userId);
await userActivityService.LogAsync(userId, UserActivities.VerificationStarted, "KYC verification session started");
// ... rest of the method
}
🤖 Prompt for AI Agents
In Dentizone.Application/Services/Authentication/VerificationService.cs around
lines 19 to 25, the IUserActivityService is injected but not used. To fix this,
identify key verification-related methods such as session starts, verification
status checks, and national ID updates, and add calls to IUserActivityService to
log these user activities appropriately. This will ensure the injected service
is utilized as intended for enhanced user activity logging.

await cartService.ClearCartAsync(buyerId);

await transaction.CommitAsync();
await userActivityService.CreateAsync(UserActivities.OrderPlaced, new DateTime(), buyerId);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix DateTime usage for user activity logging.

The new DateTime() creates a default DateTime value (01/01/0001 00:00:00) instead of the current timestamp. This should be DateTime.UtcNow or DateTime.Now to properly track when the activity occurred.

-                await userActivityService.CreateAsync(UserActivities.OrderPlaced, new DateTime(), buyerId);
+                await userActivityService.CreateAsync(UserActivities.OrderPlaced, DateTime.UtcNow, buyerId);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await userActivityService.CreateAsync(UserActivities.OrderPlaced, new DateTime(), buyerId);
await userActivityService.CreateAsync(UserActivities.OrderPlaced, DateTime.UtcNow, buyerId);
🤖 Prompt for AI Agents
In Dentizone.Application/Services/OrderService.cs at line 193, replace the
incorrect usage of new DateTime() with DateTime.UtcNow or DateTime.Now to log
the current timestamp for user activity. This change ensures the activity time
reflects the actual order placement time instead of the default minimum DateTime
value.

Comment on lines +67 to +69
job.ReviewQuestionAsync(question.Id, question.Text));

await userActivity.CreateAsync(UserActivities.AskedQuestion, DateTime.UtcNow, askerId);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider error handling for user activity logging.

Similar to the AnswerQuestionAsync method, the user activity logging lacks error handling and could potentially fail the entire question creation operation.

Apply the same error handling pattern as suggested for the AnswerQuestionAsync method.

 _backgroundJob.Enqueue<IMonitorJob>(job =>
     job.ReviewQuestionAsync(question.Id, question.Text));

-await userActivity.CreateAsync(UserActivities.AskedQuestion, DateTime.UtcNow, askerId);
+try
+{
+    await userActivity.CreateAsync(UserActivities.AskedQuestion, DateTime.UtcNow, askerId);
+}
+catch (Exception ex)
+{
+    // Log the error but don't fail the operation
+    // Consider using ILogger to log the exception
+}
🤖 Prompt for AI Agents
In Dentizone.Application/Services/QAService.cs around lines 67 to 69, the call
to userActivity.CreateAsync for logging the AskedQuestion activity lacks error
handling, which may cause the entire question creation to fail if logging fails.
Wrap this call in a try-catch block similar to the pattern used in
AnswerQuestionAsync, catching exceptions and handling them appropriately (e.g.,
logging the error) without interrupting the main flow.

Comment on lines +54 to +55
job.ReviewAnswerAsync(answer.Id, answer.Text));
await userActivity.CreateAsync(UserActivities.AnsweredQuestion, DateTime.UtcNow, responderId);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider error handling for user activity logging.

The user activity logging is added appropriately after the core business logic, but lacks error handling. If userActivity.CreateAsync fails, it could cause the entire operation to fail even though the question was successfully answered.

Consider wrapping the activity logging in a try-catch block or making it fire-and-forget to prevent it from affecting the primary operation.

 _backgroundJob.Enqueue<IMonitorJob>(job =>
     job.ReviewAnswerAsync(answer.Id, answer.Text));
-await userActivity.CreateAsync(UserActivities.AnsweredQuestion, DateTime.UtcNow, responderId);
+try
+{
+    await userActivity.CreateAsync(UserActivities.AnsweredQuestion, DateTime.UtcNow, responderId);
+}
+catch (Exception ex)
+{
+    // Log the error but don't fail the operation
+    // Consider using ILogger to log the exception
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
job.ReviewAnswerAsync(answer.Id, answer.Text));
await userActivity.CreateAsync(UserActivities.AnsweredQuestion, DateTime.UtcNow, responderId);
_backgroundJob.Enqueue<IMonitorJob>(job =>
job.ReviewAnswerAsync(answer.Id, answer.Text));
try
{
await userActivity.CreateAsync(UserActivities.AnsweredQuestion, DateTime.UtcNow, responderId);
}
catch (Exception ex)
{
// Log the error but don't fail the operation
// Consider using ILogger to log the exception
}
🤖 Prompt for AI Agents
In Dentizone.Application/Services/QAService.cs around lines 54 to 55, the call
to userActivity.CreateAsync lacks error handling, which could cause the entire
operation to fail if logging fails. To fix this, wrap the
userActivity.CreateAsync call in a try-catch block to catch and handle any
exceptions without affecting the main operation, or alternatively, make the call
fire-and-forget by not awaiting it and handling exceptions internally.

Modified OrderService to use DateTime.UtcNow for user activity
timestamp. Removed GetSubmittedReviews and GetReceivedReviews
methods from ReviewController, retaining only GetAllReviews
for admin access.
@gitnasr gitnasr merged commit 3fda673 into dev Jul 8, 2025
1 check passed
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Jul 8, 2025

@coderabbitai coderabbitai bot mentioned this pull request Jul 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant