Implement ListTokens controller action.
This commit is contained in:
parent
cd72710d24
commit
b03979b8b2
9 changed files with 167 additions and 28 deletions
|
@ -1,6 +1,8 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Retroactiune.Core.Entities;
|
||||||
|
using Retroactiune.Core.Services;
|
||||||
|
|
||||||
namespace Retroactiune.Core.Interfaces
|
namespace Retroactiune.Core.Interfaces
|
||||||
{
|
{
|
||||||
|
@ -22,5 +24,12 @@ namespace Retroactiune.Core.Interfaces
|
||||||
/// <param name="tokenIds">A list of tokens to delete.</param>
|
/// <param name="tokenIds">A list of tokens to delete.</param>
|
||||||
/// <returns>The result of the delete operation.</returns>
|
/// <returns>The result of the delete operation.</returns>
|
||||||
public Task DeleteTokens(IEnumerable<string> tokenIds);
|
public Task DeleteTokens(IEnumerable<string> tokenIds);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// List and filters tokens.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filters">Filters object for filtering results.</param>
|
||||||
|
/// <returns>A list of tokens matching the filters.</returns>
|
||||||
|
public Task<IEnumerable<Token>> ListTokens(TokenListFilters filters);
|
||||||
}
|
}
|
||||||
}
|
}
|
41
Retroactiune.Core/Services/TokenListFilters.cs
Normal file
41
Retroactiune.Core/Services/TokenListFilters.cs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace Retroactiune.Core.Services
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// TokenListFilters is a data class representing the filters used to list tokens.
|
||||||
|
/// </summary>
|
||||||
|
public class TokenListFilters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Id filters tokens by their ids.
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<string> Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FeedbackReceiverId filters tokens by their assigned FeedbackReceiverId.
|
||||||
|
/// </summary>
|
||||||
|
public string FeedbackReceiverId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// CreatedAfter filters token that have been created after the given date.
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? CreatedAfter { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// CreatedBefore filters token that have been created before the given date.
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? CreatedBefore { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UsedAfter filters token that have been used after the given date.
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? UsedAfter { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UsedBefore filters token that have been used before the given date.
|
||||||
|
/// </summary>
|
||||||
|
public DateTime? UsedBefore { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -52,5 +52,12 @@ namespace Retroactiune.Core.Services
|
||||||
throw new GenericServiceException($"Operation failed: {e.Message} {e.StackTrace}");
|
throw new GenericServiceException($"Operation failed: {e.Message} {e.StackTrace}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Token>> ListTokens(TokenListFilters filters)
|
||||||
|
{
|
||||||
|
// TODO Write unit tests.
|
||||||
|
// TODO: Implement
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@ using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AutoFixture.Xunit2;
|
using AutoFixture.Xunit2;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Retroactiune.Controllers;
|
using Retroactiune.Controllers;
|
||||||
using Retroactiune.Core.Entities;
|
using Retroactiune.Core.Entities;
|
||||||
|
@ -20,9 +21,10 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
// Arrange
|
// Arrange
|
||||||
var mapper = TestUtils.GetMapper();
|
var mapper = TestUtils.GetMapper();
|
||||||
var mockService = new Mock<IFeedbackReceiverService>();
|
var mockService = new Mock<IFeedbackReceiverService>();
|
||||||
|
var logger = new Mock<ILogger<FeedbackReceiversController>>();
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
var controller = new FeedbackReceiversController(mockService.Object, mapper, null);
|
var controller = new FeedbackReceiversController(mockService.Object, mapper, null, logger.Object);
|
||||||
var result = await controller.Post(new List<FeedbackReceiverInDto>());
|
var result = await controller.Post(new List<FeedbackReceiverInDto>());
|
||||||
|
|
||||||
// Assert, null because we don't have the ApiBehaviourOptions set, which would generate the IActionResult for the invalid input.
|
// Assert, null because we don't have the ApiBehaviourOptions set, which would generate the IActionResult for the invalid input.
|
||||||
|
@ -36,9 +38,10 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
// Arrange
|
// Arrange
|
||||||
var mapper = TestUtils.GetMapper();
|
var mapper = TestUtils.GetMapper();
|
||||||
var mockService = new Mock<IFeedbackReceiverService>();
|
var mockService = new Mock<IFeedbackReceiverService>();
|
||||||
|
var logger = new Mock<ILogger<FeedbackReceiversController>>();
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
var controller = new FeedbackReceiversController(mockService.Object, mapper, null);
|
var controller = new FeedbackReceiversController(mockService.Object, mapper, null, logger.Object);
|
||||||
var result = await controller.Post(items);
|
var result = await controller.Post(items);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
@ -52,9 +55,10 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
// Arrange
|
// Arrange
|
||||||
var mapper = TestUtils.GetMapper();
|
var mapper = TestUtils.GetMapper();
|
||||||
var mockService = new Mock<IFeedbackReceiverService>();
|
var mockService = new Mock<IFeedbackReceiverService>();
|
||||||
|
var logger = new Mock<ILogger<FeedbackReceiversController>>();
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
var controller = new FeedbackReceiversController(mockService.Object, mapper, null);
|
var controller = new FeedbackReceiversController(mockService.Object, mapper, null, logger.Object);
|
||||||
var result = await controller.Delete("bad_guid_but_unit_test_works_cause_validation_doesnt");
|
var result = await controller.Delete("bad_guid_but_unit_test_works_cause_validation_doesnt");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
@ -62,16 +66,17 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
mockService.Verify(s => s.DeleteManyAsync(new[] {"bad_guid_but_unit_test_works_cause_validation_doesnt"}),
|
mockService.Verify(s => s.DeleteManyAsync(new[] {"bad_guid_but_unit_test_works_cause_validation_doesnt"}),
|
||||||
Times.Once);
|
Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task DeleteMany_Successful()
|
public async Task DeleteMany_Successful()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var mapper = TestUtils.GetMapper();
|
var mapper = TestUtils.GetMapper();
|
||||||
var mockService = new Mock<IFeedbackReceiverService>();
|
var mockService = new Mock<IFeedbackReceiverService>();
|
||||||
|
var logger = new Mock<ILogger<FeedbackReceiversController>>();
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
var controller = new FeedbackReceiversController(mockService.Object, mapper, null);
|
var controller = new FeedbackReceiversController(mockService.Object, mapper, null, logger.Object);
|
||||||
var items = new[] {"bad_guid_but_unit_test_works_cause_validation_doesnt", "2", "3"};
|
var items = new[] {"bad_guid_but_unit_test_works_cause_validation_doesnt", "2", "3"};
|
||||||
var result = await controller.DeleteMany(items);
|
var result = await controller.DeleteMany(items);
|
||||||
|
|
||||||
|
@ -87,11 +92,12 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
// Arrange
|
// Arrange
|
||||||
var mapper = TestUtils.GetMapper();
|
var mapper = TestUtils.GetMapper();
|
||||||
var mockService = new Mock<IFeedbackReceiverService>();
|
var mockService = new Mock<IFeedbackReceiverService>();
|
||||||
|
var logger = new Mock<ILogger<FeedbackReceiversController>>();
|
||||||
mockService.Setup(i => i.FindAsync(It.IsAny<IEnumerable<string>>(), null, null))
|
mockService.Setup(i => i.FindAsync(It.IsAny<IEnumerable<string>>(), null, null))
|
||||||
.ReturnsAsync(new[] {new FeedbackReceiver()});
|
.ReturnsAsync(new[] {new FeedbackReceiver()});
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
var controller = new FeedbackReceiversController(mockService.Object, mapper, null);
|
var controller = new FeedbackReceiversController(mockService.Object, mapper, null, logger.Object);
|
||||||
var result = await controller.Get("bad_guid_but_unit_test_works_cause_validation_doesnt");
|
var result = await controller.Get("bad_guid_but_unit_test_works_cause_validation_doesnt");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
@ -107,9 +113,10 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
// Arrange
|
// Arrange
|
||||||
var mapper = TestUtils.GetMapper();
|
var mapper = TestUtils.GetMapper();
|
||||||
var mockService = new Mock<IFeedbackReceiverService>();
|
var mockService = new Mock<IFeedbackReceiverService>();
|
||||||
|
var logger = new Mock<ILogger<FeedbackReceiversController>>();
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
var controller = new FeedbackReceiversController(mockService.Object, mapper, null);
|
var controller = new FeedbackReceiversController(mockService.Object, mapper, null, logger.Object);
|
||||||
var result = await controller.Get("bad_guid_but_unit_test_works_cause_validation_doesnt");
|
var result = await controller.Get("bad_guid_but_unit_test_works_cause_validation_doesnt");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
@ -125,10 +132,11 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
// Arrange
|
// Arrange
|
||||||
var mapper = TestUtils.GetMapper();
|
var mapper = TestUtils.GetMapper();
|
||||||
var mockService = new Mock<IFeedbackReceiverService>();
|
var mockService = new Mock<IFeedbackReceiverService>();
|
||||||
|
var logger = new Mock<ILogger<FeedbackReceiversController>>();
|
||||||
var filterArr = filter as string[] ?? filter.ToArray();
|
var filterArr = filter as string[] ?? filter.ToArray();
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
var controller = new FeedbackReceiversController(mockService.Object, mapper, null);
|
var controller = new FeedbackReceiversController(mockService.Object, mapper, null, logger.Object);
|
||||||
var result = await controller.List(filterArr, offset, limit);
|
var result = await controller.List(filterArr, offset, limit);
|
||||||
|
|
||||||
Assert.IsType<OkObjectResult>(result);
|
Assert.IsType<OkObjectResult>(result);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AutoFixture.Xunit2;
|
using AutoFixture.Xunit2;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Retroactiune.Controllers;
|
using Retroactiune.Controllers;
|
||||||
using Retroactiune.Core.Entities;
|
using Retroactiune.Core.Entities;
|
||||||
|
@ -19,10 +20,12 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var feedbackService = new Mock<IFeedbackReceiverService>();
|
var feedbackService = new Mock<IFeedbackReceiverService>();
|
||||||
|
var mapper = TestUtils.GetMapper();
|
||||||
var tokens = new Mock<ITokensService>();
|
var tokens = new Mock<ITokensService>();
|
||||||
|
var logger = new Mock<ILogger<TokensController>>();
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
var controller = new TokensController(feedbackService.Object, tokens.Object);
|
var controller = new TokensController(feedbackService.Object, tokens.Object, logger.Object, mapper);
|
||||||
var result = await controller.GenerateTokens(new GenerateTokensDto());
|
var result = await controller.GenerateTokens(new GenerateTokensDto());
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
@ -33,8 +36,10 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
public async Task Test_GenerateTokens_Success(FeedbackReceiver randFedFeedbackReceiver)
|
public async Task Test_GenerateTokens_Success(FeedbackReceiver randFedFeedbackReceiver)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
var mapper = TestUtils.GetMapper();
|
||||||
var feedbackService = new Mock<IFeedbackReceiverService>();
|
var feedbackService = new Mock<IFeedbackReceiverService>();
|
||||||
var tokens = new Mock<ITokensService>();
|
var tokens = new Mock<ITokensService>();
|
||||||
|
var logger = new Mock<ILogger<TokensController>>();
|
||||||
|
|
||||||
feedbackService.Setup(i => i.FindAsync(It.IsAny<IEnumerable<string>>(),
|
feedbackService.Setup(i => i.FindAsync(It.IsAny<IEnumerable<string>>(),
|
||||||
It.IsAny<int?>(),
|
It.IsAny<int?>(),
|
||||||
|
@ -42,7 +47,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
.ReturnsAsync(new[] {randFedFeedbackReceiver});
|
.ReturnsAsync(new[] {randFedFeedbackReceiver});
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
var controller = new TokensController(feedbackService.Object, tokens.Object);
|
var controller = new TokensController(feedbackService.Object, tokens.Object, logger.Object, mapper);
|
||||||
var result = await controller.GenerateTokens(new GenerateTokensDto
|
var result = await controller.GenerateTokens(new GenerateTokensDto
|
||||||
{
|
{
|
||||||
NumberOfTokens = 2,
|
NumberOfTokens = 2,
|
||||||
|
@ -58,11 +63,13 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
public async Task Test_Delete_Ok()
|
public async Task Test_Delete_Ok()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
var mapper = TestUtils.GetMapper();
|
||||||
var feedbackService = new Mock<IFeedbackReceiverService>();
|
var feedbackService = new Mock<IFeedbackReceiverService>();
|
||||||
var tokens = new Mock<ITokensService>();
|
var tokens = new Mock<ITokensService>();
|
||||||
|
var logger = new Mock<ILogger<TokensController>>();
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
var controller = new TokensController(feedbackService.Object, tokens.Object);
|
var controller = new TokensController(feedbackService.Object, tokens.Object, logger.Object, mapper);
|
||||||
var result = await controller.DeleteToken("my_guid");
|
var result = await controller.DeleteToken("my_guid");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
@ -74,13 +81,15 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
public async Task Test_Delete_BadRequest()
|
public async Task Test_Delete_BadRequest()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
var mapper = TestUtils.GetMapper();
|
||||||
var feedbackService = new Mock<IFeedbackReceiverService>();
|
var feedbackService = new Mock<IFeedbackReceiverService>();
|
||||||
var tokens = new Mock<ITokensService>();
|
var tokens = new Mock<ITokensService>();
|
||||||
|
var logger = new Mock<ILogger<TokensController>>();
|
||||||
tokens.Setup(i => i.DeleteTokens(It.IsAny<IEnumerable<string>>()))
|
tokens.Setup(i => i.DeleteTokens(It.IsAny<IEnumerable<string>>()))
|
||||||
.Throws(new GenericServiceException("op fail"));
|
.Throws(new GenericServiceException("op fail"));
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
var controller = new TokensController(feedbackService.Object, tokens.Object);
|
var controller = new TokensController(feedbackService.Object, tokens.Object, logger.Object, mapper);
|
||||||
var result = await controller.DeleteToken("my_guid");
|
var result = await controller.DeleteToken("my_guid");
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
@ -92,11 +101,13 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
public async Task Test_DeleteMany_Ok()
|
public async Task Test_DeleteMany_Ok()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
var mapper = TestUtils.GetMapper();
|
||||||
var feedbackService = new Mock<IFeedbackReceiverService>();
|
var feedbackService = new Mock<IFeedbackReceiverService>();
|
||||||
var tokens = new Mock<ITokensService>();
|
var tokens = new Mock<ITokensService>();
|
||||||
|
var logger = new Mock<ILogger<TokensController>>();
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
var controller = new TokensController(feedbackService.Object, tokens.Object);
|
var controller = new TokensController(feedbackService.Object, tokens.Object, logger.Object, mapper);
|
||||||
var result = await controller.DeleteTokens(new[] {"my_guid", "b"});
|
var result = await controller.DeleteTokens(new[] {"my_guid", "b"});
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
@ -108,13 +119,15 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
public async Task Test_DeleteMany_BadRequest()
|
public async Task Test_DeleteMany_BadRequest()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
|
var mapper = TestUtils.GetMapper();
|
||||||
var feedbackService = new Mock<IFeedbackReceiverService>();
|
var feedbackService = new Mock<IFeedbackReceiverService>();
|
||||||
var tokens = new Mock<ITokensService>();
|
var tokens = new Mock<ITokensService>();
|
||||||
|
var logger = new Mock<ILogger<TokensController>>();
|
||||||
tokens.Setup(i => i.DeleteTokens(It.IsAny<IEnumerable<string>>()))
|
tokens.Setup(i => i.DeleteTokens(It.IsAny<IEnumerable<string>>()))
|
||||||
.Throws(new GenericServiceException("op fail"));
|
.Throws(new GenericServiceException("op fail"));
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
var controller = new TokensController(feedbackService.Object, tokens.Object);
|
var controller = new TokensController(feedbackService.Object, tokens.Object, logger.Object, mapper);
|
||||||
var result = await controller.DeleteTokens(new[] {"my_guid", "b"});
|
var result = await controller.DeleteTokens(new[] {"my_guid", "b"});
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
|
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Retroactiune.Core.Entities;
|
using Retroactiune.Core.Entities;
|
||||||
using Retroactiune.Core.Interfaces;
|
using Retroactiune.Core.Interfaces;
|
||||||
|
@ -21,13 +22,15 @@ namespace Retroactiune.Controllers
|
||||||
private readonly IOptions<ApiBehaviorOptions> _apiBehaviorOptions;
|
private readonly IOptions<ApiBehaviorOptions> _apiBehaviorOptions;
|
||||||
private readonly IFeedbackReceiverService _service;
|
private readonly IFeedbackReceiverService _service;
|
||||||
private readonly IMapper _mapper;
|
private readonly IMapper _mapper;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
public FeedbackReceiversController(IFeedbackReceiverService service, IMapper mapper,
|
public FeedbackReceiversController(IFeedbackReceiverService service, IMapper mapper,
|
||||||
IOptions<ApiBehaviorOptions> apiBehaviorOptions)
|
IOptions<ApiBehaviorOptions> apiBehaviorOptions, ILogger<FeedbackReceiversController> logger)
|
||||||
{
|
{
|
||||||
_service = service;
|
_service = service;
|
||||||
_mapper = mapper;
|
_mapper = mapper;
|
||||||
_apiBehaviorOptions = apiBehaviorOptions;
|
_apiBehaviorOptions = apiBehaviorOptions;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -80,7 +83,7 @@ namespace Retroactiune.Controllers
|
||||||
[StringLength(24, ErrorMessage = "invalid guid, must be 24 characters", MinimumLength = 24)]
|
[StringLength(24, ErrorMessage = "invalid guid, must be 24 characters", MinimumLength = 24)]
|
||||||
string guid)
|
string guid)
|
||||||
{
|
{
|
||||||
await _service.DeleteManyAsync(new [] {guid});
|
await _service.DeleteManyAsync(new[] {guid});
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +136,7 @@ namespace Retroactiune.Controllers
|
||||||
{
|
{
|
||||||
return Ok(await _service.FindAsync(filter, offset, limit));
|
return Ok(await _service.FindAsync(filter, offset, limit));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes FeedbackReceiver identified by ids.
|
/// Deletes FeedbackReceiver identified by ids.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -143,7 +146,7 @@ namespace Retroactiune.Controllers
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpDelete]
|
[HttpDelete]
|
||||||
[ProducesResponseType(typeof(NoContentResult), StatusCodes.Status204NoContent)]
|
[ProducesResponseType(typeof(NoContentResult), StatusCodes.Status204NoContent)]
|
||||||
[ProducesResponseType(typeof(BasicResponse),StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(typeof(BasicResponse), StatusCodes.Status400BadRequest)]
|
||||||
public async Task<IActionResult> DeleteMany([Required] IEnumerable<string> ids)
|
public async Task<IActionResult> DeleteMany([Required] IEnumerable<string> ids)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -153,6 +156,7 @@ namespace Retroactiune.Controllers
|
||||||
}
|
}
|
||||||
catch (GenericServiceException e)
|
catch (GenericServiceException e)
|
||||||
{
|
{
|
||||||
|
_logger.LogError("{Message}", e.Message);
|
||||||
return BadRequest(new BasicResponse
|
return BadRequest(new BasicResponse
|
||||||
{
|
{
|
||||||
Message = e.Message
|
Message = e.Message
|
||||||
|
|
|
@ -2,8 +2,11 @@
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using AutoMapper;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Retroactiune.Core.Entities;
|
||||||
using Retroactiune.Core.Interfaces;
|
using Retroactiune.Core.Interfaces;
|
||||||
using Retroactiune.Core.Services;
|
using Retroactiune.Core.Services;
|
||||||
using Retroactiune.DataTransferObjects;
|
using Retroactiune.DataTransferObjects;
|
||||||
|
@ -14,18 +17,46 @@ namespace Retroactiune.Controllers
|
||||||
[Route("api/v1/[controller]")]
|
[Route("api/v1/[controller]")]
|
||||||
public class TokensController : ControllerBase
|
public class TokensController : ControllerBase
|
||||||
{
|
{
|
||||||
// TODO: Implement ListTokens.
|
|
||||||
// Filters for: FeedbackReceiver IDS
|
|
||||||
// for: start < CreatedTime < end
|
|
||||||
// for start < TimeUsed end
|
|
||||||
|
|
||||||
private readonly IFeedbackReceiverService _feedbackReceiverService;
|
private readonly IFeedbackReceiverService _feedbackReceiverService;
|
||||||
private readonly ITokensService _tokensService;
|
private readonly ITokensService _tokensService;
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
public TokensController(IFeedbackReceiverService feedbackReceiverService, ITokensService tokensService)
|
public TokensController(IFeedbackReceiverService feedbackReceiverService, ITokensService tokensService,
|
||||||
|
ILogger<TokensController> logger, IMapper mapper)
|
||||||
{
|
{
|
||||||
_feedbackReceiverService = feedbackReceiverService;
|
_feedbackReceiverService = feedbackReceiverService;
|
||||||
_tokensService = tokensService;
|
_tokensService = tokensService;
|
||||||
|
_mapper = mapper;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The list tokens controller retrieves a list of tokens.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filtersDto">Object that holds filters for listing tokens.</param>
|
||||||
|
/// <response code="200">A list of tokens.</response>
|
||||||
|
/// <response code="400">The request is invalid.</response>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<Token>), StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
public async Task<IActionResult> ListTokens([FromQuery] ListTokensFiltersDto filtersDto)
|
||||||
|
{
|
||||||
|
// TODO: Write unit & integration tests.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var tokenFilters = _mapper.Map<TokenListFilters>(filtersDto);
|
||||||
|
var response = await _tokensService.ListTokens(tokenFilters);
|
||||||
|
return Ok(response);
|
||||||
|
}
|
||||||
|
catch (GenericServiceException e)
|
||||||
|
{
|
||||||
|
_logger.LogError("{Message}", e.Message);
|
||||||
|
return BadRequest(new BasicResponse()
|
||||||
|
{
|
||||||
|
Message = e.Message
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -69,7 +100,7 @@ namespace Retroactiune.Controllers
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpDelete]
|
[HttpDelete]
|
||||||
[ProducesResponseType(typeof(NoContentResult), StatusCodes.Status204NoContent)]
|
[ProducesResponseType(typeof(NoContentResult), StatusCodes.Status204NoContent)]
|
||||||
[ProducesResponseType(typeof(BasicResponse),StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(typeof(BasicResponse), StatusCodes.Status400BadRequest)]
|
||||||
public async Task<IActionResult> DeleteTokens([Required] IEnumerable<string> tokenIds)
|
public async Task<IActionResult> DeleteTokens([Required] IEnumerable<string> tokenIds)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -79,13 +110,14 @@ namespace Retroactiune.Controllers
|
||||||
}
|
}
|
||||||
catch (GenericServiceException e)
|
catch (GenericServiceException e)
|
||||||
{
|
{
|
||||||
|
_logger.LogError("{Message}", e.Message);
|
||||||
return BadRequest(new BasicResponse
|
return BadRequest(new BasicResponse
|
||||||
{
|
{
|
||||||
Message = e.Message
|
Message = e.Message
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes a Token given it's guid.
|
/// Deletes a Token given it's guid.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -97,15 +129,17 @@ namespace Retroactiune.Controllers
|
||||||
[ProducesResponseType(typeof(NoContentResult), StatusCodes.Status204NoContent)]
|
[ProducesResponseType(typeof(NoContentResult), StatusCodes.Status204NoContent)]
|
||||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
public async Task<IActionResult> DeleteToken(
|
public async Task<IActionResult> DeleteToken(
|
||||||
[StringLength(24, ErrorMessage = "invalid guid, must be 24 characters", MinimumLength = 24)] string guid)
|
[StringLength(24, ErrorMessage = "invalid guid, must be 24 characters", MinimumLength = 24)]
|
||||||
|
string guid)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _tokensService.DeleteTokens(new []{ guid });
|
await _tokensService.DeleteTokens(new[] {guid});
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
catch (GenericServiceException e)
|
catch (GenericServiceException e)
|
||||||
{
|
{
|
||||||
|
_logger.LogError("{Message}", e.Message);
|
||||||
return BadRequest(new BasicResponse
|
return BadRequest(new BasicResponse
|
||||||
{
|
{
|
||||||
Message = e.Message
|
Message = e.Message
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Retroactiune.Core.Entities;
|
||||||
|
|
||||||
|
namespace Retroactiune.DataTransferObjects
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// DTO with filters for listing tokens. <see cref="Token"/>
|
||||||
|
/// </summary>
|
||||||
|
public class ListTokensFiltersDto
|
||||||
|
{
|
||||||
|
public IEnumerable<string> Id { get; set; }
|
||||||
|
[StringLength(24, ErrorMessage = "invalid guid, must be 24 characters", MinimumLength = 24)]
|
||||||
|
public string FeedbackReceiverId { get; set; }
|
||||||
|
public DateTime? CreatedAfter { get; set; }
|
||||||
|
public DateTime? CreatedBefore { get; set; }
|
||||||
|
public DateTime? UsedAfter { get; set; }
|
||||||
|
public DateTime? UsedBefore { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using Retroactiune.Core.Entities;
|
using Retroactiune.Core.Entities;
|
||||||
|
using Retroactiune.Core.Services;
|
||||||
using Retroactiune.DataTransferObjects;
|
using Retroactiune.DataTransferObjects;
|
||||||
|
|
||||||
namespace Retroactiune
|
namespace Retroactiune
|
||||||
|
@ -8,6 +9,7 @@ namespace Retroactiune
|
||||||
{
|
{
|
||||||
public MappingProfile()
|
public MappingProfile()
|
||||||
{
|
{
|
||||||
|
CreateMap<ListTokensFiltersDto, TokenListFilters>();
|
||||||
CreateMap<FeedbackReceiver, FeedbackReceiverInDto>().ReverseMap();
|
CreateMap<FeedbackReceiver, FeedbackReceiverInDto>().ReverseMap();
|
||||||
CreateMap<FeedbackReceiver, FeedbackReceiverOutDto>();
|
CreateMap<FeedbackReceiver, FeedbackReceiverOutDto>();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue