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: update user details and add crud operation on user #24

Merged
merged 10 commits into from
Feb 28, 2024

Conversation

Harish-osmosys
Copy link
Contributor

@Harish-osmosys Harish-osmosys commented Feb 27, 2024

Document : User-crud-operations.docx

  • Add new api end point for update user : {{Base}}/api/users/{userId}
  • Add new api end point to delete user : {{Base}}/api/users/{userId}
  • Add the Check for the status column in the Get user Api
  • Updated the user to get additional field like country and phone number

For the Delete Api we are setting the status of user as 0 in user table and Locking out the login using

await _userManager.SetLockoutEnabledAsync(identityUser, true).ConfigureAwait(false);
await _userManager.SetLockoutEndDateAsync(identityUser, DateTimeOffset.MaxValue).ConfigureAwait(false);

Summary by CodeRabbit

  • New Features
    • Enhanced user profile management with the ability to update and delete user accounts.
    • Expanded user details to include country, email, phone number, and user roles in profiles.
  • Database Changes
    • Updated the database schema to accommodate new user information fields and improved user management.
  • API Enhancements
    • Introduced new endpoints for updating and deleting users via the API.
  • Refactor
    • Improved nullability handling in authentication and user profile processes.
  • Bug Fixes
    • Adjusted email service configuration to ensure reliability in password reset emails.

@Harish-osmosys Harish-osmosys self-assigned this Feb 27, 2024
Copy link
Contributor

coderabbitai bot commented Feb 27, 2024

Walkthrough

The DotnetFoundation project has enhanced user management capabilities with updates across DTOs, entity validation, and infrastructure. These changes introduce new features like default property values, additional user information fields, and improved user management methods, enriching the system's flexibility and robustness.

Changes

Files Change Summary
.../Models/DTOs/AuthenticationDTO/LoginRequest.cs,
.../Models/DTOs/AuthenticationDTO/PasswordResetRequest.cs
Default values set for Email and Password in LoginRequest, Token, and Password in PasswordResetRequest.
.../Models/DTOs/AuthenticationDTO/RegisterRequest.cs Added Country and [Phone]-annotated PhoneNumber properties.
.../Models/DTOs/UserDTO/UserResponse.cs Added Email, Country, and PhoneNumber properties.
.../Models/DTOs/UserDTO/UserRoleRequest.cs Email property in UserRoleRequest now has a default value.
.../Domain/Entities/User.cs Validation attributes added for Country, PhoneNumber, and Email.
.../Infrastructure/Identity/IdentityApplicationUser.cs Initialization of ApplicationUser property changed from null! to String.Empty.

