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

Provider service works with guids #424

Merged
merged 1 commit into from
Nov 4, 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
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using OutOfSchool.Services.Models;
using System;
using OutOfSchool.Services.Models;

namespace OutOfSchool.Services.Repository
{
public interface IProviderRepository : IEntityRepository<Provider>, IExistable<Provider>
public interface IProviderRepository : ISensitiveEntityRepository<Provider>, IExistable<Provider>
{
bool ExistsUserId(string id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace OutOfSchool.Services.Repository
{
public class ProviderRepository : EntityRepository<Provider>, IProviderRepository
public class ProviderRepository : SensitiveEntityRepository<Provider>, IProviderRepository
{
private readonly OutOfSchoolDbContext db;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,10 @@ public async Task<IActionResult> Get()
/// <returns>Provider.</returns>
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[HttpGet("{providerId:long}")]
[HttpGet("{providerId:Guid}")]
[AllowAnonymous]
public async Task<IActionResult> GetById(long providerId)
public async Task<IActionResult> GetById(Guid providerId)
{
try
{
this.ValidateId(providerId, localizer);
}
catch (ArgumentOutOfRangeException ex)
{
logger.LogError(ex, $"Validation failed for provider ID: {providerId}");

return BadRequest("Provider data is missing or invalid.");
}

var provider = await providerService.GetById(providerId).ConfigureAwait(false);

if (provider == null)
Expand Down Expand Up @@ -210,18 +199,16 @@ public async Task<IActionResult> Update(ProviderDto providerModel)
/// <summary>
/// Delete a specific Provider from the database.
/// </summary>
/// <param name="id">Provider's key.</param>
/// <param name="uid">Provider's key.</param>
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
[Authorize(Roles = "provider,admin")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[HttpDelete("{id}")]
public async Task<IActionResult> Delete(long id)
[HttpDelete("{uid:guid}")]
public async Task<IActionResult> Delete(Guid uid)
{
this.ValidateId(id, localizer);

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

return NoContent();
}
Expand Down
3 changes: 2 additions & 1 deletion OutOfSchool/OutOfSchool.WebApi/Services/IAddressService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using OutOfSchool.WebApi.Models;
Expand Down
4 changes: 2 additions & 2 deletions OutOfSchool/OutOfSchool.WebApi/Services/IProviderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface IProviderService
/// </summary>
/// <param name="id">Key in the table.</param>
/// <returns>Provider.</returns>
Task<ProviderDto> GetById(long id);
Task<ProviderDto> GetById(Guid id);

/// <summary>
/// Get entity by User id.
Expand All @@ -52,6 +52,6 @@ public interface IProviderService
/// </summary>
/// <param name="id">Provider's key.</param>
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
Task Delete(long id);
Task Delete(Guid id);
}
}
4 changes: 2 additions & 2 deletions OutOfSchool/OutOfSchool.WebApi/Services/ProviderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public async Task<IEnumerable<ProviderDto>> GetAll()
}

/// <inheritdoc/>
public async Task<ProviderDto> GetById(long id)
public async Task<ProviderDto> GetById(Guid id)
{
logger.LogInformation($"Getting Provider by Id started. Looking Id = {id}.");

Expand Down Expand Up @@ -193,7 +193,7 @@ public async Task<ProviderDto> Update(ProviderDto providerDto, string userId, st
}

/// <inheritdoc/>
public async Task Delete(long id)
public async Task Delete(Guid id)
{
// BUG: Possible bug with deleting provider not owned by the user itself.
// TODO: add unit tests to check ownership functionality
Expand Down