using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using UserManagement.Data.Dto;
using UserManagement.Data.Resources;
using UserManagement.MediatR.Commands;
using UserManagement.MediatR.Queries;
using UserManagement.Repository;
namespace UserManagement.API.Controllers
{
///
/// UserNotification
///
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class UserNotificationController : ControllerBase
{
public IMediator _mediator { get; set; }
///
/// UserNotification
///
///
public UserNotificationController(IMediator mediator)
{
_mediator = mediator;
}
///
/// Get Notifications for login user
///
///
[HttpGet("Notification")]
[Produces("application/json", "application/xml", Type = typeof(List))]
public async Task GetNotification()
{
var getAllUserNotificationQuery = new GetUserNotificationQuery { };
var result = await _mediator.Send(getAllUserNotificationQuery);
return Ok(result);
}
///
/// Get All Document Audit Trail detail
///
///
///
[HttpGet("Notifications")]
[Produces("application/json", "application/xml", Type = typeof(NotificationList))]
public async Task GetNotifications([FromQuery] NotificationResource notificationResource)
{
var getAllDocumentAuditTrailQuery = new GetAllUserNotificationQuery
{
NotificationResource = notificationResource
};
var result = await _mediator.Send(getAllDocumentAuditTrailQuery);
var paginationMetadata = new
{
totalCount = result.TotalCount,
pageSize = result.PageSize,
skip = result.Skip,
totalPages = result.TotalPages
};
Response.Headers.Append("X-Pagination",
JsonSerializer.Serialize(paginationMetadata));
return Ok(result);
}
///
/// Mark Notification as Read.
///
///
///
[HttpPost("MarkAsRead")]
public async Task MarkAsRead(MarkAsReadCommand markAsReadCommand)
{
await _mediator.Send(markAsReadCommand);
return Ok();
}
///
/// Mark All Notification As Read.
///
///
[HttpPost("MarkAllAsRead")]
public async Task MarkAllAsRead()
{
var markAllAsReadCommand = new MarkAllAsReadCommand();
await _mediator.Send(markAllAsReadCommand);
return Ok();
}
}
}