🐰✨
Changes here, changes there,
Our code hops forward, light as air.
With fields anew and methods bright,
We manage users, day and night.
Through schema's dance and DTOs' flight,
Our project grows, to our delight.
🌟🐾

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9c29387 and e49461d.
Files selected for processing (9)
  • DotnetFoundation/DotnetFoundation.Api/Controllers/UserController.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Interfaces/Persistence/IUsersRepository.cs (2 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Interfaces/Services/IUsersService.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/AuthenticationDTO/RegisterRequest.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/UserDTO/UserResponse.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/UserDTO/UserUpdateRequest.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Domain/Entities/User.cs (2 hunks)
  • DotnetFoundation/DotnetFoundation.Infrastructure/Persistence/UserRepository.cs (3 hunks)
  • DotnetFoundation/DotnetFoundation.Services/Services/UserService/UserService.cs (1 hunks)
Additional comments: 9
DotnetFoundation/DotnetFoundation.Application/Models/DTOs/UserDTO/UserUpdateRequest.cs (1)
  • 1-3: The introduction of the UpdateUserRequest record with nullable properties for user details is a good approach for supporting partial updates. Ensure that the consuming update logic appropriately handles null values to prevent unintended behavior.
DotnetFoundation/DotnetFoundation.Domain/Entities/User.cs (1)
  • 10-12: The addition of the [Phone] validation attribute to the PhoneNumber property is appropriate for ensuring valid phone number formats. Consider adding validation or comments for the Country property if specific formats or validations are expected.
DotnetFoundation/DotnetFoundation.Application/Interfaces/Services/IUsersService.cs (1)
  • 10-11: The addition of UpdateUserAsync and DeleteUserAsync methods to the IUserService interface aligns well with the CRUD operations' objectives, providing clear and concise definitions for updating and deleting users. The method signatures are consistent and adhere to best practices.
DotnetFoundation/DotnetFoundation.Application/Models/DTOs/UserDTO/UserResponse.cs (1)
  • 20-22: The addition of Email, Country, and PhoneNumber properties to the UserResponse class enriches the response with more detailed user information, aligning well with the objectives of enhancing user retrieval. The properties are consistent and well-integrated with the rest of the class.
DotnetFoundation/DotnetFoundation.Application/Models/DTOs/AuthenticationDTO/RegisterRequest.cs (1)
  • 15-17: The addition of Country and PhoneNumber properties to the RegisterRequest class, with the [Phone] attribute on PhoneNumber, is appropriate for capturing more detailed user information during registration. These changes enrich the user model and align well with the objectives of enhancing user data.
DotnetFoundation/DotnetFoundation.Application/Interfaces/Persistence/IUsersRepository.cs (1)
  • 17-18: The addition of UpdateUserAsync and DeleteUserAsync methods to the IUserRepository interface aligns well with the CRUD operations' objectives, providing clear and concise definitions for updating and deleting users. The method signatures are consistent and adhere to best practices.
DotnetFoundation/DotnetFoundation.Services/Services/UserService/UserService.cs (1)
  • 37-46: The implementation of DeleteUserAsync and UpdateUserAsync methods in the UserService class provides clear functionality for deleting and updating users, respectively. Consider implementing more specific error handling or logging to enhance maintainability and debuggability.
DotnetFoundation/DotnetFoundation.Api/Controllers/UserController.cs (1)
  • 76-98: The implementation of UpdateUserAsync and DeleteUserAsync methods in the UserController follows RESTful principles and includes appropriate checks, such as validating the request body in UpdateUserAsync. Consider enhancing error handling to provide more specific feedback to clients.
DotnetFoundation/DotnetFoundation.Infrastructure/Persistence/UserRepository.cs (1)
  • 141-164: The implementation of UpdateUserAsync with dynamic property updates is handled carefully, aligning with security best practices by limiting updates to allowed properties. This approach addresses potential security concerns effectively.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e49461d and f8a41ff.
Files selected for processing (1)
  • DotnetFoundation/DotnetFoundation.Infrastructure/Persistence/UserRepository.cs (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • DotnetFoundation/DotnetFoundation.Infrastructure/Persistence/UserRepository.cs

@Harish-osmosys Harish-osmosys changed the title [WIP] update user details and add crud operation on user feat: update user details and add crud operation on user Feb 27, 2024
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.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f8a41ff and 00056f4.
Files selected for processing (4)
  • DotnetFoundation/DotnetFoundation.Infrastructure/Migrations/20240227105735_UPDATE_USER_TABLE.Designer.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Infrastructure/Migrations/20240227105735_UPDATE_USER_TABLE.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Infrastructure/Migrations/SqlDatabaseContextModelSnapshot.cs (2 hunks)
  • DotnetFoundation/DotnetFoundation.Infrastructure/Persistence/UserRepository.cs (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • DotnetFoundation/DotnetFoundation.Infrastructure/Persistence/UserRepository.cs
Additional comments: 1
DotnetFoundation/DotnetFoundation.Infrastructure/Migrations/20240227105735_UPDATE_USER_TABLE.cs (1)
  • 38-48: The reversal operations in the Down method correctly remove the added columns, ensuring the migration is reversible. This is a good practice for maintaining database integrity across migrations.

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.

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 00056f4 and bd2b66d.
Files selected for processing (4)
  • DotnetFoundation/DotnetFoundation.Application/Interfaces/Persistence/IUsersRepository.cs (2 hunks)
  • DotnetFoundation/DotnetFoundation.Infrastructure/Migrations/20240228001806_UpdateUserTable.Designer.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Infrastructure/Migrations/20240228001806_UpdateUserTable.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Services/Services/UserService/UserService.cs (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • DotnetFoundation/DotnetFoundation.Application/Interfaces/Persistence/IUsersRepository.cs
  • DotnetFoundation/DotnetFoundation.Services/Services/UserService/UserService.cs
Additional comments: 2
DotnetFoundation/DotnetFoundation.Infrastructure/Migrations/20240228001806_UpdateUserTable.cs (1)
  • 36-49: The Down method correctly removes the newly added columns (Country, Email, PhoneNumber) when rolling back the migration. This ensures the database schema can be reverted to its previous state, maintaining the integrity of the migration process.
DotnetFoundation/DotnetFoundation.Infrastructure/Migrations/20240228001806_UpdateUserTable.Designer.cs (1)
  • 17-330: The rest of the auto-generated model builder configuration appears to correctly reflect the changes made to the database schema and the entity model. It's important to ensure that these changes are consistent with the application's data handling and validation logic, especially regarding the new fields.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between bd2b66d and 0b94045.
Files selected for processing (1)
  • DotnetFoundation/DotnetFoundation.Infrastructure/Persistence/UserRepository.cs (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • DotnetFoundation/DotnetFoundation.Infrastructure/Persistence/UserRepository.cs

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.

Review Status

Actionable comments generated: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0b94045 and b860924.
Files selected for processing (13)
  • DotnetFoundation/DotnetFoundation.Api/Controllers/UserController.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Interfaces/Persistence/IUsersRepository.cs (2 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Interfaces/Services/IUsersService.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/AuthenticationDTO/AuthenticationResponse.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/AuthenticationDTO/LoginRequest.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/AuthenticationDTO/PasswordResetRequest.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/AuthenticationDTO/RegisterRequest.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/UserDTO/UserResponse.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/UserDTO/UserRoleRequest.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Domain/Entities/User.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Infrastructure/Integrations/EmailService.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Infrastructure/Persistence/UserRepository.cs (3 hunks)
  • DotnetFoundation/DotnetFoundation.Services/Services/UserService/UserService.cs (2 hunks)
Files skipped from review as they are similar to previous changes (7)
  • DotnetFoundation/DotnetFoundation.Api/Controllers/UserController.cs
  • DotnetFoundation/DotnetFoundation.Application/Interfaces/Persistence/IUsersRepository.cs
  • DotnetFoundation/DotnetFoundation.Application/Interfaces/Services/IUsersService.cs
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/AuthenticationDTO/RegisterRequest.cs
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/UserDTO/UserResponse.cs
  • DotnetFoundation/DotnetFoundation.Domain/Entities/User.cs
  • DotnetFoundation/DotnetFoundation.Services/Services/UserService/UserService.cs
Additional comments: 7
DotnetFoundation/DotnetFoundation.Application/Models/DTOs/AuthenticationDTO/AuthenticationResponse.cs (1)
  • 11-11: The change to make the Token property nullable is understood and seems appropriate for scenarios where an authentication attempt might not produce a token. Ensure that all consumer code is updated to handle the possibility of a null Token value appropriately.
DotnetFoundation/DotnetFoundation.Infrastructure/Integrations/EmailService.cs (1)
  • 39-39: The use of the null-forgiving operator (!) asserts that the configuration value for the forget password email path is expected to be non-null. Ensure that this configuration value is always provided to avoid runtime exceptions.
DotnetFoundation/DotnetFoundation.Infrastructure/Persistence/UserRepository.cs (5)
  • 92-94: Adding Country, PhoneNumber, and Email fields in the AddUserAsync method aligns with the PR's objectives to enhance user details management. Ensure that these new fields are validated appropriately to maintain data integrity.
  • 119-130: The inclusion of Country and PhoneNumber fields in the GetAllUsersAsync method supports the enhanced user details management. Verify that these fields are used consistently across the application to ensure a cohesive user experience.
  • 134-141: The addition of Country and PhoneNumber filters in the GetUserByIdAsync method is a positive change. Ensure that these filters are applied correctly and tested thoroughly to maintain the accuracy of user queries.
  • 142-164: The UpdateUserAsync method introduces dynamic property updates. Given the previous learning about security concerns, ensure that this method only allows updating properties that are safe to change dynamically and that input validation is enforced to prevent injection attacks or unintended updates.
  • 166-187: The DeleteUserAsync method implements a soft delete mechanism by setting the user's status to INACTIVE and enabling lockout. This approach aligns with the PR's objectives for a soft delete functionality. Ensure that this method is thoroughly tested, especially the lockout functionality, to prevent unintended access by inactive users.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between b860924 and fbc31f7.
Files selected for processing (7)
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/AuthenticationDTO/LoginRequest.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/AuthenticationDTO/PasswordResetRequest.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/AuthenticationDTO/RegisterRequest.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/UserDTO/UserResponse.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/UserDTO/UserRoleRequest.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Domain/Entities/User.cs (1 hunks)
  • DotnetFoundation/DotnetFoundation.Infrastructure/Identity/IdentityApplicationUser.cs (1 hunks)
Files skipped from review as they are similar to previous changes (6)
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/AuthenticationDTO/LoginRequest.cs
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/AuthenticationDTO/PasswordResetRequest.cs
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/AuthenticationDTO/RegisterRequest.cs
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/UserDTO/UserResponse.cs
  • DotnetFoundation/DotnetFoundation.Application/Models/DTOs/UserDTO/UserRoleRequest.cs
  • DotnetFoundation/DotnetFoundation.Domain/Entities/User.cs

@sameer-s-b sameer-s-b merged commit af6a459 into main Feb 28, 2024
1 check passed
@sameer-s-b sameer-s-b deleted the user-crud-operation branch February 28, 2024 11:11
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.

2 participants