Skip to content

Add post approval and rejection endpoints with email notification#111

Merged
gitnasr merged 3 commits intodevfrom
nourleyy/PostReviewSystem
Jul 3, 2025
Merged

Add post approval and rejection endpoints with email notification#111
gitnasr merged 3 commits intodevfrom
nourleyy/PostReviewSystem

Conversation

@Nourleyy
Copy link
Copy Markdown
Contributor

@Nourleyy Nourleyy commented Jul 3, 2025

Introduced ApprovePost and RejectPost endpoints in PostsController for admins to update post status. PostService now sends an email notification to the seller when a post is approved.

Summary by CodeRabbit

  • New Features

    • Added admin-only endpoint to update post status with optional rejection reason.
    • Sellers receive email notifications upon post approval or rejection with reason.
  • Enhancements

    • Extended post status updates to include detailed reasons and automatic seller notifications.

Introduced ApprovePost and RejectPost endpoints in PostsController for admins to update post status. PostService now sends an email notification to the seller when a post is approved.
@korbit-ai
Copy link
Copy Markdown

korbit-ai bot commented Jul 3, 2025

You've used up your 5 PR reviews for this month under the Korbit Starter Plan. You'll get 5 more reviews on July 30th, 2025 or you can upgrade to Pro for unlimited PR reviews and enhanced features in your Korbit Console.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 3, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes add email notifications to the post status update process, sending approval or rejection emails to sellers. A new admin-only PATCH endpoint AdjustStatus is introduced in the posts controller to update post status with an optional rejection reason. A new DTO encapsulates the update data.

Changes

File(s) Change Summary
Dentizone.Application/Services/PostService.cs Added IMailService dependency; updated UpdatePostStatus to accept optional reason; sends email notifications
Dentizone.Presentaion/Controllers/PostsController.cs Added admin-only PATCH endpoint AdjustStatus to update post status with optional reason
Dentizone.Application/DTOs/Post/UpdatePostStateDto.cs Added new DTO UpdatePostStateDto with PostId, Status, and optional Reason
Dentizone.Application/Interfaces/IPostService.cs Updated UpdatePostStatus method signature to include optional reason parameter
Dentizone.Application/Services/OrderService.cs Added optional reason strings to calls of UpdatePostStatus; minor formatting and import cleanup

Sequence Diagram(s)

sequenceDiagram
    participant Admin
    participant PostsController
    participant PostService
    participant IMailService
    participant Seller

    Admin->>PostsController: PATCH /posts/adjustStatus (PostId, Status, Reason?)
    PostsController->>PostService: UpdatePostStatus(PostId, Status, Reason)
    PostService->>PostService: Retrieve post with seller info
    PostService->>PostService: Update post status
    alt Status is Active
        PostService->>IMailService: Send approval email to Seller
    else Status is Rejected and Reason provided
        PostService->>IMailService: Send rejection email with reason to Seller
    end
    PostService-->>PostsController: Return updated post DTO
    PostsController-->>Admin: Return updated post response
Loading

Poem

🐇
A status change, a note to send,
To sellers waiting ‘round the bend.
Admins patch with reason clear,
Approval cheers or reasons drear.
Mail wings swift on digital breeze,
Bringing news with gentle ease.
Hoppity-hop, the updates please! 🥕📧


📜 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 5d30c1d and e394581.

📒 Files selected for processing (1)
  • Dentizone.Application/Services/OrderService.cs (7 hunks)
✨ 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: 3

🧹 Nitpick comments (1)
Dentizone.Application/Services/PostService.cs (1)

2-2: Remove unused import.

The Azure.Core namespace is imported but not used in this file.

-using Azure.Core;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1f93951 and aa1ee95.

