Conversation
| { | ||
| 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}"); |
There was a problem hiding this comment.
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; |
| Name = user.Name, | ||
| Bio = user.Bio | ||
| }; | ||
| _context.Users.FromSqlRaw($"INSERT INTO Users (Name, Bio) VALUES ('{user.Name}', '{user.Bio}')"); |
There was a problem hiding this comment.
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces new functionality for managing user information within the MythApi application. The changes include adding a
Usermodel, 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:
Userclass to represent user data (src/Common/Database/Models/User.cs).UserInputclass to handle user input data (src/Users/Models/UserInput.cs).Database Context:
AppDbContextto includeDbSet<User>for user data (src/Common/Database/AppDBContext.cs). [1] [2]User Endpoints:
Usersstatic class to register user-related endpoints and handle user operations (src/Endpoints/v1/Users.cs).Repository Pattern:
UserRepositoryclass to manage user data in the database (src/Users/DbRepositories/UserRepository.cs).IUserRepositoryinterface for user repository operations (src/Users/Interfaces/IUserRepository.cs).Unit Tests:
tests/UnitTests/UsersTest.cs).