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

@ -14,7 +14,10 @@ namespace DamageAssesment.Api.Answers.Controllers
public AnswersController(IAnswersProvider answersProvider) { public AnswersController(IAnswersProvider answersProvider) {
this.answerProvider=answersProvider; this.answerProvider=answersProvider;
} }
//get all answers /// <summary>
/// Get all answers
/// </summary>
[HttpGet("Answers")] [HttpGet("Answers")]
public async Task<ActionResult> GetAnswersAsync() { public async Task<ActionResult> GetAnswersAsync() {
@ -26,7 +29,11 @@ namespace DamageAssesment.Api.Answers.Controllers
return NoContent(); return NoContent();
} }
//get answer based on answerid /// <summary>
/// Get an answer based on answerId.
/// </summary>
[HttpGet("Answers/{Id}")] [HttpGet("Answers/{Id}")]
public async Task<ActionResult> GetAnswerByIdAsync(int Id) public async Task<ActionResult> GetAnswerByIdAsync(int Id)
{ {
@ -39,7 +46,9 @@ namespace DamageAssesment.Api.Answers.Controllers
return NotFound(); return NotFound();
} }
// get all answers based on response id /// <summary>
/// Get all answers based on responseId.
/// </summary>
[HttpGet("AnswersByResponse/{ResponseId}")] [HttpGet("AnswersByResponse/{ResponseId}")]
public async Task<IActionResult> GetAnswersByResponseId(int ResponseId) public async Task<IActionResult> GetAnswersByResponseId(int ResponseId)
{ {
@ -50,7 +59,10 @@ namespace DamageAssesment.Api.Answers.Controllers
} }
return NoContent(); return NoContent();
} }
// get all answers based on question id /// <summary>
/// Get all answers based on questionId.
/// </summary>
[HttpGet("AnswersByQuestion/{QuestionId}")] [HttpGet("AnswersByQuestion/{QuestionId}")]
public async Task<IActionResult> AnswersByQuestionId(int QuestionId) public async Task<IActionResult> AnswersByQuestionId(int QuestionId)
{ {
@ -61,7 +73,9 @@ namespace DamageAssesment.Api.Answers.Controllers
} }
return NotFound(); return NotFound();
} }
//update existing answer /// <summary>
/// Update an existing answer.
/// </summary>
[HttpPut("Answers")] [HttpPut("Answers")]
public async Task<IActionResult> UpdateAnswer(Db.Answer answer) public async Task<IActionResult> UpdateAnswer(Db.Answer answer)
@ -80,7 +94,10 @@ namespace DamageAssesment.Api.Answers.Controllers
} }
return NotFound(); return NotFound();
} }
//save new answer /// <summary>
/// Save a new answer.
/// </summary>
[HttpPost("Answers")] [HttpPost("Answers")]
public async Task<IActionResult> CreateAnswer(Db.Answer answer) public async Task<IActionResult> CreateAnswer(Db.Answer answer)
{ {
@ -95,7 +112,10 @@ namespace DamageAssesment.Api.Answers.Controllers
} }
return CreatedAtRoute("DefaultApi", new { id = answer.Id }, answer); return CreatedAtRoute("DefaultApi", new { id = answer.Id }, answer);
} }
//delete existing answer /// <summary>
/// Delete an existing answer.
/// </summary>
[HttpDelete("Answers/{id}")] [HttpDelete("Answers/{id}")]
public async Task<IActionResult> DeleteAnswer(int id) public async Task<IActionResult> DeleteAnswer(int id)
{ {

View File

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

View File

@ -2,6 +2,7 @@ using DamageAssesment.Api.Answers.Db;
using DamageAssesment.Api.Answers.Interfaces; using DamageAssesment.Api.Answers.Interfaces;
using DamageAssesment.Api.Answers.Providers; using DamageAssesment.Api.Answers.Providers;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -10,7 +11,14 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers(); builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); 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.AddScoped<IAnswersProvider, AnswersProvider>(); builder.Services.AddScoped<IAnswersProvider, AnswersProvider>();
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30 builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30
builder.Services.AddDbContext<AnswerDbContext>(option => builder.Services.AddDbContext<AnswerDbContext>(option =>

View File

@ -19,7 +19,10 @@ namespace DamageAssesment.Api.Attachments.Controllers
this.AttachmentProvider = AttachmentsProvider; this.AttachmentProvider = AttachmentsProvider;
this.UploadService = uploadService; this.UploadService = uploadService;
} }
//get all Attachments /// <summary>
/// Get all attachments.
/// </summary>
[HttpGet("Attachments")] [HttpGet("Attachments")]
public async Task<ActionResult> GetAttachmentsAsync() public async Task<ActionResult> GetAttachmentsAsync()
{ {
@ -32,7 +35,9 @@ namespace DamageAssesment.Api.Attachments.Controllers
return NoContent(); return NoContent();
} }
//get all Attachment by Id /// <summary>
/// Get all attachments by attachmentId.
/// </summary>
[HttpGet("Attachments/{id}")] [HttpGet("Attachments/{id}")]
public async Task<ActionResult> GetAttachmentbyIdAsync(int id) public async Task<ActionResult> GetAttachmentbyIdAsync(int id)
{ {
@ -73,7 +78,10 @@ namespace DamageAssesment.Api.Attachments.Controllers
// } // }
//} //}
//Save new Attachment /// <summary>
/// Save new Attachment(s)
/// </summary>
[HttpPost("Attachments"), DisableRequestSizeLimit] [HttpPost("Attachments"), DisableRequestSizeLimit]
public async Task<IActionResult> UploadAttachmentAsync(AttachmentInfo attachmentInfo) public async Task<IActionResult> UploadAttachmentAsync(AttachmentInfo attachmentInfo)
{ {
@ -97,8 +105,10 @@ namespace DamageAssesment.Api.Attachments.Controllers
return BadRequest($"Internal server error: {ex}"); return BadRequest($"Internal server error: {ex}");
} }
} }
/// <summary>
/// Modify an new attachment.
/// </summary>
//Save new Attachment
[HttpPut("Attachments"), DisableRequestSizeLimit] [HttpPut("Attachments"), DisableRequestSizeLimit]
public async Task<IActionResult> UpdateAttachmentAsync(AttachmentInfo attachmentInfo) public async Task<IActionResult> UpdateAttachmentAsync(AttachmentInfo attachmentInfo)
{ {
@ -126,7 +136,9 @@ namespace DamageAssesment.Api.Attachments.Controllers
return BadRequest($"Internal server error: {ex}"); return BadRequest($"Internal server error: {ex}");
} }
} }
//delete existing Attachment /// <summary>
/// Delete an existing attachment.
/// </summary>
[HttpDelete("Delete")] [HttpDelete("Delete")]
public async Task<IActionResult> DeleteAttachment(int Id) public async Task<IActionResult> DeleteAttachment(int Id)
{ {

View File

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

View File

@ -4,6 +4,7 @@ using DamageAssesment.Api.Attachments.Providers;
using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Http.Features;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -12,7 +13,14 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers(); builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); 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.AddScoped<IAttachmentsProvider, AttachmentsProvider>(); builder.Services.AddScoped<IAttachmentsProvider, AttachmentsProvider>();
builder.Services.AddScoped<IUploadService, UploadService>(); builder.Services.AddScoped<IUploadService, UploadService>();
builder.Services.AddScoped<IAzureBlobService,AzureBlobService>(); builder.Services.AddScoped<IAzureBlobService,AzureBlobService>();

View File

@ -15,7 +15,11 @@ namespace DamageAssesment.Api.Employees.Controllers
{ {
this.EmployeeProvider = EmployeesProvider; this.EmployeeProvider = EmployeesProvider;
} }
//get all Employees
/// <summary>
/// GET request for retrieving employees.
/// </summary>
[HttpGet("Employees")] [HttpGet("Employees")]
public async Task<ActionResult> GetEmployeesAsync() public async Task<ActionResult> GetEmployeesAsync()
{ {
@ -28,7 +32,11 @@ namespace DamageAssesment.Api.Employees.Controllers
return NoContent(); return NoContent();
} }
//get Employee based on Employeeid
/// <summary>
/// GET request for retrieving an employee by ID.
/// </summary>
[HttpGet("Employees/{Id}")] [HttpGet("Employees/{Id}")]
public async Task<ActionResult> GetEmployeeByIdAsync(string Id) public async Task<ActionResult> GetEmployeeByIdAsync(string Id)
{ {
@ -41,8 +49,11 @@ namespace DamageAssesment.Api.Employees.Controllers
return NotFound(); return NotFound();
} }
//update existing Employee
/// <summary>
/// PUT request for updating an existing employee.
/// </summary>
/// <param name="Employee">The updated employee object.</param>
[HttpPut("Employees")] [HttpPut("Employees")]
public async Task<IActionResult> UpdateEmployee(Db.Employee Employee) public async Task<IActionResult> UpdateEmployee(Db.Employee Employee)
{ {
@ -60,7 +71,11 @@ namespace DamageAssesment.Api.Employees.Controllers
} }
return NotFound(); return NotFound();
} }
//save new Employee
/// <summary>
/// POST request for creating a new employee.
/// </summary>
/// <param name="Employee">The employee information for creating a new employee.</param>
[HttpPost("Employees")] [HttpPost("Employees")]
public async Task<IActionResult> CreateEmployee(Db.Employee Employee) public async Task<IActionResult> CreateEmployee(Db.Employee Employee)
{ {
@ -75,7 +90,10 @@ namespace DamageAssesment.Api.Employees.Controllers
} }
return CreatedAtRoute("DefaultApi", new { id = Employee.Id }, Employee); return CreatedAtRoute("DefaultApi", new { id = Employee.Id }, Employee);
} }
//delete existing Employee /// <summary>
/// DELETE request for deleting an existing employee.
/// </summary>
/// <param name="id">The ID of the employee to be deleted.</param>
[HttpDelete("Employees/{id}")] [HttpDelete("Employees/{id}")]
public async Task<IActionResult> DeleteEmployee(string id) public async Task<IActionResult> DeleteEmployee(string id)
{ {

View File

@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -2,6 +2,7 @@ using DamageAssesment.Api.Employees.Db;
using DamageAssesment.Api.Employees.Interfaces; using DamageAssesment.Api.Employees.Interfaces;
using DamageAssesment.Api.Employees.Providers; using DamageAssesment.Api.Employees.Providers;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -10,7 +11,15 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers(); builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); 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.AddScoped<IEmployeesProvider, EmployeesProvider>(); builder.Services.AddScoped<IEmployeesProvider, EmployeesProvider>();
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30 builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30
builder.Services.AddDbContext<EmployeeDbContext>(option => builder.Services.AddDbContext<EmployeeDbContext>(option =>

View File

@ -14,7 +14,10 @@ namespace DamageAssesment.Api.Locations.Controllers
{ {
this.LocationProvider = LocationsProvider; this.LocationProvider = LocationsProvider;
} }
// Get all Locations /// <summary>
/// Get all locations.
/// </summary>
[HttpGet("Locations")] [HttpGet("Locations")]
public async Task<ActionResult> GetLocationsAsync() public async Task<ActionResult> GetLocationsAsync()
{ {
@ -27,7 +30,10 @@ namespace DamageAssesment.Api.Locations.Controllers
return NotFound(); return NotFound();
} }
// Get all Location based on Id /// <summary>
/// Get all locations based on locationdId.
/// </summary>
[HttpGet("Locations/{id}")] [HttpGet("Locations/{id}")]
public async Task<ActionResult> GetLocationByIdAsync(string id) public async Task<ActionResult> GetLocationByIdAsync(string id)
{ {
@ -40,7 +46,10 @@ namespace DamageAssesment.Api.Locations.Controllers
return NotFound(); return NotFound();
} }
// Update Location entity /// <summary>
/// Update a Location.
/// </summary>
[HttpPut("Locations")] [HttpPut("Locations")]
public async Task<IActionResult> UpdateLocation(Db.Location Location) public async Task<IActionResult> UpdateLocation(Db.Location Location)
{ {
@ -55,7 +64,10 @@ namespace DamageAssesment.Api.Locations.Controllers
} }
return NotFound(); return NotFound();
} }
//save new location /// <summary>
/// Save a new location.
/// </summary>
[HttpPost("Locations")] [HttpPost("Locations")]
public async Task<IActionResult> CreateLocation(Db.Location Location) public async Task<IActionResult> CreateLocation(Db.Location Location)
{ {
@ -70,7 +82,10 @@ namespace DamageAssesment.Api.Locations.Controllers
} }
return CreatedAtRoute("DefaultApi", new { id = Location.Id }, Location); return CreatedAtRoute("DefaultApi", new { id = Location.Id }, Location);
} }
//delete existing location /// <summary>
/// Delete an existing location.
/// </summary>
[HttpDelete("Locations/{id}")] [HttpDelete("Locations/{id}")]
public async Task<IActionResult> DeleteLocation(string id) public async Task<IActionResult> DeleteLocation(string id)
{ {

View File

@ -13,8 +13,10 @@ namespace DamageAssesment.Api.Locations.Controllers
{ {
this.regionProvider = regionProvider; this.regionProvider = regionProvider;
} }
/// <summary>
/// Get all regions.
/// </summary>
// Get all Regions
[HttpGet] [HttpGet]
public async Task<ActionResult> GetRegionsAsync() public async Task<ActionResult> GetRegionsAsync()
{ {
@ -25,6 +27,9 @@ namespace DamageAssesment.Api.Locations.Controllers
} }
return NoContent(); return NoContent();
} }
/// <summary>
/// GET request for retrieving a region by its ID.
/// </summary>
[HttpGet("{Id}")] [HttpGet("{Id}")]
public async Task<ActionResult> GetRegionAsync(string Id) public async Task<ActionResult> GetRegionAsync(string Id)
@ -36,6 +41,9 @@ namespace DamageAssesment.Api.Locations.Controllers
} }
return NotFound(); return NotFound();
} }
/// <summary>
/// POST request for creating a new region.
/// </summary>
[HttpPost] [HttpPost]
public async Task<ActionResult> PostRegionAsync(Models.Region region) public async Task<ActionResult> PostRegionAsync(Models.Region region)
@ -47,6 +55,9 @@ namespace DamageAssesment.Api.Locations.Controllers
} }
return BadRequest(result.ErrorMessage); return BadRequest(result.ErrorMessage);
} }
/// <summary>
/// PUT request for updating an existing region.
/// </summary>
[HttpPut] [HttpPut]
public async Task<ActionResult> PutRegionAsync(Models.Region region) public async Task<ActionResult> PutRegionAsync(Models.Region region)
@ -61,6 +72,10 @@ namespace DamageAssesment.Api.Locations.Controllers
return BadRequest(result.ErrorMessage); return BadRequest(result.ErrorMessage);
} }
/// <summary>
/// DELETE request for deleting a region based on ID.
/// </summary>
[HttpDelete("{Id}")] [HttpDelete("{Id}")]
public async Task<ActionResult> DeleteRegionAsync(string Id) public async Task<ActionResult> DeleteRegionAsync(string Id)

