diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-10-24 06:29:23 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-10-24 06:29:23 +0200 |
| commit | 585c5c8537eb21dfc9f16108548e63d9ced3d971 (patch) | |
| tree | 1582bc45dcab585ec7204f1570019b2ca8de36c5 /code/api/src/Endpoints/V1/Entries | |
| parent | 4b42c5235482fe0d3811b4e2936614c79e20d970 (diff) | |
| download | greatoffice-585c5c8537eb21dfc9f16108548e63d9ced3d971.tar.xz greatoffice-585c5c8537eb21dfc9f16108548e63d9ced3d971.zip | |
feat: Before move to FastEndpoints
Diffstat (limited to 'code/api/src/Endpoints/V1/Entries')
4 files changed, 48 insertions, 13 deletions
diff --git a/code/api/src/Endpoints/V1/Entries/CreateEntryRoute.cs b/code/api/src/Endpoints/V1/Entries/CreateEntryRoute.cs index 362e430..854ff59 100644 --- a/code/api/src/Endpoints/V1/Entries/CreateEntryRoute.cs +++ b/code/api/src/Endpoints/V1/Entries/CreateEntryRoute.cs @@ -16,27 +16,28 @@ public class CreateEntryRoute : RouteBaseSync.WithRequest<TimeEntry.TimeEntryDto [ApiVersion(ApiSpecV1.VERSION_STRING)] [BasicAuthentication(AppConstants.TOKEN_ALLOW_CREATE)] [ProducesResponseType(200)] - [ProducesResponseType(400, Type = typeof(ErrorResult))] - [ProducesResponseType(404, Type = typeof(ErrorResult))] + [ProducesResponseType(400, Type = typeof(KnownProblemModel))] + [ProducesResponseType(404, Type = typeof(KnownProblemModel))] [HttpPost("~/v{version:apiVersion}/entries/create")] public override ActionResult<TimeEntry.TimeEntryDto> Handle(TimeEntry.TimeEntryDto timeEntryTimeEntryDto) { if (timeEntryTimeEntryDto.Stop == default) { - return BadRequest(new ErrorResult("Invalid form", "A stop date is required")); + return BadRequest(new KnownProblemModel("Invalid form", "A stop date is required")); } if (timeEntryTimeEntryDto.Start == default) { - return BadRequest(new ErrorResult("Invalid form", "A start date is required")); + return BadRequest(new KnownProblemModel("Invalid form", "A start date is required")); } if (timeEntryTimeEntryDto.Category == default) { - return BadRequest(new ErrorResult("Invalid form", "A category is required")); + return BadRequest(new KnownProblemModel("Invalid form", "A category is required")); } var category = _context.TimeCategories .Where(c => c.UserId == LoggedInUser.Id) .SingleOrDefault(c => c.Id == timeEntryTimeEntryDto.Category.Id); + if (category == default) { - return NotFound(new ErrorResult("Not found", $"Could not find category {timeEntryTimeEntryDto.Category.Name}")); + return NotFound(new KnownProblemModel("Not found", $"Could not find category {timeEntryTimeEntryDto.Category.Name}")); } var entry = new TimeEntry(LoggedInUser.Id) { @@ -52,7 +53,7 @@ public class CreateEntryRoute : RouteBaseSync.WithRequest<TimeEntry.TimeEntryDto .Where(c => timeEntryTimeEntryDto.Labels.Select(p => p.Id).Contains(c.Id)) .ToList(); if (labels.Count != timeEntryTimeEntryDto.Labels.Count) { - return NotFound(new ErrorResult("Not found", "Could not find all of the specified labels")); + return NotFound(new KnownProblemModel("Not found", "Could not find all of the specified labels")); } entry.Labels = labels; diff --git a/code/api/src/Endpoints/V1/Entries/EntryQueryRoute.cs b/code/api/src/Endpoints/V1/Entries/EntryQueryRoute.cs index d431ac5..ec6003c 100644 --- a/code/api/src/Endpoints/V1/Entries/EntryQueryRoute.cs +++ b/code/api/src/Endpoints/V1/Entries/EntryQueryRoute.cs @@ -20,7 +20,7 @@ public class EntryQueryRoute : RouteBaseSync.WithRequest<EntryQueryPayload>.With [BasicAuthentication(AppConstants.TOKEN_ALLOW_READ)] [HttpPost("~/v{version:apiVersion}/entries/query")] [ProducesResponseType(204)] - [ProducesResponseType(400, Type = typeof(ErrorResult))] + [ProducesResponseType(400, Type = typeof(KnownProblemModel))] [ProducesResponseType(200, Type = typeof(EntryQueryResponse))] public override ActionResult<EntryQueryResponse> Handle(EntryQueryPayload entryQuery) { var result = new TimeQueryDto(); @@ -142,19 +142,19 @@ public class EntryQueryRoute : RouteBaseSync.WithRequest<EntryQueryPayload>.With break; case TimeEntryQueryDuration.DATE_RANGE: if (entryQuery.DateRange.From == default) { - return BadRequest(new ErrorResult("Invalid query", "From date cannot be empty")); + return BadRequest(new KnownProblemModel("Invalid query", "From date cannot be empty")); } var fromDate = DateTime.SpecifyKind(entryQuery.DateRange.From, DateTimeKind.Utc); if (entryQuery.DateRange.To == default) { - return BadRequest(new ErrorResult("Invalid query", "To date cannot be empty")); + return BadRequest(new KnownProblemModel("Invalid query", "To date cannot be empty")); } var toDate = DateTime.SpecifyKind(entryQuery.DateRange.To, DateTimeKind.Utc); if (DateTime.Compare(fromDate, toDate) > 0) { - return BadRequest(new ErrorResult("Invalid query", "To date cannot be less than From date")); + return BadRequest(new KnownProblemModel("Invalid query", "To date cannot be less than From date")); } var baseDateRangeEntries = baseQuery diff --git a/code/api/src/Endpoints/V1/Entries/TimeQueryDto.cs b/code/api/src/Endpoints/V1/Entries/TimeQueryDto.cs new file mode 100644 index 0000000..6c199d8 --- /dev/null +++ b/code/api/src/Endpoints/V1/Entries/TimeQueryDto.cs @@ -0,0 +1,34 @@ + +namespace IOL.GreatOffice.Api.Endpoints.V1.Entries; + +public class TimeQueryDto +{ + public TimeQueryDto() { + Results = new List<TimeEntry.TimeEntryDto>(); + } + + /// <summary> + /// List of entries. + /// </summary> + public List<TimeEntry.TimeEntryDto> Results { get; set; } + + /// <summary> + /// Curren page. + /// </summary> + public int Page { get; set; } + + /// <summary> + /// Maximum count of entries in a page. + /// </summary> + public int PageSize { get; set; } + + /// <summary> + /// Total count of entries. + /// </summary> + public int TotalSize { get; set; } + + /// <summary> + /// Total count of pages. + /// </summary> + public int TotalPageCount { get; set; } +} diff --git a/code/api/src/Endpoints/V1/Entries/UpdateEntryRoute.cs b/code/api/src/Endpoints/V1/Entries/UpdateEntryRoute.cs index ac233e0..09e3b9c 100644 --- a/code/api/src/Endpoints/V1/Entries/UpdateEntryRoute.cs +++ b/code/api/src/Endpoints/V1/Entries/UpdateEntryRoute.cs @@ -16,7 +16,7 @@ public class UpdateEntryRoute : RouteBaseSync.WithRequest<TimeEntry.TimeEntryDto [ApiVersion(ApiSpecV1.VERSION_STRING)] [BasicAuthentication(AppConstants.TOKEN_ALLOW_UPDATE)] [HttpPost("~/v{version:apiVersion}/entries/update")] - [ProducesResponseType(404, Type = typeof(ErrorResult))] + [ProducesResponseType(404, Type = typeof(KnownProblemModel))] [ProducesResponseType(200, Type = typeof(TimeEntry.TimeEntryDto))] public override ActionResult<TimeEntry.TimeEntryDto> Handle(TimeEntry.TimeEntryDto timeEntryTimeEntryDto) { var entry = _context.TimeEntries @@ -32,7 +32,7 @@ public class UpdateEntryRoute : RouteBaseSync.WithRequest<TimeEntry.TimeEntryDto .Where(c => c.UserId == LoggedInUser.Id) .SingleOrDefault(c => c.Id == timeEntryTimeEntryDto.Category.Id); if (category == default) { - return NotFound(new ErrorResult("Not found", $"Could not find category {timeEntryTimeEntryDto.Category.Name}")); + return NotFound(new KnownProblemModel("Not found", $"Could not find category {timeEntryTimeEntryDto.Category.Name}")); } entry.Start = timeEntryTimeEntryDto.Start.ToUniversalTime(); |
