forked from MDCPS/DamageAssessment_Backend
Multilingual support for survey and Questions
This commit is contained in:
@ -15,11 +15,20 @@ namespace DamageAssesment.Api.Questions.Controllers
|
||||
this.questionsProvider = questionsProvider;
|
||||
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
// get all questions
|
||||
[Route("{Language}/Questions")]
|
||||
[Route("Questions")]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetQuestionsAsync(string? Language)
|
||||
=======
|
||||
/// <summary>
|
||||
/// GET request for retrieving questions.
|
||||
/// </summary>
|
||||
|
||||
[HttpGet("Questions")]
|
||||
public async Task<IActionResult> GetQuestionsAsync()
|
||||
>>>>>>> cf3a04891b7b50d0a02ac9c8b9a78ccb9436c35c
|
||||
{
|
||||
var result = await this.questionsProvider.GetQuestionsAsync(Language);
|
||||
if (result.IsSuccess)
|
||||
@ -28,11 +37,20 @@ namespace DamageAssesment.Api.Questions.Controllers
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
//Get questions based on question id
|
||||
[Route("{Language}/Questions/{id}")]
|
||||
[Route("Questions/{id}")]
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetQuestionAsync(int id, string? Language)
|
||||
=======
|
||||
/// <summary>
|
||||
/// GET request for retrieving a question by ID.
|
||||
/// </summary>
|
||||
|
||||
[HttpGet("Questions/{id}")]
|
||||
public async Task<IActionResult> GetQuestionAsync(int id)
|
||||
>>>>>>> cf3a04891b7b50d0a02ac9c8b9a78ccb9436c35c
|
||||
{
|
||||
var result = await this.questionsProvider.GetQuestionAsync(id,Language);
|
||||
if (result.IsSuccess)
|
||||
@ -41,10 +59,19 @@ namespace DamageAssesment.Api.Questions.Controllers
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
//get all questions based on survey id
|
||||
[Route("{Language}/GetSurveyQuestions/{surveyId}")]
|
||||
[Route("GetSurveyQuestions/{surveyId}")]
|
||||
[HttpGet]
|
||||
=======
|
||||
/// <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}")]
|
||||
>>>>>>> cf3a04891b7b50d0a02ac9c8b9a78ccb9436c35c
|
||||
public async Task<IActionResult> GetSurveyQuestions(int surveyId,string? Language)
|
||||
{
|
||||
var result = await this.questionsProvider.GetSurveyQuestionAsync(surveyId, Language);
|
||||
@ -54,7 +81,10 @@ namespace DamageAssesment.Api.Questions.Controllers
|
||||
}
|
||||
return NotFound();
|
||||
}
|
||||
//update existing question
|
||||
/// <summary>
|
||||
/// PUT request for updating a question (multilingual).
|
||||
/// </summary>
|
||||
|
||||
[HttpPut("Questions")]
|
||||
public async Task<IActionResult> UpdateQuestion(Models.Question question)
|
||||
{
|
||||
@ -72,7 +102,10 @@ namespace DamageAssesment.Api.Questions.Controllers
|
||||
}
|
||||
return CreatedAtRoute("DefaultApi", new { id = question.Id }, question);
|
||||
}
|
||||
//save new question
|
||||
/// <summary>
|
||||
/// POST request for creating a new question (multilingual).
|
||||
/// </summary>
|
||||
|
||||
[HttpPost("Questions")]
|
||||
public async Task<IActionResult> CreateQuestion(Models.Question question)
|
||||
{
|
||||
@ -87,7 +120,10 @@ namespace DamageAssesment.Api.Questions.Controllers
|
||||
}
|
||||
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}")]
|
||||
public async Task<IActionResult> DeleteQuestion(int id)
|
||||
{
|
||||
@ -100,7 +136,10 @@ namespace DamageAssesment.Api.Questions.Controllers
|
||||
}
|
||||
|
||||
|
||||
// get all questions
|
||||
/// <summary>
|
||||
/// GET request for retrieving question categories.
|
||||
/// </summary>
|
||||
|
||||
[HttpGet("QuestionCategories")]
|
||||
public async Task<IActionResult> GetQuestionCategoriesAsync()
|
||||
{
|
||||
@ -111,7 +150,10 @@ namespace DamageAssesment.Api.Questions.Controllers
|
||||
}
|
||||
return NoContent();
|
||||
}
|
||||
//Get questions based on question id
|
||||
/// <summary>
|
||||
/// GET request for retrieving a question category by ID.
|
||||
/// </summary>
|
||||
|
||||
[HttpGet("QuestionCategories/{id}")]
|
||||
public async Task<IActionResult> GetQuestionCategoryAsync(int id)
|
||||
{
|
||||
@ -124,7 +166,10 @@ namespace DamageAssesment.Api.Questions.Controllers
|
||||
}
|
||||
|
||||
|
||||
//update existing question
|
||||
/// <summary>
|
||||
/// PUT request for updating a question category.
|
||||
/// </summary>
|
||||
|
||||
[HttpPut("QuestionCategories")]
|
||||
public async Task<IActionResult> UpdateQuestionCategory(Models.QuestionCategory questionCategory)
|
||||
{
|
||||
@ -142,7 +187,10 @@ namespace DamageAssesment.Api.Questions.Controllers
|
||||
}
|
||||
return CreatedAtRoute("DefaultApi", new { id = questionCategory.Id }, questionCategory);
|
||||
}
|
||||
//save new question
|
||||
/// <summary>
|
||||
/// POST request for creating a new question category.
|
||||
/// </summary>
|
||||
|
||||
[HttpPost("QuestionCategories")]
|
||||
public async Task<IActionResult> CreateQuestionCategory(Models.QuestionCategory questionCategory)
|
||||
{
|
||||
@ -157,7 +205,10 @@ namespace DamageAssesment.Api.Questions.Controllers
|
||||
}
|
||||
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}")]
|
||||
public async Task<IActionResult> DeleteQuestionCategory(int id)
|
||||
{
|
||||
|
@ -1,9 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -20,7 +20,6 @@ namespace DamageAssesment.Api.Questions.Db
|
||||
public bool Key { get; set; }
|
||||
[ForeignKey("Survey")]
|
||||
public int? SurveyId { get; set; }
|
||||
public string QuestionGroup { get; set; }
|
||||
[ForeignKey("QuestionCategory")]
|
||||
public int CategoryId { get; set; }
|
||||
|
||||
|
@ -17,7 +17,6 @@ namespace DamageAssesment.Api.Questions.Models
|
||||
|
||||
public bool Key { get; set; }
|
||||
public int? SurveyId { get; set; }
|
||||
public string QuestionGroup { get; set; }
|
||||
public int CategoryId { get; set; }
|
||||
// public int? Survey_SurveyID { get; set; }
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using DamageAssesment.Api.Questions.Interfaces;
|
||||
using DamageAssesment.Api.Questions.Providers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Reflection;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@ -17,7 +18,14 @@ 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<QuestionDbContext>(option =>
|
||||
{
|
||||
option.UseInMemoryDatabase("Questions");
|
||||
|
@ -37,35 +37,47 @@ namespace DamageAssesment.Api.Questions.Providers
|
||||
questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { Id = 4, QuestionId = 2, QuestionText = "Les terrains sont-ils inondés ?", Language = "fr" });
|
||||
questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { Id = 5, QuestionId = 3, QuestionText = "Is the access blocked by flooding ?", Language = "en" });
|
||||
questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { Id = 6, QuestionId = 3, QuestionText = "L'accès est-il bloqué par les inondations ?", Language = "fr" });
|
||||
questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { Id = 7, QuestionId = 1, QuestionText = "Puedes abrir ?", Language = "sp" });
|
||||
questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { Id = 8, QuestionId = 2, QuestionText = "¿Están inundados los terrenos?", Language = "sp" });
|
||||
questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { Id = 9, QuestionId = 3, QuestionText = "¿El acceso está bloqueado por inundaciones?", Language = "sp" });
|
||||
questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { Id = 7, QuestionId = 1, QuestionText = "Puedes abrir ?", Language = "es" });
|
||||
questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { Id = 8, QuestionId = 2, QuestionText = "¿Están inundados los terrenos?", Language = "es" });
|
||||
questionDbContext.QuestionsTranslations.Add(new Db.QuestionsTranslation() { Id = 9, QuestionId = 3, QuestionText = "¿El acceso está bloqueado por inundaciones?", Language = "es" });
|
||||
questionDbContext.SaveChanges();
|
||||
}
|
||||
if (!questionDbContext.Questions.Any())
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
questionDbContext.Questions.Add(new Db.Question() { Id = 1, QuestionTypeId = 2, SurveyId = 1, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, QuestionGroup = "group1", CategoryId = 1 });
|
||||
questionDbContext.Questions.Add(new Db.Question() { Id = 2, QuestionTypeId = 1, SurveyId = 1, QuestionNumber = 2, IsRequired = false, Comment = true, Key = false, QuestionGroup = "group1", CategoryId = 1 });
|
||||
questionDbContext.Questions.Add(new Db.Question() { Id = 3, QuestionTypeId = 1, SurveyId = 1, QuestionNumber = 3, IsRequired = true, Comment = false, Key = true, QuestionGroup = "group1", CategoryId = 2 });
|
||||
=======
|
||||
questionDbContext.Questions.Add(new Db.Question() { Id = 1, QuestionTypeId = 2, SurveyId = 1, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, CategoryId=1 });
|
||||
questionDbContext.Questions.Add(new Db.Question() { Id = 2, QuestionTypeId = 1, SurveyId = 1, QuestionNumber = 2, IsRequired = false, Comment = true, Key = false, CategoryId = 1 });
|
||||
questionDbContext.Questions.Add(new Db.Question() { Id = 3, QuestionTypeId = 1, SurveyId = 1, QuestionNumber = 3, IsRequired = true, Comment = false, Key = true, CategoryId = 2 });
|
||||
>>>>>>> cf3a04891b7b50d0a02ac9c8b9a78ccb9436c35c
|
||||
questionDbContext.SaveChanges();
|
||||
}
|
||||
if (!questionDbContext.QuestionTypes.Any())
|
||||
{
|
||||
questionDbContext.QuestionTypes.Add(new Db.QuestionType() { Id = 1, TypeText = "Text 1" });
|
||||
questionDbContext.QuestionTypes.Add(new Db.QuestionType() { Id = 2, TypeText = "Text 2" });
|
||||
questionDbContext.QuestionTypes.Add(new Db.QuestionType() { Id = 3, TypeText = "Text 3" });
|
||||
questionDbContext.QuestionTypes.Add(new Db.QuestionType() { Id = 4, TypeText = "Text 4" });
|
||||
questionDbContext.QuestionTypes.Add(new Db.QuestionType() { Id = 5, TypeText = "Text 5" });
|
||||
questionDbContext.QuestionTypes.Add(new Db.QuestionType() { Id = 1, TypeText = "RadioButton" });
|
||||
questionDbContext.QuestionTypes.Add(new Db.QuestionType() { Id = 2, TypeText = "CheckBox" });
|
||||
questionDbContext.QuestionTypes.Add(new Db.QuestionType() { Id = 3, TypeText = "TextBox" });
|
||||
questionDbContext.SaveChanges();
|
||||
}
|
||||
|
||||
if (!questionDbContext.QuestionCategories.Any())
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
questionDbContext.QuestionCategories.Add(new Db.QuestionCategory() { Id = 1, CategoryName = "Category 1", CategoryImage = "img1" });
|
||||
questionDbContext.QuestionCategories.Add(new Db.QuestionCategory() { Id = 2, CategoryName = "Category 2", CategoryImage = "img1" });
|
||||
questionDbContext.QuestionCategories.Add(new Db.QuestionCategory() { Id = 3, CategoryName = "Category 3", CategoryImage = "img1" });
|
||||
questionDbContext.QuestionCategories.Add(new Db.QuestionCategory() { Id = 4, CategoryName = "Category 4", CategoryImage = "img1" });
|
||||
questionDbContext.QuestionCategories.Add(new Db.QuestionCategory() { Id = 5, CategoryName = "Category 5", CategoryImage = "img1" });
|
||||
=======
|
||||
questionDbContext.QuestionCategories.Add(new Db.QuestionCategory() { Id = 1, CategoryName = "Flooding", CategoryImage= "https://example.com/images/img1.png" });
|
||||
questionDbContext.QuestionCategories.Add(new Db.QuestionCategory() { Id = 2, CategoryName = "Electrical", CategoryImage = "https://example.com/images/img2.png" });
|
||||
questionDbContext.QuestionCategories.Add(new Db.QuestionCategory() { Id = 3, CategoryName = "Structural", CategoryImage = "https://example.com/images/img3.png" });
|
||||
questionDbContext.QuestionCategories.Add(new Db.QuestionCategory() { Id = 4, CategoryName = "Utility", CategoryImage = "https://example.com/images/img4.png" });
|
||||
questionDbContext.QuestionCategories.Add(new Db.QuestionCategory() { Id = 5, CategoryName = "Debris", CategoryImage = "https://example.com/images/img5.png" });
|
||||
>>>>>>> cf3a04891b7b50d0a02ac9c8b9a78ccb9436c35c
|
||||
questionDbContext.SaveChanges();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user