Multi Language support

This commit is contained in:
Reginald Cherenfant Jasmin 2023-08-25 11:36:31 -04:00
parent 448950ea27
commit fe1614fee3
9 changed files with 42 additions and 99 deletions

View File

@ -95,10 +95,10 @@ namespace DamageAssesment.Api.Answers.Test
var mockAnswerService = new Mock<IAnswersProvider>();
var mockResponse = await MockData.getOkResponse(1);
var mockInputAnswer = await MockData.getInputAnswerData();
mockAnswerService.Setup(service => service.PostAnswerAsync(mockInputAnswer)).ReturnsAsync(mockResponse);
mockAnswerService.Setup(service => service.PostAnswerAsync(mockInputAnswer)).Returns(mockResponse);
var AnswerProvider = new AnswersController(mockAnswerService.Object);
var result = (OkObjectResult)await AnswerProvider.CreateAnswer(mockInputAnswer);
var result = (OkObjectResult) AnswerProvider.CreateAnswer(mockInputAnswer);
Assert.Equal(200, result.StatusCode);
}
@ -109,10 +109,10 @@ namespace DamageAssesment.Api.Answers.Test
var mockAnswerService = new Mock<IAnswersProvider>();
var mockInputAnswer = await MockData.getInputAnswerData();
var mockResponse = await MockData.getBadRequestResponse();
mockAnswerService.Setup(service => service.PostAnswerAsync(mockInputAnswer)).ReturnsAsync(mockResponse);
mockAnswerService.Setup(service => service.PostAnswerAsync(mockInputAnswer)).Returns(mockResponse);
var AnswerProvider = new AnswersController(mockAnswerService.Object);
var result = (BadRequestObjectResult)await AnswerProvider.CreateAnswer(mockInputAnswer);
var result = (BadRequestObjectResult) AnswerProvider.CreateAnswer(mockInputAnswer);
Assert.Equal(400, result.StatusCode);
}
@ -123,10 +123,10 @@ namespace DamageAssesment.Api.Answers.Test
var mockAnswerService = new Mock<IAnswersProvider>();
var mockResponse = await MockData.getOkResponse(1);
var mockInputAnswer = await MockData.getInputAnswerData();
mockAnswerService.Setup(service => service.UpdateAnswerAsync(mockInputAnswer)).ReturnsAsync(mockResponse);
mockAnswerService.Setup(service => service.UpdateAnswerAsync(mockInputAnswer)).Returns(mockResponse);
var AnswerProvider = new AnswersController(mockAnswerService.Object);
var result = (OkObjectResult)await AnswerProvider.UpdateAnswer(mockInputAnswer);
var result = (OkObjectResult) AnswerProvider.UpdateAnswer(mockInputAnswer);
Assert.Equal(200, result.StatusCode);
}
@ -137,10 +137,10 @@ namespace DamageAssesment.Api.Answers.Test
var mockAnswerService = new Mock<IAnswersProvider>();
var mockResponse = await MockData.getNotFoundResponse();
var mockInputAnswer = await MockData.getInputAnswerData();
mockAnswerService.Setup(service => service.UpdateAnswerAsync(mockInputAnswer)).ReturnsAsync(mockResponse);
mockAnswerService.Setup(service => service.UpdateAnswerAsync(mockInputAnswer)).Returns(mockResponse);
var AnswerProvider = new AnswersController(mockAnswerService.Object);
var result = (NotFoundObjectResult)await AnswerProvider.UpdateAnswer(mockInputAnswer);
var result = (NotFoundObjectResult) AnswerProvider.UpdateAnswer(mockInputAnswer);
Assert.Equal(404, result.StatusCode);
}
@ -151,10 +151,10 @@ namespace DamageAssesment.Api.Answers.Test
var mockAnswerService = new Mock<IAnswersProvider>();
var mockResponse = await MockData.getBadRequestResponse();
var mockInputAnswer = await MockData.getInputAnswerData();
mockAnswerService.Setup(service => service.UpdateAnswerAsync(mockInputAnswer)).ReturnsAsync(mockResponse);
mockAnswerService.Setup(service => service.UpdateAnswerAsync(mockInputAnswer)).Returns(mockResponse);
var AnswerProvider = new AnswersController(mockAnswerService.Object);
var result = (BadRequestObjectResult)await AnswerProvider.UpdateAnswer(mockInputAnswer);
var result = (BadRequestObjectResult) AnswerProvider.UpdateAnswer(mockInputAnswer);
Assert.Equal(400, result.StatusCode);
}

