Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for supplied transmission attachment ID on create/update #1242

Merged

Conversation

oskogstad
Copy link
Collaborator

@oskogstad oskogstad commented Oct 7, 2024

Description

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Documentation

  • Documentation is updated (either in docs-directory, Altinnpedia or a separate linked PR in altinn-studio-docs., if applicable)

Summary by CodeRabbit

  • New Features

    • Introduced id properties in CreateDialogTransmissionAttachmentDto and UpdateDialogTransmissionAttachmentDto for better management of transmission attachments.
    • Added validation rules for Id properties to ensure they are valid UUID version 7 with past timestamps.
  • Bug Fixes

    • Enhanced validation logic during dialog creation and updates to prevent duplicate transmission attachments.
  • Documentation

    • Updated XML comments for clarity and consistency.

These changes enhance the API's functionality, ensuring better tracking and validation of transmission attachments.

@oskogstad oskogstad requested a review from a team as a code owner October 7, 2024 12:09
Copy link
Contributor

coderabbitai bot commented Oct 7, 2024

Warning

Rate limit exceeded

@oskogstad has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 57 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between be4e026 and ca7434f.

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces significant updates to the Dialogporten API's OpenAPI specification and related classes. Key changes include the addition of id properties in the CreateDialogTransmissionAttachmentDto and UpdateDialogTransmissionAttachmentDto schemas, enhancing the management of transmission attachments. Validation logic has been improved by implementing checks for existing attachment IDs during dialog creation and updates. Additionally, new validation rules for UUIDs have been added across various DTOs. The mapping configurations have also been updated to include the new id properties, ensuring they are properly handled in the mapping process.

Changes

File Change Summary
docs/schema/V1/swagger.verified.json Added id property to CreateDialogTransmissionAttachmentDto and UpdateDialogTransmissionAttachmentDto; updated descriptions for existing properties.
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommand.cs Enhanced EnsureNoExistingUserDefinedIds method to include checks for existing transmission attachment IDs.
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs Added validation rule for Id property in CreateDialogTransmissionAttachmentDto to ensure valid UUIDv7 format.
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogDto.cs Added Id property to CreateDialogTransmissionAttachmentDto; updated XML comments for formatting consistency.
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/MappingProfile.cs Updated mappings for UpdateDialogTransmissionAttachmentDto and UpdateDialogTransmissionAttachmentUrlDto to include Id property.
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommand.cs Added validation logic in AppendTransmission method to check for existing transmission attachment IDs.
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs Introduced UpdateDialogTransmissionAttachmentDtoValidator with validation rules for Id property; updated existing validator for clarity.
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogDto.cs Added nullable Id property to UpdateDialogTransmissionAttachmentDto to support idempotent creation of attachments.

Possibly related PRs

Suggested reviewers

  • MagnusSandgren
  • knuhau

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

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

🧹 Outside diff range comments (2)
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommand.cs (1)

Line range hint 1-125: Consider enhancing error handling and optimizing ID generation.

While the overall implementation is solid, consider the following suggestions for further improvement:

  1. Error Handling: Instead of adding errors to the DomainContext, consider throwing custom exceptions for each error case. This approach can make error handling more explicit and easier to manage at higher levels of the application.

  2. ID Generation: If the IDs for dialogs, activities, transmissions, and attachments are being generated on the client-side, consider moving this responsibility to the server-side. This can help prevent potential ID conflicts and reduce the need for existence checks.

Here's an example of how you might implement server-side ID generation:

public async Task<CreateDialogResult> Handle(CreateDialogCommand request, CancellationToken cancellationToken)
{
    var dialog = _mapper.Map<DialogEntity>(request);
    
    // Generate IDs server-side
    dialog.Id = Guid.NewGuid();
    foreach (var activity in dialog.Activities)
    {
        activity.Id = Guid.NewGuid();
    }
    foreach (var transmission in dialog.Transmissions)
    {
        transmission.Id = Guid.NewGuid();
        foreach (var attachment in transmission.Attachments)
        {
            attachment.Id = Guid.NewGuid();
        }
    }

    // Rest of the method remains the same
    // ...
}

