Format .NET projects with csharpier
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using System.Net.Mime;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Solar.Api.Models;
|
||||
using Solar.Api.Services;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using System.Net.Mime;
|
||||
|
||||
namespace Solar.Api.Controllers;
|
||||
|
||||
@@ -14,9 +14,7 @@ public class SolarLogController : ControllerBase
|
||||
private readonly SolarService solarService;
|
||||
private readonly ILogger<SolarLogController> logger;
|
||||
|
||||
public SolarLogController(
|
||||
SolarService solarService,
|
||||
ILogger<SolarLogController> logger)
|
||||
public SolarLogController(SolarService solarService, ILogger<SolarLogController> logger)
|
||||
{
|
||||
this.solarService = solarService;
|
||||
this.logger = logger;
|
||||
@@ -25,10 +23,8 @@ public class SolarLogController : ControllerBase
|
||||
[HttpGet()]
|
||||
[Route("/day")]
|
||||
public async Task<ActionResult<DayResponse>> GetDayDetails(
|
||||
[SwaggerParameter(Required = true)]
|
||||
[SwaggerSchema(Format = "date")]
|
||||
[FromQuery]
|
||||
string date)
|
||||
[SwaggerParameter(Required = true)] [SwaggerSchema(Format = "date")] [FromQuery] string date
|
||||
)
|
||||
{
|
||||
var parsedDate = TryParseDate(date);
|
||||
if (!parsedDate.HasValue || parsedDate.Value.Year < 2000 || parsedDate.Value.Year > 3000)
|
||||
@@ -47,28 +43,38 @@ public class SolarLogController : ControllerBase
|
||||
[SwaggerParameter(Required = true)]
|
||||
[SwaggerSchema(Format = "date")]
|
||||
[FromQuery]
|
||||
string start,
|
||||
[SwaggerParameter(Required = true)]
|
||||
[SwaggerSchema(Format = "date")]
|
||||
[FromQuery]
|
||||
string stop)
|
||||
string start,
|
||||
[SwaggerParameter(Required = true)] [SwaggerSchema(Format = "date")] [FromQuery] string stop
|
||||
)
|
||||
{
|
||||
var parsedStartDate = TryParseDate(start);
|
||||
if (!parsedStartDate.HasValue || parsedStartDate.Value.Year < 2000 || parsedStartDate.Value.Year > 3000)
|
||||
if (
|
||||
!parsedStartDate.HasValue
|
||||
|| parsedStartDate.Value.Year < 2000
|
||||
|| parsedStartDate.Value.Year > 3000
|
||||
)
|
||||
{
|
||||
logger.LogInformation("Invalid start date {Date} requested", start);
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
var parsedStopDate = TryParseDate(stop);
|
||||
if (!parsedStopDate.HasValue || parsedStopDate.Value.Year < 2000 || parsedStopDate.Value.Year > 3000)
|
||||
if (
|
||||
!parsedStopDate.HasValue
|
||||
|| parsedStopDate.Value.Year < 2000
|
||||
|| parsedStopDate.Value.Year > 3000
|
||||
)
|
||||
{
|
||||
logger.LogInformation("Invalid stop date {Date} requested", stop);
|
||||
return BadRequest();
|
||||
}
|
||||
else if (parsedStopDate < parsedStartDate)
|
||||
{
|
||||
logger.LogInformation("Stop date {StopDate} must come before start date {StartDate} requested", stop, start);
|
||||
logger.LogInformation(
|
||||
"Stop date {StopDate} must come before start date {StartDate} requested",
|
||||
stop,
|
||||
start
|
||||
);
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
@@ -81,28 +87,41 @@ public class SolarLogController : ControllerBase
|
||||
[SwaggerParameter(Required = true)]
|
||||
[SwaggerSchema(Format = "yyyy-MM")]
|
||||
[FromQuery]
|
||||
string start,
|
||||
string start,
|
||||
[SwaggerParameter(Required = true)]
|
||||
[SwaggerSchema(Format = "yyyy-MM")]
|
||||
[FromQuery]
|
||||
string stop)
|
||||
string stop
|
||||
)
|
||||
{
|
||||
var parsedStartDate = TryParseDate($"{start}-01");
|
||||
if (!parsedStartDate.HasValue || parsedStartDate.Value.Year < 2000 || parsedStartDate.Value.Year > 3000)
|
||||
if (
|
||||
!parsedStartDate.HasValue
|
||||
|| parsedStartDate.Value.Year < 2000
|
||||
|| parsedStartDate.Value.Year > 3000
|
||||
)
|
||||
{
|
||||
logger.LogInformation("Invalid start year month {YearMonth} requested", start);
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
var parsedStopDate = TryParseDate($"{stop}-01");
|
||||
if (!parsedStopDate.HasValue || parsedStopDate.Value.Year < 2000 || parsedStopDate.Value.Year > 3000)
|
||||
if (
|
||||
!parsedStopDate.HasValue
|
||||
|| parsedStopDate.Value.Year < 2000
|
||||
|| parsedStopDate.Value.Year > 3000
|
||||
)
|
||||
{
|
||||
logger.LogInformation("Invalid stop year month {YearMonth} requested", stop);
|
||||
return BadRequest();
|
||||
}
|
||||
else if (parsedStopDate < parsedStartDate)
|
||||
{
|
||||
logger.LogInformation("Stop year month {StopYearMonth} must come before start year month {StartYearMonth} requested", stop, start);
|
||||
logger.LogInformation(
|
||||
"Stop year month {StopYearMonth} must come before start year month {StartYearMonth} requested",
|
||||
stop,
|
||||
start
|
||||
);
|
||||
return BadRequest();
|
||||
}
|
||||
|
||||
@@ -110,7 +129,8 @@ public class SolarLogController : ControllerBase
|
||||
parsedStartDate.Value.Year,
|
||||
parsedStartDate.Value.Month,
|
||||
parsedStopDate.Value.Year,
|
||||
parsedStopDate.Value.Month);
|
||||
parsedStopDate.Value.Month
|
||||
);
|
||||
}
|
||||
|
||||
private static DateOnly? TryParseDate(string value)
|
||||
|
||||
Reference in New Issue
Block a user