Skip to content

Conversation

SIkebe
Copy link
Collaborator

@SIkebe SIkebe commented Sep 25, 2025

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:

  • Added the 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]
  • Registered MessageSearchService as a scoped dependency in the service container. (src/RazorPagesProject/Program.cs src/RazorPagesProject/Program.csR51)
  • Added a new GET endpoint at /messages/filter that accepts an optional term query parameter and returns matching messages as JSON. (src/RazorPagesProject/Program.cs src/RazorPagesProject/Program.csR77-R86)

Other changes:

@Copilot Copilot AI review requested due to automatic review settings September 25, 2025 07:35
Copy link
Contributor

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

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

Comment on lines +23 to +26
var sql = $"SELECT Id, Text FROM Messages WHERE Text LIKE '%{term}%'";

return await dbContext.Messages
.FromSqlRaw(sql)
Copy link

Copilot AI Sep 25, 2025

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

Suggested change
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;
Copy link

Copilot AI Sep 25, 2025

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.

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