Skip to content

Image service#71

Merged
gitnasr merged 4 commits intodevfrom
image_service
Jun 13, 2025
Merged

Image service#71
gitnasr merged 4 commits intodevfrom
image_service

Conversation

@mariamalaa98
Copy link
Copy Markdown
Contributor

@mariamalaa98 mariamalaa98 commented Jun 12, 2025

Summary by CodeRabbit

  • New Features
    • Introduced an API endpoint for uploading image files, with validation for file type and size.
    • Added an endpoint to retrieve asset information by ID.
    • Implemented upload service logic to handle image uploads and asset creation.
  • Enhancements
    • Assets now store and return the associated user ID.
    • Asset data transfer objects and validation now include a user ID field.
  • Other Changes
    • Database seeding of categories and subcategories during startup has been disabled.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jun 12, 2025

Walkthrough

This update introduces a new image upload feature, including a controller, service, and interface for handling uploads and asset retrieval. It adds user association to asset entities and DTOs, configures dependency injection for the new service, and updates AutoMapper profiles. A database seed operation is also commented out in the startup logic.

Changes

File(s) Change Summary
Dentizone.Application/AutoMapper/Asset/AssetProfile.cs Added bidirectional mapping between Asset and CreateAssetDto in AutoMapper profile.
Dentizone.Application/DI/Services.cs Registered IUploadService with UploadService as a scoped service.
Dentizone.Application/Interfaces/IUploadService.cs Introduced IUploadService interface with methods for uploading images and finding assets by ID.
Dentizone.Application/Services/UploadService.cs Added UploadService implementing IUploadService, handling image uploads and asset retrieval.
Dentizone.Presentaion/Controllers/UploadController.cs Added UploadController with endpoints for image upload and asset retrieval by ID.
Dentizone.Application/DTOs/Asset/CreateAssetDto.cs Added UserId property to CreateAssetDto and corresponding validation rules.
Dentizone.Domain/Entity/Asset.cs Added UserId and navigation property User to Asset entity.
Dentizone.Presentaion/Program.cs Commented out database category and subcategory seeding during application startup.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant UploadController
    participant UploadService
    participant CloudinaryService
    participant AssetService

    Client->>UploadController: POST /api/upload/image (file)
    UploadController->>UploadService: UploadImageAsync(file, userId)
    UploadService->>CloudinaryService: UploadAsync(file stream)
    CloudinaryService-->>UploadService: Uploaded file URL
    UploadService->>AssetService: CreateAsset (metadata, userId)
    AssetService-->>UploadService: AssetDto
    UploadService-->>UploadController: AssetDto
    UploadController-->>Client: 200 OK (AssetDto)
Loading

Possibly related PRs

  • Asset service #47: Introduced the initial AssetProfile class and mappings, which this PR extends with additional bidirectional mapping.

Suggested labels

enhancement

Poem

A bunny with code in its ear 🐇
Now helps your images appear!
Uploads are safe, and users are linked,
With assets and DTOs perfectly synced.
A hop, a skip, a cloud in the sky—
Your pictures are stored, just give it a try!


📜 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 86f36df and 8d1b167.

📒 Files selected for processing (1)
  • Dentizone.Application/DI/Services.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Dentizone.Application/DI/Services.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

🧹 Nitpick comments (4)
Dentizone.Infrastructure/DependencyInjection/AddRepositories.cs (1)

16-16: Registration looks correct – keep the list sorted.

IAssetRepositoryAssetRepository is the right lifetime.
Minor nit: consider alphabetically ordering registrations for easier scanning.

Dentizone.Application/AutoMapper/Asset/AssetProfile.cs (1)

18-18: Mapping OK, but watch out for overload proliferation.

The extra Asset ↔ CreateAssetDto map is valid, just ensure overlapping maps don’t become ambiguous when you add custom ForMember rules later.

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

18-21: _mapper is injected but never used.

If mapping is not required, drop the dependency to reduce coupling; otherwise, use it.

Dentizone.Presentaion/Controllers/UploadController.cs (1)

33-44: REST semantics & naming

  1. Method name getAssetById uses camel-case; keep interface & implementation Pascal-case (GetAssetByIdAsync) for consistency.
  2. Route get-asset-by-id/{id} is RPC-style and verbose. Prefer /assets/{id} and return 200 OK with the asset representation (or 404) instead of a message wrapper.

Not blocking, but improves API ergonomics.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 90e4b1c and bc3048f.

📒 Files selected for processing (6)
  • Dentizone.Application/AutoMapper/Asset/AssetProfile.cs (1 hunks)
  • Dentizone.Application/DI/Services.cs (2 hunks)
  • Dentizone.Application/Interfaces/IUploadService.cs (1 hunks)
  • Dentizone.Application/Services/UploadService.cs (1 hunks)
  • Dentizone.Infrastructure/DependencyInjection/AddRepositories.cs (1 hunks)
  • Dentizone.Presentaion/Controllers/UploadController.cs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
