From fe1614fee327b52f8e37e336213e7aba5a1b5d18 Mon Sep 17 00:00:00 2001 From: Reginald Cherenfant Jasmin Date: Fri, 25 Aug 2023 11:36:31 -0400 Subject: [PATCH] Multi Language support --- .../AnswersServiceTest.cs | 20 +++++----- .../AttachmentsServiceTest.cs | 16 ++++---- .../Controllers/QuestionsController.cs | 40 ++++++------------- .../Providers/QuestionsProvider.cs | 19 --------- .../MockData.cs | 11 +---- .../Controllers/SurveysController.cs | 24 +++-------- .../DamageAssesment.Api.Surveys/Db/Survey.cs | 4 +- .../Models/Survey.cs | 4 +- .../DamageAssesment.Api.Surveys/Program.cs | 3 -- 9 files changed, 42 insertions(+), 99 deletions(-) diff --git a/DamageAssesmentApi/DamageAssesment.Api.Answers.Test/AnswersServiceTest.cs b/DamageAssesmentApi/DamageAssesment.Api.Answers.Test/AnswersServiceTest.cs index 3b114f7..ad6ec72 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Answers.Test/AnswersServiceTest.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Answers.Test/AnswersServiceTest.cs @@ -95,10 +95,10 @@ namespace DamageAssesment.Api.Answers.Test var mockAnswerService = new Mock(); 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(); 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(); 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(); 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(); 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); } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Attachments.Test/AttachmentsServiceTest.cs b/DamageAssesmentApi/DamageAssesment.Api.Attachments.Test/AttachmentsServiceTest.cs index 5bf695c..6b65c79 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Attachments.Test/AttachmentsServiceTest.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Attachments.Test/AttachmentsServiceTest.cs @@ -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(); 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(); 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); } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Controllers/QuestionsController.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Controllers/QuestionsController.cs index 7c0ba52..ae98924 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/Controllers/QuestionsController.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Controllers/QuestionsController.cs @@ -15,20 +15,16 @@ namespace DamageAssesment.Api.Questions.Controllers this.questionsProvider = questionsProvider; } -<<<<<<< HEAD + + /// + /// GET request for retrieving questions. + /// + // get all questions [Route("{Language}/Questions")] [Route("Questions")] [HttpGet] public async Task GetQuestionsAsync(string? Language) -======= - /// - /// GET request for retrieving questions. - /// - - [HttpGet("Questions")] - public async Task 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 + /// + /// GET request for retrieving a question by ID. + /// [Route("{Language}/Questions/{id}")] [Route("Questions/{id}")] [HttpGet] public async Task GetQuestionAsync(int id, string? Language) -======= - /// - /// GET request for retrieving a question by ID. - /// - - [HttpGet("Questions/{id}")] - public async Task 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] -======= /// /// GET request for retrieving survey questions based on a survey ID. /// Uri: {Optional language}/GetSurveyQuestions/{surveyId} :Default returns question in all languages /// - - [HttpGet("GetSurveyQuestions/{surveyId}")] ->>>>>>> cf3a04891b7b50d0a02ac9c8b9a78ccb9436c35c + [Route("{Language}/GetSurveyQuestions/{surveyId}")] + [Route("GetSurveyQuestions/{surveyId}")] + [HttpGet] public async Task GetSurveyQuestions(int surveyId,string? Language) { var result = await this.questionsProvider.GetSurveyQuestionAsync(surveyId, Language); @@ -135,7 +122,6 @@ namespace DamageAssesment.Api.Questions.Controllers return NotFound(); } - /// /// GET request for retrieving question categories. /// diff --git a/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs b/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs index 7baea60..719fb5f 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Questions/Providers/QuestionsProvider.cs @@ -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 Questions, string ErrorMessage)> GetQuestionsAsync(string Language) @@ -273,8 +256,6 @@ namespace DamageAssesment.Api.Questions.Providers } } - - //Question Category Logic public async Task<(bool IsSuccess, IEnumerable QuestionCategories, string ErrorMessage)> GetQuestionCategoriesAsync() diff --git a/DamageAssesmentApi/DamageAssesment.Api.QuestionsTest/MockData.cs b/DamageAssesmentApi/DamageAssesment.Api.QuestionsTest/MockData.cs index be919ed..1991128 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.QuestionsTest/MockData.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.QuestionsTest/MockData.cs @@ -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 question = new List(); - 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, diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Controllers/SurveysController.cs b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Controllers/SurveysController.cs index f98a3e0..e360e53 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Controllers/SurveysController.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Controllers/SurveysController.cs @@ -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. /// - [Route("Surveys")] [Route("{Language}/Surveys")] [HttpGet] @@ -32,20 +29,14 @@ namespace DamageAssesment.Api.Surveys.Controllers } return NoContent(); } -<<<<<<< HEAD + /// + /// GET request for retrieving surveys by ID. + /// [Route("Surveys/{Id}")] [Route("{Language}/Surveys/{Id}")] [HttpGet] public async Task GetSurveysAsync(int Id, string? Language) -======= - /// - /// GET request for retrieving surveys by ID. - /// - - [HttpGet("{Id}")] - public async Task GetSurveysAsync(int Id) ->>>>>>> cf3a04891b7b50d0a02ac9c8b9a78ccb9436c35c { var result = await this.surveyProvider.GetSurveysAsync(Id, Language); if (result.IsSuccess) @@ -71,7 +62,7 @@ namespace DamageAssesment.Api.Surveys.Controllers /// /// PUT request for updating an existing survey (surveyId,Updated Survey data). /// - + [HttpPut("Surveys/{Id}")] public async Task PutSurveysAsync(int Id, Models.Survey survey) @@ -86,16 +77,11 @@ namespace DamageAssesment.Api.Surveys.Controllers return BadRequest(result.ErrorMessage); } -<<<<<<< HEAD - [HttpDelete("Surveys/{Id}")] -======= /// /// DELETE request for deleting a survey by ID. /// - - [HttpDelete("{Id}")] ->>>>>>> cf3a04891b7b50d0a02ac9c8b9a78ccb9436c35c + [HttpDelete("Surveys/{Id}")] public async Task DeleteSurveysAsync(int Id) { var result = await this.surveyProvider.DeleteSurveyAsync(Id); diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Db/Survey.cs b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Db/Survey.cs index 36983bd..c031f57 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Db/Survey.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Db/Survey.cs @@ -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; /* diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Models/Survey.cs b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Models/Survey.cs index ab741b5..7fa898d 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Models/Survey.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Models/Survey.cs @@ -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 Titles { get; set; } } diff --git a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Program.cs b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Program.cs index 7368a72..98fa8a3 100644 --- a/DamageAssesmentApi/DamageAssesment.Api.Surveys/Program.cs +++ b/DamageAssesmentApi/DamageAssesment.Api.Surveys/Program.cs @@ -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);