View File

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

View File

@ -2,6 +2,7 @@ using DamageAssesment.Api.Locations.Db;
using DamageAssesment.Api.Locations.Interfaces; using DamageAssesment.Api.Locations.Interfaces;
using DamageAssesment.Api.Locations.Providers; using DamageAssesment.Api.Locations.Providers;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -10,8 +11,14 @@ var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers(); builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer(); 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.AddScoped<ILocationsProvider, LocationsProvider>(); builder.Services.AddScoped<ILocationsProvider, LocationsProvider>();
builder.Services.AddScoped<IRegionsProvider, RegionsProvider>(); builder.Services.AddScoped<IRegionsProvider, RegionsProvider>();
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30 builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30

View File

@ -19,7 +19,10 @@ namespace DamageAssesment.Api.Questions.Controllers
this.questionsProvider = questionsProvider; this.questionsProvider = questionsProvider;
} }
// get all questions /// <summary>
/// GET request for retrieving questions.
/// </summary>
[HttpGet("Questions")] [HttpGet("Questions")]
public async Task<IActionResult> GetQuestionsAsync() public async Task<IActionResult> GetQuestionsAsync()
{ {
@ -30,7 +33,10 @@ namespace DamageAssesment.Api.Questions.Controllers
} }
return NoContent(); return NoContent();
} }
//Get questions based on question id /// <summary>
/// GET request for retrieving a question by ID.
/// </summary>
[HttpGet("Questions/{id}")] [HttpGet("Questions/{id}")]
public async Task<IActionResult> GetQuestionAsync(int id) public async Task<IActionResult> GetQuestionAsync(int id)
{ {
@ -41,7 +47,11 @@ namespace DamageAssesment.Api.Questions.Controllers
} }
return NotFound(); return NotFound();
} }
//get all questions based on survey id /// <summary>
/// GET request for retrieving survey questions based on a survey ID.
/// Uri: {Optional language}/GetSurveyQuestions/{surveyId} :Default returns question in all languages
/// </summary>
[HttpGet("GetSurveyQuestions/{surveyId}")] [HttpGet("GetSurveyQuestions/{surveyId}")]
public async Task<IActionResult> GetSurveyQuestions(int surveyId,string? Language) public async Task<IActionResult> GetSurveyQuestions(int surveyId,string? Language)
{ {
@ -53,7 +63,10 @@ namespace DamageAssesment.Api.Questions.Controllers
} }
return NotFound(); return NotFound();
} }
//update existing question /// <summary>
/// PUT request for updating a question (multilingual).
/// </summary>
[HttpPut("Questions")] [HttpPut("Questions")]
public async Task<IActionResult> UpdateQuestion(Models.Question question) public async Task<IActionResult> UpdateQuestion(Models.Question question)
{ {
@ -71,7 +84,10 @@ namespace DamageAssesment.Api.Questions.Controllers
} }
return CreatedAtRoute("DefaultApi", new { id = question.Id }, question); return CreatedAtRoute("DefaultApi", new { id = question.Id }, question);
} }
//save new question /// <summary>
/// POST request for creating a new question (multilingual).
/// </summary>
[HttpPost("Questions")] [HttpPost("Questions")]
public async Task<IActionResult> CreateQuestion(Models.Question question) public async Task<IActionResult> CreateQuestion(Models.Question question)
{ {
@ -86,7 +102,10 @@ namespace DamageAssesment.Api.Questions.Controllers
} }
return CreatedAtRoute("DefaultApi", new { id = question.Id }, question); return CreatedAtRoute("DefaultApi", new { id = question.Id }, question);
} }
// delete existing question /// <summary>
/// DELETE request for deleting a question based on ID.
/// </summary>
[HttpDelete("Questions/{id}")] [HttpDelete("Questions/{id}")]
public async Task<IActionResult> DeleteQuestion(int id) public async Task<IActionResult> DeleteQuestion(int id)
{ {
@ -99,7 +118,10 @@ namespace DamageAssesment.Api.Questions.Controllers
} }
// get all questions /// <summary>
/// GET request for retrieving question categories.
/// </summary>
[HttpGet("QuestionCategories")] [HttpGet("QuestionCategories")]
public async Task<IActionResult> GetQuestionCategoriesAsync() public async Task<IActionResult> GetQuestionCategoriesAsync()
{ {
@ -110,7 +132,10 @@ namespace DamageAssesment.Api.Questions.Controllers
} }
return NoContent(); return NoContent();
} }
//Get questions based on question id /// <summary>
/// GET request for retrieving a question category by ID.
/// </summary>
[HttpGet("QuestionCategories/{id}")] [HttpGet("QuestionCategories/{id}")]
public async Task<IActionResult> GetQuestionCategoryAsync(int id) public async Task<IActionResult> GetQuestionCategoryAsync(int id)
{ {
@ -123,7 +148,10 @@ namespace DamageAssesment.Api.Questions.Controllers
} }
//update existing question /// <summary>
/// PUT request for updating a question category.
/// </summary>
[HttpPut("QuestionCategories")] [HttpPut("QuestionCategories")]
public async Task<IActionResult> UpdateQuestionCategory(Models.QuestionCategory questionCategory) public async Task<IActionResult> UpdateQuestionCategory(Models.QuestionCategory questionCategory)
{ {
@ -141,7 +169,10 @@ namespace DamageAssesment.Api.Questions.Controllers
} }
return CreatedAtRoute("DefaultApi", new { id = questionCategory.Id }, questionCategory); return CreatedAtRoute("DefaultApi", new { id = questionCategory.Id }, questionCategory);
} }
//save new question /// <summary>
/// POST request for creating a new question category.
/// </summary>
[HttpPost("QuestionCategories")] [HttpPost("QuestionCategories")]
public async Task<IActionResult> CreateQuestionCategory(Models.QuestionCategory questionCategory) public async Task<IActionResult> CreateQuestionCategory(Models.QuestionCategory questionCategory)
{ {
@ -156,7 +187,10 @@ namespace DamageAssesment.Api.Questions.Controllers
} }
return CreatedAtRoute("DefaultApi", new { id = questionCategory.Id }, questionCategory); return CreatedAtRoute("DefaultApi", new { id = questionCategory.Id }, questionCategory);
} }
// delete existing question /// <summary>
/// DELETE request for deleting a question category based on ID.
/// </summary>
[HttpDelete("QuestionCategories/{id}")] [HttpDelete("QuestionCategories/{id}")]
public async Task<IActionResult> DeleteQuestionCategory(int id) public async Task<IActionResult> DeleteQuestionCategory(int id)
{ {

View File

@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -3,6 +3,7 @@ using DamageAssesment.Api.Questions.Interfaces;
using DamageAssesment.Api.Questions.Providers; using DamageAssesment.Api.Questions.Providers;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -17,7 +18,14 @@ builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
builder.Services.AddEndpointsApiExplorer(); 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<QuestionDbContext>(option => builder.Services.AddDbContext<QuestionDbContext>(option =>
{ {
option.UseInMemoryDatabase("Questions"); option.UseInMemoryDatabase("Questions");

View File

@ -16,6 +16,9 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
{ {
this.surveyResponseProvider = surveyResponseProvider; this.surveyResponseProvider = surveyResponseProvider;
} }
/// <summary>
/// GET request for retrieving survey responses.
/// </summary>
[HttpGet("SurveyResponses")] [HttpGet("SurveyResponses")]
public async Task<ActionResult> GetSurveyResponsesAsync() public async Task<ActionResult> GetSurveyResponsesAsync()
@ -31,6 +34,9 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
return BadRequest(result.ErrorMessage); return BadRequest(result.ErrorMessage);
} }
/// <summary>
/// GET request for retrieving survey responses by survey ID.
/// </summary>
[HttpGet("SurveyResponses/{surveyId}")] [HttpGet("SurveyResponses/{surveyId}")]
public async Task<ActionResult> GetSurveyResponsesAsync(int surveyId) public async Task<ActionResult> GetSurveyResponsesAsync(int surveyId)
@ -42,6 +48,11 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
} }
return NoContent(); 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}")] [HttpGet("Responses/{surveyId}/{locationId}")]
public async Task<ActionResult> GetSurveyResponsesBySurveyAndLocationAsync(int surveyId, string locationId) public async Task<ActionResult> GetSurveyResponsesBySurveyAndLocationAsync(int surveyId, string locationId)
@ -54,6 +65,12 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
return NoContent(); 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}")] [HttpGet("ResponsesByAnswer/{surveyId}/{questionId}/{answer}")]
public async Task<ActionResult> GetSurveyResponsesByAnswerAsyncAsync(int surveyId, int questionId, string answer) public async Task<ActionResult> GetSurveyResponsesByAnswerAsyncAsync(int surveyId, int questionId, string answer)
@ -66,6 +83,10 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
return NoContent(); 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}")] [HttpGet("AnswersByRegion/{surveyId}")]
public async Task<ActionResult> GetAnswersByRegionAsync(int surveyId) public async Task<ActionResult> GetAnswersByRegionAsync(int surveyId)
@ -77,6 +98,10 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
} }
return NoContent(); 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}")] [HttpGet("AnswersByMaintenanceCenter/{surveyId}")]
public async Task<ActionResult> GetAnswersByMaintenaceCentersync(int surveyId) public async Task<ActionResult> GetAnswersByMaintenaceCentersync(int surveyId)
@ -88,6 +113,10 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
} }
return NoContent(); 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}")] [HttpGet("SurveyResponse/{responseId}")]
public async Task<ActionResult> GetSurveyResponseByIdAsync(int responseId) public async Task<ActionResult> GetSurveyResponseByIdAsync(int responseId)
@ -100,6 +129,10 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
return NoContent(); 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")] [HttpPost("SurveyResponses")]
public async Task<ActionResult> PostSurveysAsync(Models.SurveyResponse surveyResponse) public async Task<ActionResult> PostSurveysAsync(Models.SurveyResponse surveyResponse)
@ -111,6 +144,11 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
} }
return BadRequest(result.ErrorMessage); 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}")] [HttpPut("SurveyResponses/{Id}")]
public async Task<ActionResult> PutSurveyResponseAsync(int Id, Models.SurveyResponse surveyResponse) public async Task<ActionResult> PutSurveyResponseAsync(int Id, Models.SurveyResponse surveyResponse)
@ -125,6 +163,9 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
return BadRequest(result.ErrorMessage); return BadRequest(result.ErrorMessage);
} }
/// <summary>
/// DELETE request for deleting an existing survey response.
/// </summary>
[HttpDelete("SurveyResponses/{Id}")] [HttpDelete("SurveyResponses/{Id}")]
public async Task<ActionResult> DeleteSurveyResponseAsync(int Id) public async Task<ActionResult> DeleteSurveyResponseAsync(int Id)
@ -136,6 +177,10 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
} }
return NotFound(); 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")] [HttpPost("SurveyResponses/Answers")]
public async Task<ActionResult> PostSurveyAnswersAsync(AnswerRequest answers) public async Task<ActionResult> PostSurveyAnswersAsync(AnswerRequest answers)

