-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add IMessageSearchService and MessageSearchService for message … #518
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request introduces a new message search feature that allows filtering messages by a search term through a dedicated service and API endpoint.
- Adds
IMessageSearchService
interface andMessageSearchService
implementation for database-backed message searching - Registers the message search service in the dependency injection container
- Exposes a new
/messages/filter
GET endpoint that accepts a search term and returns matching messages as JSON
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/RazorPagesProject/Services/IMessageSearchService.cs |
Defines the interface contract for message search functionality |
src/RazorPagesProject/Services/MessageSearchService.cs |
Implements the message search service with SQL LIKE query logic |
src/RazorPagesProject/Program.cs |
Registers the service and adds the API endpoint for message filtering |
var sql = $"SELECT Id, Text FROM Messages WHERE Text LIKE '%{term}%'"; | ||
|
||
return await dbContext.Messages | ||
.FromSqlRaw(sql) |
Copilot
AI
Sep 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SQL query is vulnerable to SQL injection attacks because the term
parameter is directly interpolated into the SQL string. Use parameterized queries instead: dbContext.Messages.Where(m => EF.Functions.Like(m.Text, $\"%{term}%\")).AsNoTracking().ToListAsync()
var sql = $"SELECT Id, Text FROM Messages WHERE Text LIKE '%{term}%'"; | |
return await dbContext.Messages | |
.FromSqlRaw(sql) | |
// Use parameterized query with EF.Functions.Like to prevent SQL injection | |
return await dbContext.Messages | |
.Where(m => EF.Functions.Like(m.Text, $"%{term}%")) |
Copilot uses AI. Check for mistakes.
@@ -0,0 +1,30 @@ | |||
using System; |
Copilot
AI
Sep 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The using System;
directive is unnecessary since no System namespace types are directly used in this file. The Array.Empty<Message>()
call can be replaced with []
in C# 12 or new List<Message>()
to remove this dependency.
Copilot uses AI. Check for mistakes.
This pull request introduces a new message search feature to the project. It adds a scoped message search service, exposes a new API endpoint for filtering messages by a search term, and implements the service logic for querying messages from the database.
New message search functionality:
IMessageSearchService
interface and its implementation,MessageSearchService
, which provides asynchronous search capabilities for messages using a SQL LIKE query. (src/RazorPagesProject/Services/IMessageSearchService.cs
[1]src/RazorPagesProject/Services/MessageSearchService.cs
[2]MessageSearchService
as a scoped dependency in the service container. (src/RazorPagesProject/Program.cs
src/RazorPagesProject/Program.csR51)/messages/filter
that accepts an optionalterm
query parameter and returns matching messages as JSON. (src/RazorPagesProject/Program.cs
src/RazorPagesProject/Program.csR77-R86)Other changes:
using System;
directive toProgram.cs
. (src/RazorPagesProject/Program.cs
src/RazorPagesProject/Program.csR1)…filtering