add message type to search query
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using GozareshgirProgramManager.Application._Common.Interfaces;
|
||||
using GozareshgirProgramManager.Application._Common.Models;
|
||||
using GozareshgirProgramManager.Application.Modules.TaskChat.DTOs;
|
||||
using GozareshgirProgramManager.Domain.TaskChatAgg.Enums;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@@ -8,6 +9,7 @@ namespace GozareshgirProgramManager.Application.Modules.TaskChat.Queries.GetMess
|
||||
|
||||
public record GetMessagesQuery(
|
||||
Guid TaskId,
|
||||
MessageType? MessageType,
|
||||
int Page = 1,
|
||||
int PageSize = 50
|
||||
) : IBaseQuery<PaginationResult<MessageDto>>;
|
||||
@@ -34,7 +36,12 @@ public class GetMessagesQueryHandler : IBaseQueryHandler<GetMessagesQuery, Pagin
|
||||
var query = _context.TaskChatMessages
|
||||
.Where(m => m.TaskId == request.TaskId && !m.IsDeleted)
|
||||
.Include(m => m.ReplyToMessage)
|
||||
.OrderBy(m => m.CreationDate);
|
||||
.OrderBy(m => m.CreationDate).AsQueryable();
|
||||
|
||||
if (request.MessageType.HasValue)
|
||||
{
|
||||
query = query.Where(m => m.MessageType == request.MessageType.Value);
|
||||
}
|
||||
|
||||
var totalCount = await query.CountAsync(cancellationToken);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using GozareshgirProgramManager.Application.Modules.TaskChat.DTOs;
|
||||
using GozareshgirProgramManager.Application.Modules.TaskChat.Queries.GetMessages;
|
||||
using GozareshgirProgramManager.Application.Modules.TaskChat.Queries.GetPinnedMessages;
|
||||
using GozareshgirProgramManager.Application.Modules.TaskChat.Queries.SearchMessages;
|
||||
using GozareshgirProgramManager.Domain.TaskChatAgg.Enums;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ServiceHost.BaseControllers;
|
||||
@@ -30,15 +31,17 @@ public class TaskChatController : ProgramManagerBaseController
|
||||
/// دریافت لیست پیامهای یک تسک
|
||||
/// </summary>
|
||||
/// <param name="taskId">شناسه تسک</param>
|
||||
/// <param name="messageType">نوع پیام</param>
|
||||
/// <param name="page">صفحه (پیشفرض: 1)</param>
|
||||
/// <param name="pageSize">تعداد در هر صفحه (پیشفرض: 50)</param>
|
||||
[HttpGet("{taskId:guid}/messages")]
|
||||
public async Task<ActionResult<OperationResult<PaginationResult<MessageDto>>>> GetMessages(
|
||||
Guid taskId,
|
||||
[FromQuery] MessageType? messageType,
|
||||
[FromQuery] int page = 1,
|
||||
[FromQuery] int pageSize = 50)
|
||||
{
|
||||
var query = new GetMessagesQuery(taskId, page, pageSize);
|
||||
var query = new GetMessagesQuery(taskId,messageType, page, pageSize);
|
||||
var result = await _mediator.Send(query);
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user