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

Add User model and repository for user management functionality #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RickardHF
Copy link
Owner

This pull request introduces new functionality for managing user information within the MythApi application. The changes include adding a User model, creating endpoints for user operations, implementing a repository pattern for database interactions, and adding unit tests to ensure the correctness of the new features.

New User Management Functionality:

  • User Model:

    • Added User class to represent user data (src/Common/Database/Models/User.cs).
    • Added UserInput class to handle user input data (src/Users/Models/UserInput.cs).
  • Database Context:

    • Updated AppDbContext to include DbSet<User> for user data (src/Common/Database/AppDBContext.cs). [1] [2]
  • User Endpoints:

    • Created Users static class to register user-related endpoints and handle user operations (src/Endpoints/v1/Users.cs).
  • Repository Pattern:

    • Implemented UserRepository class to manage user data in the database (src/Users/DbRepositories/UserRepository.cs).
    • Defined IUserRepository interface for user repository operations (src/Users/Interfaces/IUserRepository.cs).
  • Unit Tests:

    • Added unit tests to verify the functionality of user operations and ensure input encoding to prevent XSS attacks (tests/UnitTests/UsersTest.cs).

@RickardHF RickardHF requested a review from Copilot January 20, 2025 12:07
Copy link

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

Copilot reviewed 5 out of 7 changed files in this pull request and generated 2 comments.

Files not reviewed (2)
  • src/Common/Database/AppDBContext.cs: Evaluated as low risk
  • src/Users/Interfaces/IUserRepository.cs: Evaluated as low risk

{
if (user.Id.HasValue && _context.Users.Any(x => x.Id == user.Id))
{
_context.Users.FromSqlRaw($"UPDATE Users SET Name = '{user.Name}', Bio = '{user.Bio}' WHERE Id = {user.Id}");
Copy link
Preview

Copilot AI Jan 20, 2025

Choose a reason for hiding this comment

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

The use of FromSqlRaw with string interpolation can lead to SQL injection vulnerabilities. Use parameterized queries or Entity Framework's built-in methods to avoid this risk.

Suggested change
_context.Users.FromSqlRaw($"UPDATE Users SET Name = '{user.Name}', Bio = '{user.Bio}' WHERE Id = {user.Id}");
var existingUser = _context.Users.First(x => x.Id == user.Id); existingUser.Name = user.Name; existingUser.Bio = user.Bio;

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Name = user.Name,
Bio = user.Bio
};
_context.Users.FromSqlRaw($"INSERT INTO Users (Name, Bio) VALUES ('{user.Name}', '{user.Bio}')");
Copy link
Preview

Copilot AI Jan 20, 2025

Choose a reason for hiding this comment

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

The use of FromSqlRaw with string interpolation can lead to SQL injection vulnerabilities. Use parameterized queries or Entity Framework's built-in methods to avoid this risk.

Suggested change
_context.Users.FromSqlRaw($"INSERT INTO Users (Name, Bio) VALUES ('{user.Name}', '{user.Bio}')");
_context.Users.Add(newUser);

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
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