Dentizone.Application/DI/Services.cs (2)
Dentizone.Domain/Entity/Asset.cs (1)
  • Asset (6-18)
Dentizone.Application/Services/UploadService.cs (2)
  • UploadService (16-57)
  • UploadService (22-27)
Dentizone.Application/AutoMapper/Asset/AssetProfile.cs (2)
Dentizone.Domain/Entity/Asset.cs (1)
  • Asset (6-18)
Dentizone.Application/DTOs/Asset/CreateAssetDto.cs (1)
  • CreateAssetDto (6-11)
Dentizone.Application/Interfaces/IUploadService.cs (2)
Dentizone.Application/Services/UploadService.cs (2)
  • Task (29-37)
  • Task (39-52)
Dentizone.Application/DTOs/Asset/AssetDto.cs (1)
  • AssetDto (5-11)
Dentizone.Presentaion/Controllers/UploadController.cs (2)
Dentizone.Application/Interfaces/IUploadService.cs (2)
  • Task (13-13)
  • Task (14-14)
Dentizone.Application/Services/UploadService.cs (2)
  • Task (29-37)
  • Task (39-52)
🔇 Additional comments (1)
Dentizone.Application/DI/Services.cs (1)

27-28: Good addition – services correctly registered.

IUploadService and IAssetService are scoped like the rest of the application services – LGTM.

@gitnasr gitnasr requested review from Copilot and gitnasr June 13, 2025 08:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces new image upload functionality with two API endpoints: one for uploading images and returning their URLs, and another for checking asset existence by ID, along with necessary service and repository registrations.

  • Introduced UploadController with endpoints for uploading images and asset lookup.
  • Added UploadService and related DI registrations for handling image uploads and assets.
  • Updated AutoMapper configuration to include mapping for asset DTOs.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Dentizone.Presentaion/Controllers/UploadController.cs New endpoints for image upload and asset lookup.
Dentizone.Infrastructure/DependencyInjection/AddRepositories.cs Added asset repository DI registration.
Dentizone.Application/Services/UploadService.cs Implemented upload functionality and asset check logic.
Dentizone.Application/Interfaces/IUploadService.cs Defined upload service interface for image handling.
Dentizone.Application/DI/Services.cs Registered new services in the DI container.
Dentizone.Application/AutoMapper/Asset/AssetProfile.cs Updated AutoMapper configuration for asset mappings.
Comments suppressed due to low confidence (3)

Dentizone.Application/Services/UploadService.cs:29

  • Method names in C# should follow PascalCase; consider renaming 'getAssetById' to 'GetAssetById'.
public  async Task<bool> getAssetById(string id)

Dentizone.Application/Services/UploadService.cs:43

  • [nitpick] Variable 'added_image_to_our_DB' should follow camelCase conventions; consider renaming it to 'addedImageToDb'.
