Swagger Documentation Enhancement (273)

This commit is contained in:
Santhosh S
2023-08-24 21:25:38 -04:00
parent 9345ee2ca5
commit e56ffae1a4
22 changed files with 288 additions and 49 deletions

View File

@ -16,6 +16,9 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
{
this.surveyResponseProvider = surveyResponseProvider;
}
/// <summary>
/// GET request for retrieving survey responses.
/// </summary>
[HttpGet("SurveyResponses")]
public async Task<ActionResult> GetSurveyResponsesAsync()
@ -31,7 +34,10 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
return BadRequest(result.ErrorMessage);
}
/// <summary>
/// GET request for retrieving survey responses by survey ID.
/// </summary>
[HttpGet("SurveyResponses/{surveyId}")]
public async Task<ActionResult> GetSurveyResponsesAsync(int surveyId)
{
@ -42,6 +48,11 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
}
return NoContent();
}
/// <summary>
/// GET request for retrieving survey responses by survey and location IDs.
/// </summary>
/// <param name="surveyId">The ID of the survey for which responses are to be retrieved.</param>
/// <param name="locationId">The ID of the location for which responses are to be retrieved.</param>
[HttpGet("Responses/{surveyId}/{locationId}")]
public async Task<ActionResult> GetSurveyResponsesBySurveyAndLocationAsync(int surveyId, string locationId)
@ -54,6 +65,12 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
return NoContent();
}
/// <summary>
/// GET request for retrieving survey responses by survey, question, and answer.
/// </summary>
/// <param name="surveyId">The ID of the survey for which responses are to be retrieved.</param>
/// <param name="questionId">The ID of the question for which responses are to be retrieved.</param>
/// <param name="answer">The answer for which responses are to be retrieved.</param>
[HttpGet("ResponsesByAnswer/{surveyId}/{questionId}/{answer}")]
public async Task<ActionResult> GetSurveyResponsesByAnswerAsyncAsync(int surveyId, int questionId, string answer)
@ -66,6 +83,10 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
return NoContent();
}
/// <summary>
/// GET request for retrieving answers from survey responses by survey ID and region.
/// </summary>
/// <param name="surveyId">The ID of the survey for which answers are to be retrieved.</param>
[HttpGet("AnswersByRegion/{surveyId}")]
public async Task<ActionResult> GetAnswersByRegionAsync(int surveyId)
@ -77,6 +98,10 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
}
return NoContent();
}
/// <summary>
/// GET request for retrieving survey responses by survey ID and maintenance center.
/// </summary>
/// <param name="surveyId">The ID of the survey for which responses are to be retrieved.</param>
[HttpGet("AnswersByMaintenanceCenter/{surveyId}")]
public async Task<ActionResult> GetAnswersByMaintenaceCentersync(int surveyId)
@ -88,6 +113,10 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
}
return NoContent();
}
/// <summary>
/// GET request for retrieving a survey response by response ID.
/// </summary>
/// <param name="responseId">The ID of the survey response to be retrieved.</param>
[HttpGet("SurveyResponse/{responseId}")]
public async Task<ActionResult> GetSurveyResponseByIdAsync(int responseId)
@ -100,6 +129,10 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
return NoContent();
}
/// <summary>
/// POST request for creating a new survey response.
/// </summary>
/// <param name="surveyResponse">The survey response object to be created.</param>
[HttpPost("SurveyResponses")]
public async Task<ActionResult> PostSurveysAsync(Models.SurveyResponse surveyResponse)
@ -111,6 +144,11 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
}
return BadRequest(result.ErrorMessage);
}
/// <summary>
/// PUT request for updating an existing survey response.
/// </summary>
/// <param name="Id">The ID of the survey response to be updated.</param>
/// <param name="surveyResponse">The updated survey response object.</param>
[HttpPut("SurveyResponses/{Id}")]
public async Task<ActionResult> PutSurveyResponseAsync(int Id, Models.SurveyResponse surveyResponse)
@ -125,7 +163,10 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
return BadRequest(result.ErrorMessage);
}
/// <summary>
/// DELETE request for deleting an existing survey response.
/// </summary>
[HttpDelete("SurveyResponses/{Id}")]
public async Task<ActionResult> DeleteSurveyResponseAsync(int Id)
{
@ -136,6 +177,10 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
}
return NotFound();
}
/// <summary>
/// POST request for submitting survey with multiple answers.
/// </summary>
/// <param name="answers">The answers to be submitted for the survey.</param>
[HttpPost("SurveyResponses/Answers")]
public async Task<ActionResult> PostSurveyAnswersAsync(AnswerRequest answers)

View File

@ -4,6 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>

View File

@ -4,6 +4,7 @@ using DamageAssesment.Api.SurveyResponses.Providers;
using Microsoft.AspNetCore.DataProtection.XmlEncryption;
using Microsoft.EntityFrameworkCore;
using Polly;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args);
const int maxApiCallRetries = 3;
@ -50,7 +51,14 @@ builder.Services.AddHttpClient<ISurveyServiceProvider, SurveyServiceProvider>().
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
//builder.Services.AddSwaggerGen();
builder.Services.AddSwaggerGen(c =>
{
// Include XML comments from your assembly
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
builder.Services.AddDbContext<SurveyResponseDbContext>(option =>
{
option.UseInMemoryDatabase("SurveyResponses");