-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
PingsController.cs
41 lines (37 loc) · 1.31 KB
/
PingsController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Net;
using HappyCode.NetCoreBoilerplate.Api.BackgroundServices;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace HappyCode.NetCoreBoilerplate.Api.Controllers
{
[AllowAnonymous]
[Route("api/pings")]
public class PingsController : ApiControllerBase
{
private readonly IPingService _pingService;
public PingsController(IPingService pingService)
{
_pingService = pingService;
}
[HttpGet("website")]
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
public IActionResult GetWebsitePingStatusCode()
{
var result = _pingService.WebsiteStatusCode;
return Ok($"{(int)result} ({result})");
}
[HttpGet("random")]
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
public IActionResult GetRandomStatusCode()
{
var random = new Random(Guid.NewGuid().GetHashCode());
int pretender;
do
{
pretender = random.Next(100, 600);
} while (!Enum.IsDefined(typeof(HttpStatusCode), pretender));
return Ok($"{pretender} ({(HttpStatusCode)pretender})");
}
}
}