📒 Files selected for processing (2)
  • Dentizone.Application/Services/PostService.cs (3 hunks)
  • Dentizone.Presentaion/Controllers/PostsController.cs (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
Dentizone.Presentaion/Controllers/PostsController.cs (2)
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.

@gitnasr gitnasr self-requested a review July 3, 2025 17:02
- Updated `IPostService` to include a nullable `reason` parameter in `UpdatePostStatus`.
- Modified `PostService` to implement the new parameter and added `NotifySellerAsync` for email notifications.
- Replaced `ApprovePost` and `RejectPost` methods in `PostsController` with a unified `AdjustStatus` method using `UpdatePostStateDto`.
- Introduced `UpdatePostStateDto` to encapsulate post status update parameters.
- Cleaned up unused `using` directives in `PostService` and `PostsController`.
@gitnasr gitnasr added the enhancement New feature or request label Jul 3, 2025
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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aa1ee95 and 5d30c1d.

📒 Files selected for processing (4)
  • Dentizone.Application/DTOs/Post/UpdatePostStateDto.cs (1 hunks)
  • Dentizone.Application/Interfaces/IPostService.cs (1 hunks)
  • Dentizone.Application/Services/PostService.cs (4 hunks)
  • Dentizone.Presentaion/Controllers/PostsController.cs (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Dentizone.Application/DTOs/Post/UpdatePostStateDto.cs
🚧 Files skipped from review as they are similar to previous changes (2)
  • Dentizone.Presentaion/Controllers/PostsController.cs
  • Dentizone.Application/Services/PostService.cs
🧰 Additional context used
🧬 Code Graph Analysis (1)
Dentizone.Application/Interfaces/IPostService.cs (1)
Dentizone.Application/DTOs/Post/PostViewDTO.cs (1)
  • PostViewDto (5-20)

Task<List<PostViewDto>> Search(UserPreferenceDto userPreferenceDto);
Task<List<Domain.Entity.Post>> ValidatePosts(List<string> postIds);
Task<PostViewDto> UpdatePostStatus(string postId, PostStatus status);
Task<PostViewDto> UpdatePostStatus(string postId, PostStatus status, string? reason);
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.

💡 Verification agent

🧩 Analysis chain

Good addition for enhanced post status communication.

The optional reason parameter is a sensible enhancement that allows providing explanations when updating post status, particularly useful for rejections. The nullable string type is appropriate for this optional parameter.

Note that this is a breaking change to the interface - ensure all implementations of IPostService have been updated to include this parameter.


🏁 Script executed:

#!/bin/bash
# Description: Verify all implementations of IPostService have been updated with the new signature
# Expected: All implementations should include the reason parameter

# Search for classes implementing IPostService
ast-grep --pattern 'class $_ : $$$IPostService$$$'

# Search for UpdatePostStatus method implementations  
ast-grep --pattern 'UpdatePostStatus($$$) {'

Length of output: 99


I’ll double-check all C# files to find where IPostService is referenced, which classes implement it, and verify each UpdatePostStatus signature.


🏁 Script executed:

#!/bin/bash
echo "1) All references to IPostService:"
rg -n --no-heading --color never --glob '*.cs' "IPostService"

echo
echo "2) Classes implementing IPostService:"
rg -nP --no-heading --color never --glob '*.cs' "class\s+\w+\s*:\s*.*IPostService"

echo
echo "3) All UpdatePostStatus definitions/calls:"
rg -n --no-heading --color never --glob '*.cs' "UpdatePostStatus"

Length of output: 1981


Action Required: Update all UpdatePostStatus invocations to include the new reason argument

The nullable reason parameter is a sensible enhancement for communicating rejection details, but existing calls need to be updated to avoid breakage. Specifically:

  • Dentizone.Application/Services/OrderService.cs
    • Line 75: await postService.UpdatePostStatus(post.Id, PostStatus.Active);
    • Line 170: await postService.UpdatePostStatus(post.Id, PostStatus.Sold);
      → Add a third argument (e.g. null or a message) for the new reason parameter.

Verify there are no other two-argument calls to UpdatePostStatus across the codebase.

🤖 Prompt for AI Agents
In Dentizone.Application/Services/OrderService.cs at lines 75 and 170, the calls
to UpdatePostStatus currently pass only two arguments, but the method signature
now requires a third nullable reason parameter. Update these calls by adding a
third argument, such as null or an appropriate message string, to match the new
method signature. Also, search the entire codebase for any other calls to
UpdatePostStatus with only two arguments and update them similarly to prevent
compilation errors.

- Added using directive for Dentizone.Application.DTOs.Payment.
- Updated CancelOrderAsync to include reason for post status change.
- Modified email notifications for order cancellation and new orders for consistency.
- Improved code readability by removing unnecessary line breaks and reformatting method calls.
@gitnasr gitnasr merged commit 23b0099 into dev Jul 3, 2025
1 check was pending
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Jul 3, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants