Skip to content

Add User model and repository for user management functionality#13

Open
RickardHF wants to merge 2 commits intomainfrom
user-page
Open

Add User model and repository for user management functionality#13
RickardHF wants to merge 2 commits intomainfrom
user-page

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

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 uses AI. Check for mistakes.
Name = user.Name,
Bio = user.Bio
};
_context.Users.FromSqlRaw($"INSERT INTO Users (Name, Bio) VALUES ('{user.Name}', '{user.Bio}')");
Copy link

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 uses AI. Check for mistakes.
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

Comments