View File

@ -77,10 +77,10 @@ namespace DamageAssesment.Api.Attachments.Test
var mockResponse = await MockData.getOkResponse();
var AttachmentResponse = await MockData.GetAttachmentInfo(0);
var mockInputAttachment = await MockData.getInputAttachmentData();
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse);
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).Returns(mockResponse);
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
var result = (NoContentResult)await AttachmentProvider.UploadAttachmentAsync(AttachmentResponse);
var result = (NoContentResult) AttachmentProvider.UploadAttachmentAsync(AttachmentResponse);
Assert.Equal(204, result.StatusCode);
}
@ -92,11 +92,11 @@ namespace DamageAssesment.Api.Attachments.Test
var mockUploadService = new Mock<IUploadService>();
var mockInputAttachment = await MockData.getInputAttachmentData();
var mockResponse = await MockData.getBadRequestResponse();
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse);
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).Returns(mockResponse);
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
AttachmentInfo attachmentInfo=new AttachmentInfo();
var result = (BadRequestObjectResult)await AttachmentProvider.UploadAttachmentAsync(attachmentInfo);
var result = (BadRequestObjectResult) AttachmentProvider.UploadAttachmentAsync(attachmentInfo);
Assert.Equal(400, result.StatusCode);
}
@ -109,10 +109,10 @@ namespace DamageAssesment.Api.Attachments.Test
var mockResponse = await MockData.getOkResponse();
var AttachmentResponse = await MockData.GetAttachmentInfo(1);
var mockInputAttachment = await MockData.getInputAttachmentData();
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse);
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).Returns(mockResponse);
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
var result = (NoContentResult)await AttachmentProvider.UpdateAttachmentAsync(AttachmentResponse);
var result = (NoContentResult) AttachmentProvider.UpdateAttachmentAsync(AttachmentResponse);
Assert.Equal(204, result.StatusCode);
}
@ -124,11 +124,11 @@ namespace DamageAssesment.Api.Attachments.Test
var mockUploadService = new Mock<IUploadService>();
var mockInputAttachment = await MockData.getInputAttachmentData();
var mockResponse = await MockData.getBadRequestResponse();
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).ReturnsAsync(mockResponse);
mockAttachmentService.Setup(service => service.PostAttachmentAsync(mockInputAttachment)).Returns(mockResponse);
var AttachmentProvider = new AttachmentsController(mockAttachmentService.Object, mockUploadService.Object);
AttachmentInfo attachmentInfo = new AttachmentInfo();
var result = (BadRequestObjectResult)await AttachmentProvider.UpdateAttachmentAsync(attachmentInfo);
var result = (BadRequestObjectResult) AttachmentProvider.UpdateAttachmentAsync(attachmentInfo);
Assert.Equal(400, result.StatusCode);
}

View File

@ -15,20 +15,16 @@ namespace DamageAssesment.Api.Questions.Controllers
this.questionsProvider = questionsProvider;
}
<<<<<<< HEAD
/// <summary>
/// GET request for retrieving questions.
/// </summary>
// 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)
@ -37,20 +33,15 @@ namespace DamageAssesment.Api.Questions.Controllers
}
return NoContent();
}
<<<<<<< HEAD
//Get questions based on question id
/// <summary>
/// GET request for retrieving a question by ID.
/// </summary>
[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)
@ -59,19 +50,15 @@ 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
[Route("{Language}/GetSurveyQuestions/{surveyId}")]
[Route("GetSurveyQuestions/{surveyId}")]
[HttpGet]
public async Task<IActionResult> GetSurveyQuestions(int surveyId,string? Language)
{
var result = await this.questionsProvider.GetSurveyQuestionAsync(surveyId, Language);
@ -135,7 +122,6 @@ namespace DamageAssesment.Api.Questions.Controllers
return NotFound();
}
/// <summary>
/// GET request for retrieving question categories.
/// </summary>

View File

@ -24,8 +24,6 @@ namespace DamageAssesment.Api.Questions.Providers
SeedData();
}
private void SeedData()
{
@ -44,15 +42,9 @@ namespace DamageAssesment.Api.Questions.Providers
}
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())
@ -65,22 +57,13 @@ namespace DamageAssesment.Api.Questions.Providers
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();
}
}
public async Task<(bool IsSuccess, IEnumerable<Models.Question> Questions, string ErrorMessage)> GetQuestionsAsync(string Language)
@ -273,8 +256,6 @@ namespace DamageAssesment.Api.Questions.Providers
}
}
//Question Category Logic
public async Task<(bool IsSuccess, IEnumerable<Models.QuestionCategory> QuestionCategories, string ErrorMessage)> GetQuestionCategoriesAsync()

