Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ivanchuk/Fix logging #129

Merged
merged 10 commits into from
May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions OutOfSchool/OutOfSchool.WebApi/Controllers/AddressController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using OutOfSchool.WebApi.Extensions;
using OutOfSchool.WebApi.Models;
using OutOfSchool.WebApi.Services;

Expand Down Expand Up @@ -52,12 +52,7 @@ public async Task<IActionResult> GetAddresses()
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<IActionResult> GetAddressById(long id)
{
if (id < 1)
{
throw new ArgumentOutOfRangeException(
nameof(id),
localizer["The id cannot be less than 1."]);
}
this.ValidateId(id, localizer);

return Ok(await addressService.GetById(id).ConfigureAwait(false));
}
Expand Down Expand Up @@ -132,12 +127,7 @@ public async Task<IActionResult> Update(AddressDto addressDto)
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<IActionResult> Delete(long id)
{
if (id < 1)
{
throw new ArgumentOutOfRangeException(
nameof(id),
localizer["The id cannot be less than 1."]);
}
this.ValidateId(id, localizer);

await addressService.Delete(id).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using OutOfSchool.WebApi.Extensions;
using OutOfSchool.WebApi.Models;
using OutOfSchool.WebApi.Services;

Expand Down Expand Up @@ -63,7 +64,7 @@ public async Task<IActionResult> Get()
[HttpGet("{id}")]
public async Task<IActionResult> GetById(long id)
{
ValidateId(id);
this.ValidateId(id, localizer);

return Ok(await service.GetById(id).ConfigureAwait(false));
}
Expand Down Expand Up @@ -104,7 +105,7 @@ public async Task<IActionResult> GetByUserId(string id)
[HttpGet("{id}")]
public async Task<IActionResult> GetByWorkshopId(long id)
{
ValidateId(id);
this.ValidateId(id, localizer);

try
{
Expand Down Expand Up @@ -182,21 +183,11 @@ public async Task<IActionResult> Update(ApplicationDto applicationDto)
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(long id)
{
ValidateId(id);
this.ValidateId(id, localizer);

await service.Delete(id).ConfigureAwait(false);

return NoContent();
}

private void ValidateId(long id)
{
if (id < 1)
{
throw new ArgumentOutOfRangeException(
nameof(id),
localizer["The id cannot be less than 1."]);
}
}
}
}
15 changes: 3 additions & 12 deletions OutOfSchool/OutOfSchool.WebApi/Controllers/CategoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using OutOfSchool.WebApi.Extensions;
using OutOfSchool.WebApi.Models;
using OutOfSchool.WebApi.Services;

Expand Down Expand Up @@ -65,7 +66,7 @@ public async Task<IActionResult> Get()
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetById(long id)
{
IdValidation(id);
this.ValidateId(id, localizer);

return Ok(await service.GetById(id).ConfigureAwait(false));
}
Expand Down Expand Up @@ -137,21 +138,11 @@ public async Task<ActionResult> Update(CategoryDTO categoryDTO)
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult> Delete(long id)
{
IdValidation(id);
this.ValidateId(id, localizer);

await service.Delete(id).ConfigureAwait(false);

return NoContent();
}

private void IdValidation(long id)
{
if (id < 1)
{
throw new ArgumentOutOfRangeException(
nameof(id),
localizer["The id cannot be less than 1."]);
}
}
}
}
19 changes: 4 additions & 15 deletions OutOfSchool/OutOfSchool.WebApi/Controllers/ChildController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using OutOfSchool.WebApi.Extensions;
using OutOfSchool.WebApi.Models;
using OutOfSchool.WebApi.Services;

