Add Feedback: Infer FeedbackReceiverId from the generated Token.
This commit is contained in:
parent
85fcc29b61
commit
d3b014c566
3 changed files with 21 additions and 18 deletions
|
@ -428,7 +428,7 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
|
||||||
Rating = 4
|
Rating = 4
|
||||||
};
|
};
|
||||||
var content = JsonSerializer.Serialize(feedback);
|
var content = JsonSerializer.Serialize(feedback);
|
||||||
var response = await _client.PostAsync($"api/v1/feedback_receivers/{feedbackReceiver.Id}/feedbacks",
|
var response = await _client.PostAsync($"api/v1/feedback_receivers/feedbacks",
|
||||||
new StringContent(content, Encoding.UTF8, "application/json"));
|
new StringContent(content, Encoding.UTF8, "application/json"));
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
|
|
@ -219,7 +219,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
var controller = new FeedbackReceiversController(feedbackReceiversService.Object, tokensService.Object,
|
var controller = new FeedbackReceiversController(feedbackReceiversService.Object, tokensService.Object,
|
||||||
feedbacksService.Object, mapper, null,
|
feedbacksService.Object, mapper, null,
|
||||||
logger.Object);
|
logger.Object);
|
||||||
var result = await controller.AddFeedback("guid-test", requestBody);
|
var result = await controller.AddFeedback(requestBody);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsType<BadRequestObjectResult>(result);
|
Assert.IsType<BadRequestObjectResult>(result);
|
||||||
|
@ -243,7 +243,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
var controller = new FeedbackReceiversController(feedbackReceiversService.Object, tokensService.Object,
|
var controller = new FeedbackReceiversController(feedbackReceiversService.Object, tokensService.Object,
|
||||||
feedbacksService.Object, mapper, null,
|
feedbacksService.Object, mapper, null,
|
||||||
logger.Object);
|
logger.Object);
|
||||||
var result = await controller.AddFeedback("guid-test", requestBody);
|
var result = await controller.AddFeedback(requestBody);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsType<BadRequestObjectResult>(result);
|
Assert.IsType<BadRequestObjectResult>(result);
|
||||||
|
@ -277,7 +277,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
var controller = new FeedbackReceiversController(feedbackReceiversService.Object, tokensService.Object,
|
var controller = new FeedbackReceiversController(feedbackReceiversService.Object, tokensService.Object,
|
||||||
feedbacksService.Object, mapper, null,
|
feedbacksService.Object, mapper, null,
|
||||||
logger.Object);
|
logger.Object);
|
||||||
var result = await controller.AddFeedback("guid-test", requestBody);
|
var result = await controller.AddFeedback(requestBody);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsType<BadRequestObjectResult>(result);
|
Assert.IsType<BadRequestObjectResult>(result);
|
||||||
|
@ -314,7 +314,7 @@ namespace Retroactiune.Tests.Retroactiune.WebAPI.Controllers
|
||||||
// Test
|
// Test
|
||||||
var controller = new FeedbackReceiversController(feedbackReceiversService.Object, tokensService.Object,
|
var controller = new FeedbackReceiversController(feedbackReceiversService.Object, tokensService.Object,
|
||||||
feedbacksService.Object, mapper, null, logger.Object);
|
feedbacksService.Object, mapper, null, logger.Object);
|
||||||
var result = await controller.AddFeedback("guid-test", requestBody);
|
var result = await controller.AddFeedback(requestBody);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.IsType<OkResult>(result);
|
Assert.IsType<OkResult>(result);
|
||||||
|
|
|
@ -172,31 +172,21 @@ namespace Retroactiune.Controllers
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add Feedback to a FeedbackReceiver.
|
/// Add Feedback to a FeedbackReceiver.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="guid">The guid of the FeedbackReceiver to add feedback.</param>
|
|
||||||
/// <param name="feedbackInDto">The feedback dto.</param>
|
/// <param name="feedbackInDto">The feedback dto.</param>
|
||||||
/// <response code="200">The feedback has been added.</response>
|
/// <response code="200">The feedback has been added.</response>
|
||||||
/// <response code="400">The request is invalid.</response>
|
/// <response code="400">The request is invalid.</response>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("{guid}/feedbacks")]
|
[HttpPost("feedbacks")]
|
||||||
[ProducesResponseType(typeof(NoContentResult), StatusCodes.Status204NoContent)]
|
[ProducesResponseType(typeof(NoContentResult), StatusCodes.Status204NoContent)]
|
||||||
[ProducesResponseType(typeof(BasicResponse), StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(typeof(BasicResponse), StatusCodes.Status400BadRequest)]
|
||||||
public async Task<IActionResult> AddFeedback(string guid, [FromBody] FeedbackInDto feedbackInDto)
|
public async Task<IActionResult> AddFeedback([FromBody] FeedbackInDto feedbackInDto)
|
||||||
{
|
{
|
||||||
// TODO: Remove guid from request and infer it from the given token.
|
|
||||||
var receivers = await _feedbackReceiversService.FindAsync(new[] {guid}, limit: 1);
|
|
||||||
var tokenEnum = await _tokensService.FindAsync(new TokenListFilters
|
var tokenEnum = await _tokensService.FindAsync(new TokenListFilters
|
||||||
{
|
{
|
||||||
Ids = new[] {feedbackInDto.TokenId}
|
Ids = new[] {feedbackInDto.TokenId}
|
||||||
});
|
});
|
||||||
var feedbackReceivers = receivers as FeedbackReceiver[] ?? receivers.ToArray();
|
|
||||||
var tokens = (tokenEnum as Token[] ?? tokenEnum.ToArray());
|
var tokens = (tokenEnum as Token[] ?? tokenEnum.ToArray());
|
||||||
if (!feedbackReceivers.Any())
|
|
||||||
{
|
|
||||||
return BadRequest(new BasicResponse
|
|
||||||
{
|
|
||||||
Message = $"FeedbackReceiver with id {guid} not found."
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tokens.Length == 0)
|
if (tokens.Length == 0)
|
||||||
{
|
{
|
||||||
|
@ -207,6 +197,19 @@ namespace Retroactiune.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
var token = tokens[0];
|
var token = tokens[0];
|
||||||
|
|
||||||
|
var receivers = await _feedbackReceiversService.FindAsync(
|
||||||
|
new[] {token.FeedbackReceiverId}, limit: 1
|
||||||
|
);
|
||||||
|
var feedbackReceivers = receivers as FeedbackReceiver[] ?? receivers.ToArray();
|
||||||
|
if (!feedbackReceivers.Any())
|
||||||
|
{
|
||||||
|
return BadRequest(new BasicResponse
|
||||||
|
{
|
||||||
|
Message = $"FeedbackReceiver with id {token.FeedbackReceiverId} not found."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!token.IsValid(feedbackReceivers[0]))
|
if (!token.IsValid(feedbackReceivers[0]))
|
||||||
{
|
{
|
||||||
return BadRequest(new BasicResponse
|
return BadRequest(new BasicResponse
|
||||||
|
|
Loading…
Reference in a new issue