View File

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

View File

@ -4,6 +4,7 @@ using DamageAssesment.Api.SurveyResponses.Providers;
using Microsoft.AspNetCore.DataProtection.XmlEncryption; using Microsoft.AspNetCore.DataProtection.XmlEncryption;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Polly; using Polly;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
const int maxApiCallRetries = 3; const int maxApiCallRetries = 3;
@ -50,7 +51,14 @@ builder.Services.AddHttpClient<ISurveyServiceProvider, SurveyServiceProvider>().
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
builder.Services.AddEndpointsApiExplorer(); 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 => builder.Services.AddDbContext<SurveyResponseDbContext>(option =>
{ {
option.UseInMemoryDatabase("SurveyResponses"); option.UseInMemoryDatabase("SurveyResponses");

View File

@ -14,6 +14,9 @@ namespace DamageAssesment.Api.Surveys.Controllers
{ {
this.surveyProvider = surveyProvider; this.surveyProvider = surveyProvider;
} }
/// <summary>
/// GET request for retrieving surveys.
/// </summary>
[HttpGet] [HttpGet]
public async Task<ActionResult> GetSurveysAsync() public async Task<ActionResult> GetSurveysAsync()
@ -25,6 +28,10 @@ namespace DamageAssesment.Api.Surveys.Controllers
} }
return NoContent(); return NoContent();
} }
/// <summary>
/// GET request for retrieving surveys by ID.
/// </summary>
[HttpGet("{Id}")] [HttpGet("{Id}")]
public async Task<ActionResult> GetSurveysAsync(int Id) public async Task<ActionResult> GetSurveysAsync(int Id)
{ {
@ -35,6 +42,9 @@ namespace DamageAssesment.Api.Surveys.Controllers
} }
return NotFound(); return NotFound();
} }
/// <summary>
/// POST request for creating a new survey.
/// </summary>
[HttpPost] [HttpPost]
public async Task<ActionResult> PostSurveysAsync(Models.Survey survey) public async Task<ActionResult> PostSurveysAsync(Models.Survey survey)
@ -46,6 +56,10 @@ namespace DamageAssesment.Api.Surveys.Controllers
} }
return BadRequest(result.ErrorMessage); return BadRequest(result.ErrorMessage);
} }
/// <summary>
/// PUT request for updating an existing survey (surveyId,Updated Survey data).
/// </summary>
[HttpPut("{Id}")] [HttpPut("{Id}")]
public async Task<ActionResult> PutSurveysAsync(int Id, Models.Survey survey) public async Task<ActionResult> PutSurveysAsync(int Id, Models.Survey survey)
@ -60,6 +74,9 @@ namespace DamageAssesment.Api.Surveys.Controllers
return BadRequest(result.ErrorMessage); return BadRequest(result.ErrorMessage);
} }
/// <summary>
/// DELETE request for deleting a survey by ID.
/// </summary>
[HttpDelete("{Id}")] [HttpDelete("{Id}")]
public async Task<ActionResult> DeleteSurveysAsync(int Id) public async Task<ActionResult> DeleteSurveysAsync(int Id)

View File

@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -2,6 +2,7 @@ using DamageAssesment.Api.Surveys.Db;
using DamageAssesment.Api.Surveys.Interfaces; using DamageAssesment.Api.Surveys.Interfaces;
using DamageAssesment.Api.Surveys.Providers; using DamageAssesment.Api.Surveys.Providers;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -12,7 +13,14 @@ builder.Services.AddControllers();
builder.Services.AddScoped<ISurveyProvider, SurveysProvider>(); builder.Services.AddScoped<ISurveyProvider, SurveysProvider>();
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
builder.Services.AddEndpointsApiExplorer(); 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<SurveysDbContext>(option => builder.Services.AddDbContext<SurveysDbContext>(option =>
{ {
option.UseInMemoryDatabase("Surveys"); option.UseInMemoryDatabase("Surveys");