var added_image_to_our_DB= await _assetService.CreateAssetAsync(new CreateAssetDto

Dentizone.Application/Interfaces/IUploadService.cs:14

  • Interface method names should use PascalCase; consider renaming 'getAssetById' to 'GetAssetById' to maintain consistency with C# conventions.
public Task<bool> getAssetById(string id);

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: 4

♻️ Duplicate comments (3)
Dentizone.Application/Interfaces/IUploadService.cs (1)

8-10: 🛠️ Refactor suggestion

Async-suffix missing & signature drift

FindAssetById returns Task<AssetDto> but omits the Async suffix → violates .NET naming guidelines and breaks discoverability alongside other async API.

-public Task<AssetDto> FindAssetById(string id);
+Task<AssetDto> FindAssetByIdAsync(string id);
Dentizone.Presentaion/Controllers/UploadController.cs (2)

7-8: ⚠️ Potential issue

Namespace typo breaks endpoint discovery.

Dentizone.PresentaionDentizone.Presentation. The misspelled assembly/route namespace prevents MVC from finding the controller.

-namespace Dentizone.Presentaion.Controllers
+namespace Dentizone.Presentation.Controllers

11-15: 🛠️ Refactor suggestion

Missing [Consumes] + [FromForm] attributes & incorrect DI-style ctor.

  1. Multipart binding is fragile without [Consumes("multipart/form-data")] and [FromForm] IFormFile file.
  2. Primary-ctor syntax for controllers is C# 12 only – confirm LangVersion or switch to classic ctor for wider TFMs.
 [HttpPost("image")]
+[Consumes("multipart/form-data")]
 [Authorize]
-public async Task<IActionResult> UploadImageAsync(IFormFile file)
+public async Task<IActionResult> UploadImageAsync([FromForm] IFormFile file)
🧹 Nitpick comments (3)
Dentizone.Application/DTOs/Asset/CreateAssetDto.cs (1)

27-29: Validation chain: add Cascade(CascadeMode.Stop) for clearer errors.

If UserId is empty the second rule still evaluates. Use cascade to avoid redundant messages.

-RuleFor(x => x.UserId)
+RuleFor(x => x.UserId)
+    .Cascade(CascadeMode.Stop)
Dentizone.Presentaion/Controllers/UploadController.cs (2)

20-25: Unprofessional exception message.

API error strings should be actionable & neutral for clients.

-throw new BadActionException("Why you upload non image man?");
+throw new BadActionException("Only JPG, JPEG, PNG or WEBP images are allowed.");

27-31: Hard-coded size limit: make it configurable & reuse constant.

Move 10 * 1024 * 1024 to a configuration option or FileSizeLimits constant to avoid magic numbers.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bc3048f and 86f36df.

📒 Files selected for processing (13)
  • Dentizone.Application/DTOs/Asset/CreateAssetDto.cs (2 hunks)
  • Dentizone.Application/Interfaces/IUploadService.cs (1 hunks)
  • Dentizone.Application/Services/UploadService.cs (1 hunks)
  • Dentizone.Domain/Entity/Asset.cs (1 hunks)
  • Dentizone.Infrastructure/Migrations/20250606212156_Update.Designer.cs (0 hunks)
  • Dentizone.Infrastructure/Migrations/20250606212156_Update.cs (0 hunks)
  • Dentizone.Infrastructure/Migrations/20250609100443_UpdateCats.Designer.cs (0 hunks)
  • Dentizone.Infrastructure/Migrations/20250609100443_UpdateCats.cs (0 hunks)
  • Dentizone.Infrastructure/Migrations/20250611212139_Merge.Designer.cs (0 hunks)
  • Dentizone.Infrastructure/Migrations/20250611212139_Merge.cs (0 hunks)
  • Dentizone.Infrastructure/Migrations/AppDbContextModelSnapshot.cs (0 hunks)
  • Dentizone.Presentaion/Controllers/UploadController.cs (1 hunks)
  • Dentizone.Presentaion/Program.cs (1 hunks)
💤 Files with no reviewable changes (7)
  • Dentizone.Infrastructure/Migrations/20250609100443_UpdateCats.cs
  • Dentizone.Infrastructure/Migrations/AppDbContextModelSnapshot.cs
  • Dentizone.Infrastructure/Migrations/20250606212156_Update.Designer.cs
  • Dentizone.Infrastructure/Migrations/20250611212139_Merge.Designer.cs
  • Dentizone.Infrastructure/Migrations/20250609100443_UpdateCats.Designer.cs
  • Dentizone.Infrastructure/Migrations/20250606212156_Update.cs
  • Dentizone.Infrastructure/Migrations/20250611212139_Merge.cs
✅ Files skipped from review due to trivial changes (1)
  • Dentizone.Presentaion/Program.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • Dentizone.Application/Services/UploadService.cs
🧰 Additional context used
🧬 Code Graph Analysis (2)
Dentizone.Application/Interfaces/IUploadService.cs (3)
Dentizone.Domain/Entity/Asset.cs (1)
  • Asset (6-21)
Dentizone.Application/Services/UploadService.cs (2)
  • Task (13-17)
  • Task (19-32)
Dentizone.Application/DTOs/Asset/AssetDto.cs (1)
  • AssetDto (5-11)
Dentizone.Domain/Entity/Asset.cs (3)
Dentizone.Domain/Entity/UserAsset.cs (1)
  • UserAsset (6-21)
Dentizone.Domain/Entity/PostAsset.cs (1)
  • PostAsset (5-16)
Dentizone.Domain/Entity/AppUser.cs (1)
  • AppUser (6-32)
🔇 Additional comments (2)
Dentizone.Domain/Entity/Asset.cs (1)

20-20: Navigation property should be nullable or guarded.

public virtual AppUser User { get; set; } is non-nullable but can be null for orphan assets, causing NRT warnings at call-sites.
Either mark it nullable (AppUser?) or enforce required relationship in the DbContext.

Dentizone.Application/DTOs/Asset/CreateAssetDto.cs (1)

12-13: UserId added here but missing from AssetDto.

The read-model (AssetDto) no longer mirrors the write-model – callers that rely on AssetDto cannot see the associated user.
Ensure the projection DTO is updated or intentionally omit the field with justification.

Copy link
Copy Markdown
Contributor

@gitnasr gitnasr left a comment

Choose a reason for hiding this comment

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

Approved with No Changes

@gitnasr gitnasr merged commit 75f1ac6 into dev Jun 13, 2025
1 check passed
@gitnasr gitnasr self-assigned this Jun 13, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jun 28, 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.

3 participants