Skip to content

Commit

Permalink
Respond to consultation request from VH Officer and transfer to provi…
Browse files Browse the repository at this point in the history
…ded consultation room
  • Loading branch information
shaed-parkar committed Aug 27, 2019
1 parent de0c048 commit d66f2a0
Show file tree
Hide file tree
Showing 17 changed files with 587 additions and 216 deletions.
1 change: 1 addition & 0 deletions VideoAPI/Testing.Common/Helper/ApiUriFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class ConsultationEndpoints

public string HandleConsultationRequest => $"{ApiRoot}";
public string LeaveConsultationRequest => $"{ApiRoot}/leave";
public string RespondToAdminConsultationRequest => $"{ApiRoot}/vhofficer/respond";

}

Expand Down
36 changes: 36 additions & 0 deletions VideoAPI/Video.API/Controllers/ConsultationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ await NotifyConsultationResponse(conference, requestedBy, requestedFor,
[HttpPost("leave")]
[SwaggerOperation(OperationId = "LeavePrivateConsultation")]
[ProducesResponseType((int) HttpStatusCode.NoContent)]
[ProducesResponseType((int) HttpStatusCode.NotFound)]
[ProducesResponseType((int) HttpStatusCode.BadRequest)]
public async Task<IActionResult> LeavePrivateConsultation(LeaveConsultationRequest request)
{
Expand Down Expand Up @@ -159,6 +160,41 @@ public async Task<IActionResult> LeavePrivateConsultation(LeaveConsultationReque
return NoContent();
}

[HttpPost("vhofficer/respond")]
[SwaggerOperation(OperationId = "RespondToAdminConsultationRequest")]
[ProducesResponseType((int) HttpStatusCode.NoContent)]
[ProducesResponseType((int) HttpStatusCode.NotFound)]
[ProducesResponseType((int) HttpStatusCode.BadRequest)]
public async Task<IActionResult> RespondToAdminConsultationRequest(AdminConsultationRequest request)
{
_logger.LogDebug($"RespondToAdminConsultationRequest");

var getConferenceByIdQuery = new GetConferenceByIdQuery(request.ConferenceId);
var conference =
await _queryHandler.Handle<GetConferenceByIdQuery, Conference>(getConferenceByIdQuery);

if (conference == null)
{
_logger.LogError($"Unable to find conference {request.ConferenceId}");
return NotFound();
}

var participant = conference.GetParticipants().SingleOrDefault(x => x.Id == request.ParticipantId);
if (participant == null)
{
_logger.LogError($"Unable to find participant request by with id {request.ParticipantId}");
return NotFound();
}

if (request.Answer.Value == ConsultationAnswer.Accepted)
{
await _videoPlatformService.TransferParticipantAsync(conference.Id, participant.Id,
participant.CurrentRoom.Value, request.ConsultationRoom);
}

return NoContent();
}

/// <summary>
/// This method raises a notification to the requestee informing them of an incoming consultation request
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using FluentValidation;
using VideoApi.Contract.Requests;
using VideoApi.Domain.Enums;

namespace Video.API.Validations
{
public class AdminConsultationRequestValidation : AbstractValidator<AdminConsultationRequest>
{
public static readonly string NoConferenceIdErrorMessage = "ConferenceId is required";
public static readonly string NoParticipantIdErrorMessage = "ParticipantId is required";
public static readonly string NoAnswerErrorMessage = "Answer to request is required";
public static readonly string NotValidConsultationRoomMessage = "Room must be a consultation room";

public AdminConsultationRequestValidation()
{
RuleFor(x => x.ConferenceId).NotEmpty().WithMessage(NoConferenceIdErrorMessage);
RuleFor(x => x.ParticipantId).NotEmpty().WithMessage(NoParticipantIdErrorMessage);
RuleFor(x => x.Answer).NotEqual(ConsultationAnswer.None).WithMessage(NoAnswerErrorMessage);
RuleFor(x => x.ConsultationRoom).Custom((type, context) =>
{
var validRooms = new List<RoomType> {RoomType.ConsultationRoom1, RoomType.ConsultationRoom2};
if (!validRooms.Contains(type))
{
context.AddFailure("ConsultationRoom", NotValidConsultationRoomMessage);
}
});
}
}
}
33 changes: 33 additions & 0 deletions VideoAPI/VideoApi.Contract/Requests/AdminConsultationRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.ComponentModel.DataAnnotations;
using VideoApi.Domain.Enums;

namespace VideoApi.Contract.Requests
{
/// <summary>
/// Request a private consultation with another participant
/// </summary>
public class AdminConsultationRequest
{
/// <summary>
/// The conference UUID
/// </summary>
public Guid ConferenceId { get; set; }

/// <summary>
/// UUID of participant VH Officer attempted to call
/// </summary>
public Guid ParticipantId { get; set; }

/// <summary>
/// Consultation Room to use
/// </summary>
public RoomType ConsultationRoom { get; set; }

/// <summary>
/// Response to a consultation request (i.e. 'Accepted or Rejected')
/// </summary>
[EnumDataType(typeof(ConsultationAnswer))]
public ConsultationAnswer? Answer { get; set; }
}
}
2 changes: 1 addition & 1 deletion VideoAPI/VideoApi.Contract/Requests/ConsultationRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ConsultationRequest
[EnumDataType(typeof(ConsultationAnswer))]
public ConsultationAnswer? Answer { get; set; }
}

public enum ConsultationAnswer
{
/// <summary>
Expand Down
1 change: 0 additions & 1 deletion VideoAPI/VideoApi.Events/Handlers/Core/EventHandlerBase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using VideoApi.DAL.Commands.Core;
using VideoApi.DAL.Exceptions;
Expand Down
105 changes: 0 additions & 105 deletions VideoAPI/VideoApi.IntegrationTests/Api/Consultations.feature

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Feature: Respond to Admin Consultations
In order to manage private consultations with the VH Admin team
As an API service
I want to respond to private consultations with the VH Admin team

Scenario: Respond to a VH Officer Consultation with an invalid request
Given I have an invalid respond to admin consultation request
When I send the request to the endpoint
Then the response should have the status BadRequest and success status False
And the error response message should also contain 'ConferenceId is required'
And the error response message should also contain 'ParticipantId is required'
And the error response message should also contain 'Room must be a consultation room'
And the error response message should also contain 'Answer to request is required'

Scenario: Respond to a VH Officer Consultation for a non-existent conference
Given I have a conference
Given I have a nonexistent respond to admin consultation request
When I send the request to the endpoint
Then the response should have the status NotFound and success status False

Scenario: Respond to a VH Officer Consultation for a non-existent participant
Given I have a conference
Given I have a respond to admin consultation request with a non-existent participant
When I send the request to the endpoint
Then the response should have the status NotFound and success status False

Scenario: Respond to a VH Officer Consultation successfully
Given I have a conference
And I have a valid respond to admin consultation request
When I send the request to the endpoint
Then the response should have the status NoContent and success status True
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Feature: Leave Private Consultations
In order to manage private consultations
As an API service
I want to leave private consultations

Scenario: Leave a private consultation with an invalid request
Given I have an invalid leave consultation request
When I send the request to the endpoint
Then the response should have the status BadRequest and success status False
And the error response message should also contain 'ConferenceId is required'
And the error response message should also contain 'ParticipantId is required'

Scenario: Successfully leave a private consultation
Given I have a conference
And I have an valid leave consultation request
When I send the request to the endpoint
Then the response should have the status NoContent and success status True

Scenario: Leaving a consultation for a non-existent conference returns not found
Given I have a conference
And I have an nonexistent leave consultation request
When I send the request to the endpoint
Then the response should have the status NotFound and success status False

Scenario: Leaving a consultation for a non-existent participant returns not found
Given I have a conference
And I have a leave consultation request for a nonexistent participant
When I send the request to the endpoint
Then the response should have the status NotFound and success status False

Scenario: Leaving a consultation for a participant not in a consultation returns a bad request
Given I have a conference
And I have a leave consultation request for a participant not in a consultation
When I send the request to the endpoint
Then the response should have the status BadRequest and success status False
And the error response message should also contain 'is not in a consultation room'
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Feature: Raise Private Consultations
In order to manage private consultations
As an API service
I want to raise private consultations

Scenario: Successfully raise a private consultation request
Given I have a conference
And I have a valid raise consultation request
When I send the request to the endpoint
Then the response should have the status NoContent and success status True

Scenario: Raise private consultation request against non-existent conference
Given I have a conference
And I have a nonexistent raise consultation request
When I send the request to the endpoint
Then the response should have the status NotFound and success status False

Scenario: Raise a private consultation request that fails validation
Given I have an invalid raise consultation request
When I send the request to the endpoint
Then the response should have the status BadRequest and success status False
And the error response message should also contain 'RequestedBy is required'
And the error response message should also contain 'RequestedFor is required'
And the error response message should also contain 'ConferenceId is required'

Scenario: Raise private consultation request when user requested by does not exist
Given I have a conference
And I have a raise consultation request with an invalid requestedBy
When I send the request to the endpoint
Then the response should have the status NotFound and success status False

Scenario: Raise private consultation request when user requested for does not exist
Given I have a conference
And I have a raise consultation request with an invalid requestedFor
When I send the request to the endpoint
Then the response should have the status NotFound and success status False
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Feature: Respond To Consultations
In order to manage private consultations
As an API service
I want to respond to private consultations

Scenario: Successfully respond to a private consultation request
Given I have a conference
And I have a valid respond consultation request
When I send the request to the endpoint
Then the response should have the status NoContent and success status True

Scenario: Respond to private consultation request against non-existent conference
Given I have a conference
And I have a nonexistent respond consultation request
When I send the request to the endpoint
Then the response should have the status NotFound and success status False

Scenario: Respond to a private consultation request that fails validation
Given I have an invalid respond consultation request
When I send the request to the endpoint
Then the response should have the status BadRequest and success status False
And the error response message should also contain 'RequestedBy is required'
And the error response message should also contain 'RequestedFor is required'
And the error response message should also contain 'ConferenceId is required'
And the error response message should also contain 'Answer to request is required'

Scenario: Respond to private consultation request when user requested by does not exist
Given I have a conference
And I have a respond consultation request with an invalid requestedBy
When I send the request to the endpoint
Then the response should have the status NotFound and success status False

Scenario: Respond to private consultation request when user requested for does not exist
Given I have a conference
And I have a respond consultation request with an invalid requestedFor
When I send the request to the endpoint
Then the response should have the status NotFound and success status False
Loading

0 comments on commit d66f2a0

Please sign in to comment.