Files
raven/server/AyaNova/Controllers/NotifyController.cs
2020-06-16 22:17:25 +00:00

76 lines
2.5 KiB
C#

using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;
using AyaNova.Models;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
namespace AyaNova.Api.Controllers
{
[ApiController]
[ApiVersion("8.0")]
[Route("api/v{version:apiVersion}/notify")]
[Produces("application/json")]
[Authorize]
public class NotifyController : ControllerBase
{
private readonly AyContext ct;
private readonly ILogger<NotifyController> log;
private readonly ApiServerState serverState;
/// <summary>
/// ctor
/// </summary>
/// <param name="dbcontext"></param>
/// <param name="logger"></param>
/// <param name="apiServerState"></param>
public NotifyController(AyContext dbcontext, ILogger<NotifyController> logger, ApiServerState apiServerState)
{
ct = dbcontext;
log = logger;
serverState = apiServerState;
}
/// <summary>
/// Pre-login route to confirm server is available
/// </summary>
/// <returns></returns>
[AllowAnonymous]
[HttpGet("hello")]
public async Task<IActionResult> GetPreLoginPing()
{
bool showSampleLogins = false;
if (AyaNova.Core.License.ActiveKey.Status == AyaNova.Core.License.AyaNovaLicenseKey.LicenseStatus.ActiveTrial)
showSampleLogins = await AyaNova.Util.DbUtil.DBHasTrialUsersAsync(ct, log);
return Ok(ApiOkResponse.Response(showSampleLogins));
}
/// <summary>
/// Get count of new notifications waiting
/// </summary>
/// <returns></returns>
[HttpGet("new-count")]
public ActionResult GetNewCount()
{
//STUB: https://rockfish.ayanova.com/default.htm#!/rfcaseEdit/3783
if (serverState.IsClosed)
return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
return Ok(ApiOkResponse.Response(69));
}
//TODO: See new count case for gist of it
//todo: see the core-notification.txt spec doc for details and
//todo: see seemingly countless Notification related cases for details :)
//------------
}//eoc
}//eons