View File

@ -1,11 +1,4 @@
using DamageAssesment.Api.Questions.Db;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text;
namespace DamageAssesment.Api.Questions.Test
{
@ -31,7 +24,7 @@ namespace DamageAssesment.Api.Questions.Test
for (int i = 0; i < 10; i++)
{
List<Models.Question> question = new List<Models.Question>();
question.Add(new Models.Question { Id = i, TypeText = "Text" + i, SurveyId = 1, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, QuestionGroup = "group1", CategoryId = i });
question.Add(new Models.Question { Id = i, TypeText = "Text" + i, SurveyId = 1, QuestionNumber = 1, IsRequired = true, Comment = false, Key = true, CategoryId = i });
list.Append(new Questions.Models.SurveyQuestions
{
CategoryId = i,

View File

@ -1,6 +1,4 @@
using DamageAssesment.Api.Surveys.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace DamageAssesment.Api.Surveys.Controllers
@ -19,7 +17,6 @@ namespace DamageAssesment.Api.Surveys.Controllers
/// GET request for retrieving surveys.
/// </summary>
[Route("Surveys")]
[Route("{Language}/Surveys")]
[HttpGet]
@ -32,20 +29,14 @@ namespace DamageAssesment.Api.Surveys.Controllers
}
return NoContent();
}
<<<<<<< HEAD
/// <summary>
/// GET request for retrieving surveys by ID.
/// </summary>
[Route("Surveys/{Id}")]
[Route("{Language}/Surveys/{Id}")]
[HttpGet]
public async Task<ActionResult> GetSurveysAsync(int Id, string? Language)
=======
/// <summary>
/// GET request for retrieving surveys by ID.
/// </summary>
[HttpGet("{Id}")]
public async Task<ActionResult> GetSurveysAsync(int Id)
>>>>>>> cf3a04891b7b50d0a02ac9c8b9a78ccb9436c35c
{
var result = await this.surveyProvider.GetSurveysAsync(Id, Language);
if (result.IsSuccess)
@ -71,7 +62,7 @@ namespace DamageAssesment.Api.Surveys.Controllers
/// <summary>
/// PUT request for updating an existing survey (surveyId,Updated Survey data).
/// </summary>
[HttpPut("Surveys/{Id}")]
public async Task<ActionResult> PutSurveysAsync(int Id, Models.Survey survey)
@ -86,16 +77,11 @@ namespace DamageAssesment.Api.Surveys.Controllers
return BadRequest(result.ErrorMessage);
}
<<<<<<< HEAD
[HttpDelete("Surveys/{Id}")]
=======
/// <summary>
/// DELETE request for deleting a survey by ID.
/// </summary>
[HttpDelete("{Id}")]
>>>>>>> cf3a04891b7b50d0a02ac9c8b9a78ccb9436c35c
[HttpDelete("Surveys/{Id}")]
public async Task<ActionResult> DeleteSurveysAsync(int Id)
{
var result = await this.surveyProvider.DeleteSurveyAsync(Id);

View File

@ -12,9 +12,9 @@ namespace DamageAssesment.Api.Surveys.Db
public bool IsEnabled { get; set; }
public DateTime? StartDate { get; set; }
public DateTime StartDate { get; set; }
public DateTime? EndDate { get; set; }
public DateTime EndDate { get; set; }
public DateTime CreatedDate { get; set; } = DateTime.Now;
/*

View File

@ -6,8 +6,8 @@ namespace DamageAssesment.Api.Surveys.Models
{
public int Id { get; set; }
public bool IsEnabled { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public DateTime CreatedDate { get; set; }
public IEnumerable<SurveyTranslation> Titles { get; set; }
}

View File

@ -3,12 +3,9 @@ using DamageAssesment.Api.Surveys.Interfaces;
using DamageAssesment.Api.Surveys.Providers;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.EntityFrameworkCore;
<<<<<<< HEAD
using Microsoft.IdentityModel.Tokens;
using System.Text;
=======
using System.Reflection;
>>>>>>> cf3a04891b7b50d0a02ac9c8b9a78ccb9436c35c
var builder = WebApplication.CreateBuilder(args);