This approach would eliminate the need for the EnsureNoExistingUserDefinedIds method altogether, simplifying the code and improving performance.

docs/schema/V1/swagger.verified.json (1)

Line range hint 1-4630: Consider updating API documentation for new ID fields.

The changes to both CreateDialogTransmissionAttachmentDto and UpdateDialogTransmissionAttachmentDto schemas are well-implemented and consistent. They improve the API by allowing for idempotent operations on transmission attachments.

To ensure API consumers can make the most of these new features:

  1. Consider updating any external API documentation to explain the usage and benefits of these new ID fields.
  2. If there are code examples or client SDKs, they may need to be updated to demonstrate how to use these fields effectively.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 3031d8d and be4e026.

📒 Files selected for processing (8)
  • docs/schema/V1/swagger.verified.json (4 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommand.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommandValidator.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogDto.cs (3 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/MappingProfile.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommand.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs (1 hunks)
  • src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogDto.cs (1 hunks)
🧰 Additional context used
🔇 Additional comments (9)
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogCommand.cs (1)

Line range hint 1-125: Summary: Approved with suggestions for improvement

The changes made to add support for supplied transmission attachment ID on create/update are well-implemented and consistent with the existing codebase. The new check for existing transmission attachment IDs enhances data integrity and prevents potential duplicates.

Key points:

  1. The implementation is approved and ready for merging.
  2. Minor optimization suggested for combining ID checks into a single database query.
  3. Consider enhancing error handling by using custom exceptions instead of adding to DomainContext.
  4. Explore the possibility of server-side ID generation to simplify the code and improve performance.

These suggestions aim to further improve the robustness and efficiency of the implementation without blocking the current changes from being merged.

src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/MappingProfile.cs (1)

84-84: LGTM: New mapping allows for transmission attachment ID updates.

The new mapping configuration allows the Id property to be mapped from UpdateDialogTransmissionAttachmentDto to DialogTransmissionAttachment. This change aligns with the PR objective of adding support for supplied transmission attachment IDs during updates.

To ensure all mentioned changes are present, please run the following script:

✅ Verification successful

Verified: Both mapping configurations are present.

All mapping changes mentioned in the review comment are confirmed and align with the PR objectives.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the presence of both mapping changes mentioned in the AI summary

# Test 1: Check for UpdateDialogTransmissionAttachmentDto mapping
echo "Checking UpdateDialogTransmissionAttachmentDto mapping:"
rg "CreateMap<UpdateDialogTransmissionAttachmentDto, DialogTransmissionAttachment>" src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/MappingProfile.cs

# Test 2: Check for UpdateDialogTransmissionAttachmentUrlDto mapping
echo "Checking UpdateDialogTransmissionAttachmentUrlDto mapping:"
rg "CreateMap<UpdateDialogTransmissionAttachmentUrlDto, AttachmentUrl>" src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/MappingProfile.cs

Length of output: 794

src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommand.cs (1)

Line range hint 1-424: Overall, the file demonstrates high-quality implementation.

The UpdateDialogCommandHandler class is well-structured and includes thorough validation checks for various aspects of the dialog update process. The new addition for checking existing transmission attachment IDs further enhances the robustness of the update operation.

Key strengths of this implementation:

  1. Comprehensive error handling and validation
  2. Proper use of dependency injection
  3. Clear separation of concerns in different methods
  4. Effective use of AutoMapper for object mapping
  5. Careful handling of entity relationships
src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogCommandValidator.cs (1)

117-120: Verify consistency of UUID v7 validation across the codebase

The addition of UUID v7 validation for the Id property in UpdateDialogTransmissionAttachmentDtoValidator is a good practice. To ensure consistency, it's recommended to verify if similar validation is applied to other DTOs that use UUID v7 as identifiers.

Run the following script to check for consistent UUID v7 validation across the codebase:

Review the output to ensure that all relevant DTOs with Id properties of type Guid have consistent UUID v7 validation.

src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Update/UpdateDialogDto.cs (1)

513-517: Verify handling of the new Id property throughout the codebase

The addition of the Id property to UpdateDialogTransmissionAttachmentDto is a significant change that may affect other parts of the codebase. While it doesn't require changes to other classes in this file, it's crucial to ensure proper handling of this new property when processing transmission attachments.

Please run the following script to check for potential impacts:

Review the output to ensure that all relevant parts of the codebase properly handle the new Id property, including any mapping configurations, validation logic, and data processing related to transmission attachments.

✅ Verification successful

Verified: Proper Handling of the New Id Property

The addition of the Id property to UpdateDialogTransmissionAttachmentDto is correctly integrated across the codebase. Validators ensure the Id is a valid UUIDv7 and that its timestamp is appropriate. Mapping profiles accurately map the Id to the domain entities, and database migrations accommodate the new property with necessary constraints and relationships. No issues were found in the current implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usage of UpdateDialogTransmissionAttachmentDto and potential places where the new Id property should be handled.

# Search for usages of UpdateDialogTransmissionAttachmentDto
echo "Searching for usages of UpdateDialogTransmissionAttachmentDto:"
rg --type csharp -A 5 "UpdateDialogTransmissionAttachmentDto"

# Search for potential mapping or processing of transmission attachments
echo "Searching for potential mapping or processing of transmission attachments:"
rg --type csharp -A 10 -e "TransmissionAttachment" -e "transmission.*attachment"

Length of output: 137593

src/Digdir.Domain.Dialogporten.Application/Features/V1/ServiceOwner/Dialogs/Commands/Create/CreateDialogDto.cs (2)

70-70: LGTM: Minor formatting improvements

The removal of trailing spaces in the XML comments for Process and SystemLabel properties improves code cleanliness. These changes don't affect functionality and are in line with good coding practices.

Also applies to: 107-107


Line range hint 1-573: Summary: Successful implementation of transmission attachment ID support

The changes in this file successfully implement the support for supplied transmission attachment ID on create/update, as outlined in the PR objectives. The addition of the Id property to CreateDialogTransmissionAttachmentDto allows for idempotent creation of transmission attachments, which can improve system reliability and prevent duplicate entries.

The changes are localized and don't affect other parts of the file. They maintain consistency with the existing code style and patterns. The minor formatting improvements in XML comments contribute to better code readability.

Overall, these changes enhance the functionality of the dialog creation process while maintaining the integrity of the existing codebase.

docs/schema/V1/swagger.verified.json (2)

754-760: LGTM! Good addition for idempotent operations.

The new id property in the CreateDialogTransmissionAttachmentDto schema is a welcome addition. It allows for idempotent creation of transmission attachments, which is a best practice in API design. The property is correctly defined as a nullable GUID with a clear description of its purpose.


4099-4105: LGTM! Consistent implementation for update operations.

The addition of the id property to the UpdateDialogTransmissionAttachmentDto schema is consistent with the changes made to the create operation. This ensures a uniform approach to handling transmission attachment IDs across different operations in the API. The property is correctly defined as a nullable GUID with an appropriate description.

Copy link

sonarcloud bot commented Oct 7, 2024

@oskogstad oskogstad merged commit c7bfb07 into main Oct 7, 2024
22 checks passed
@oskogstad oskogstad deleted the feat/support-id-input-when-creating-transmission-attachments branch October 7, 2024 12:41
oskogstad pushed a commit that referenced this pull request Oct 7, 2024
🤖 I have created a release *beep* *boop*
---


##
[1.22.0](v1.21.0...v1.22.0)
(2024-10-07)


### Features

* Add support for supplied transmission attachment ID on create/update
([#1242](#1242))
([c7bfb07](c7bfb07))


### Bug Fixes

* Only allow legacy HTML on AditionalInfo content
([#1210](#1210))
([aa4acde](aa4acde))
* **webAPI:** Specifying EndUserId on the ServiceOwner Search endpoint
produces 500 - Internal Server error
([#1234](#1234))
([49c0d34](49c0d34))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants