using MediatR;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using System;
using UserManagement.Api.Helpers;
using UserManagement.Data.Dto;
using UserManagement.Data.Resources;
using UserManagement.MediatR.CommandAndQuery;
using UserManagement.MediatR.Commands;
using UserManagement.Repository;
using System.Linq;
using System.Text.Json;
using Microsoft.AspNetCore.Http;
namespace UserManagement.API.Controllers.Reminder
{
[Route("api/[controller]")]
[ApiController]
public class ReminderController : BaseController
{
public IMediator _mediator { get; set; }
///
/// Initializes a new instance of the class.
///
/// The mediator.
public ReminderController(IMediator mediator)
{
_mediator = mediator;
}
///
/// Gets the reminders.
///
/// The reminder resource.
///
[HttpGet("all")]
[Produces("application/json", "application/xml", Type = typeof(ReminderList))]
[ClaimCheck("reminder_list")]
public async Task GetReminders([FromQuery] ReminderResource reminderResource)
{
var getAllReminderQuery = new GetAllReminderQuery
{
ReminderResource = reminderResource
};
var result = await _mediator.Send(getAllReminderQuery);
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);
}
[HttpGet("all/currentuser")]
[Produces("application/json", "application/xml", Type = typeof(ReminderList))]
public async Task GetReminderForLoginUser([FromQuery] ReminderResource reminderResource)
{
var getReminderForLoginUserCommand = new GetReminderForLoginUserCommand
{
ReminderResource = reminderResource
};
var result = await _mediator.Send(getReminderForLoginUserCommand);
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);
}
///
/// Creates the reminder.
///
/// The add reminder command.
///
[HttpPost]
[Produces("application/json", "application/xml", Type = typeof(ReminderDto))]
[ClaimCheck("reminder_add")]
public async Task CreateReminder(AddReminderCommand addReminderCommand)
{
var result = await _mediator.Send(addReminderCommand);
return Ok(result);
}
///
/// Gets the reminder.
///
/// The identifier.
///
[HttpGet("{id}")]
[Produces("application/json", "application/xml", Type = typeof(ReminderList))]
public async Task GetReminder(Guid id)
{
var getReminderByIdQuery = new GetReminderByIdQuery
{
Id = id
};
var result = await _mediator.Send(getReminderByIdQuery);
return GenerateResponse(result);
}
///
/// Updates the reminder.
///
/// The identifier.
/// The update reminder command.
///
[HttpPost("{id}")]
[Produces("application/json", "application/xml", Type = typeof(ReminderDto))]
[ClaimCheck("reminder_edit")]
public async Task UpdateReminder(Guid id, UpdateReminderCommand updateReminderCommand)
{
var result = await _mediator.Send(updateReminderCommand);
return GenerateResponse(result);
}
[HttpDelete("{id}/currentuser")]
[Produces("application/json", "application/xml", Type = typeof(bool))]
[ClaimCheck("reminder_delete")]
public async Task DeleteReminderCurrentUser(Guid id)
{
var deleteReminderCurrentUserCommand = new DeleteReminderCurrentUserCommand { Id = id };
var result = await _mediator.Send(deleteReminderCurrentUserCommand);
return GenerateResponse(result);
}
///
/// Deletes the reminder.
///
/// The identifier.
///
[HttpDelete("{id}")]
[Produces("application/json", "application/xml", Type = typeof(bool))]
[ClaimCheck("reminder_delete")]
public async Task DeleteReminder(Guid id)
{
var deleteReminderCommaond = new DeleteReminderCommand { Id = id };
var result = await _mediator.Send(deleteReminderCommaond);
return GenerateResponse(result);
}
///
/// Gets the reminder.
///
///
[HttpGet("notofication/top10")]
[Produces("application/json", "application/xml")]
public async Task GetTop10ReminderNotification()
{
var getTop10ReminderNotificationQuery = new GetTop10ReminderNotificationQuery
{
};
var result = await _mediator.Send(getTop10ReminderNotificationQuery);
return Ok(result);
}
///
/// Gets the reminder.
///
/// The identifier.
///
[HttpGet("notifications")]
[Produces("application/json", "application/xml")]
public async Task GetNotifications([FromQuery] ReminderResource reminderResource)
{
var getAllReminderNotificationQuery = new GetAllReminderNotificationQuery
{
ReminderResource = reminderResource
};
var result = await _mediator.Send(getAllReminderNotificationQuery);
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);
}
//[HttpGet("notification/markasread")]
//[Produces("application/json", "application/xml")]
//public async Task GetNotificationMarkasRead()
//{
// var markAsReadAllNotificationsCommand = new MarkAsReadAllNotificationsCommand
// {
// };
// var result = await _mediator.Send(markAsReadAllNotificationsCommand);
// return Ok(result);
//}
}
}