Expand Down Expand Up @@ -63,12 +62,7 @@ public async Task<IActionResult> Get()
[HttpGet("{id}")]
public async Task<IActionResult> GetById(long id)
{
if (id < 1)
{
throw new ArgumentOutOfRangeException(
nameof(id),
localizer["The id cannot be less than 1."]);
}
this.ValidateId(id, localizer);

return Ok(await service.GetById(id).ConfigureAwait(false));
}
Expand Down Expand Up @@ -129,12 +123,7 @@ public async Task<IActionResult> Update(ChildDTO dto)
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(long id)
{
if (id < 1)
{
throw new ArgumentOutOfRangeException(
nameof(id),
localizer["The id cannot be less than 1."]);
}
this.ValidateId(id, localizer);

await service.Delete(id).ConfigureAwait(false);

Expand Down
14 changes: 2 additions & 12 deletions OutOfSchool/OutOfSchool.WebApi/Controllers/ParentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ public async Task<IActionResult> Get()
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetById(long id)
{
if (id < 1)
{
throw new ArgumentOutOfRangeException(
nameof(id),
localizer["The id cannot be less than 1."]);
}
this.ValidateId(id, localizer);

return Ok(await service.GetById(id).ConfigureAwait(false));
}
Expand Down Expand Up @@ -144,12 +139,7 @@ public async Task<ActionResult> Update(ParentDTO parentDTO)
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult> Delete(long id)
{
if (id < 1)
{
throw new ArgumentOutOfRangeException(
nameof(id),
localizer["The id cannot be less than 1."]);
}
this.ValidateId(id, localizer);

await service.Delete(id).ConfigureAwait(false);

Expand Down
15 changes: 3 additions & 12 deletions OutOfSchool/OutOfSchool.WebApi/Controllers/ProviderController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using OutOfSchool.WebApi.Extensions;
using OutOfSchool.WebApi.Models;
using OutOfSchool.WebApi.Services;

Expand Down Expand Up @@ -59,12 +60,7 @@ public async Task<IActionResult> Get()
[HttpGet("{id}")]
public async Task<IActionResult> GetById(long id)
{
if (id < 1)
{
throw new ArgumentOutOfRangeException(
nameof(id),
localizer["The id cannot be less than 1."]);
}
this.ValidateId(id, localizer);

return Ok(await providerService.GetById(id).ConfigureAwait(false));
}
Expand Down Expand Up @@ -166,12 +162,7 @@ public async Task<IActionResult> Update(ProviderDto dto)
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(long id)
{
if (id < 1)
{
throw new ArgumentOutOfRangeException(
nameof(id),
localizer["The id cannot be less than 1."]);
}
this.ValidateId(id, localizer);

await providerService.Delete(id).ConfigureAwait(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using OutOfSchool.WebApi.Extensions;
using OutOfSchool.WebApi.Models;
using OutOfSchool.WebApi.Services;

Expand Down Expand Up @@ -65,7 +66,7 @@ public async Task<IActionResult> Get()
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetById(long id)
{
IdValidation(id);
this.ValidateId(id, localizer);

return Ok(await service.GetById(id).ConfigureAwait(false));
}
Expand Down Expand Up @@ -165,21 +166,11 @@ public async Task<ActionResult> Update(SubcategoryDTO categoryDTO)
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult> Delete(long id)
{
IdValidation(id);
this.ValidateId(id, localizer);

await service.Delete(id).ConfigureAwait(false);

return NoContent();
}

private void IdValidation(long id)
{
if (id < 1)
{
throw new ArgumentOutOfRangeException(
nameof(id),
localizer["The id cannot be less than 1."]);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using OutOfSchool.WebApi.Extensions;
using OutOfSchool.WebApi.Models;
using OutOfSchool.WebApi.Services;

Expand Down Expand Up @@ -65,7 +66,7 @@ public async Task<IActionResult> Get()
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetById(long id)
{
IdValidation(id);
this.ValidateId(id, localizer);

return Ok(await service.GetById(id).ConfigureAwait(false));
}
Expand Down Expand Up @@ -165,21 +166,11 @@ public async Task<ActionResult> Update(SubsubcategoryDTO categoryDTO)
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<ActionResult> Delete(long id)
{
IdValidation(id);
this.ValidateId(id, localizer);

await service.Delete(id).ConfigureAwait(false);

return NoContent();
}

private void IdValidation(long id)
{
if (id < 1)
{
throw new ArgumentOutOfRangeException(
nameof(id),
localizer["The id cannot be less than 1."]);
}
}
}
}
15 changes: 3 additions & 12 deletions OutOfSchool/OutOfSchool.WebApi/Controllers/TeacherController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using OutOfSchool.WebApi.Extensions;
using OutOfSchool.WebApi.Models;
using OutOfSchool.WebApi.Services;

Expand Down Expand Up @@ -62,12 +63,7 @@ public async Task<IActionResult> Get()
[HttpGet("{id}")]
public async Task<IActionResult> GetById(long id)
{
if (id < 1)
{
throw new ArgumentOutOfRangeException(
nameof(id),
localizer["The id cannot be less than 1."]);
}
this.ValidateId(id, localizer);

return Ok(await service.GetById(id).ConfigureAwait(false));
}
Expand Down Expand Up @@ -131,12 +127,7 @@ public async Task<IActionResult> Update(TeacherDTO dto)
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(long id)
{
if (id < 1)
{
throw new ArgumentOutOfRangeException(
nameof(id),
localizer["The id cannot be less than 1."]);
}
this.ValidateId(id, localizer);

await service.Delete(id).ConfigureAwait(false);

Expand Down
15 changes: 3 additions & 12 deletions OutOfSchool/OutOfSchool.WebApi/Controllers/WorkshopController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Localization;
using OutOfSchool.WebApi.Extensions;
using OutOfSchool.WebApi.Models;
using OutOfSchool.WebApi.Services;

Expand Down Expand Up @@ -62,12 +63,7 @@ public async Task<IActionResult> Get()
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetById(long id)
{
if (id < 1)
{
throw new ArgumentOutOfRangeException(
nameof(id),
localizer["The id cannot be less than 1."]);
}
this.ValidateId(id, localizer);

return Ok(await service.GetById(id).ConfigureAwait(false));
}
Expand Down Expand Up @@ -128,12 +124,7 @@ public async Task<IActionResult> Update(WorkshopDTO dto)
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(long id)
{
if (id < 1)
{
throw new ArgumentOutOfRangeException(
nameof(id),
localizer["The id cannot be less than 1."]);
}
this.ValidateId(id, localizer);

await service.Delete(id).ConfigureAwait(false);

Expand Down
Loading