forked from MDCPS/DamageAssessment_Backend
		
	Fix for Data seed issue,Url Correction for SurveyResponses
This commit is contained in:
		| @ -6,7 +6,7 @@ using Microsoft.Extensions.Configuration; | ||||
|  | ||||
| namespace DamageAssesment.Api.SurveyResponses.Controllers | ||||
| { | ||||
|     //[Route("api")] | ||||
|     [Route("Responses")] | ||||
|     [ApiController] | ||||
|     public class SurveyResponsesController : ControllerBase | ||||
|     { | ||||
| @ -20,7 +20,7 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers | ||||
|         /// GET request for retrieving survey responses. | ||||
|         /// </summary> | ||||
|  | ||||
|         [HttpGet("SurveyResponses")] | ||||
|         [HttpGet] | ||||
|         public async Task<ActionResult> GetSurveyResponsesAsync() | ||||
|         { | ||||
|             var result = await this.surveyResponseProvider.GetSurveyResponsesAsync(); | ||||
| @ -38,7 +38,7 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers | ||||
|         /// GET request for retrieving survey responses by survey ID. | ||||
|         /// </summary> | ||||
|         | ||||
|         [HttpGet("SurveyResponses/{surveyId}")] | ||||
|         [HttpGet("{surveyId}")] | ||||
|         public async Task<ActionResult> GetSurveyResponsesAsync(int surveyId) | ||||
|         { | ||||
|             var result = await this.surveyResponseProvider.GetSurveyResponsesBySurveyAsync(surveyId); | ||||
| @ -54,7 +54,7 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers | ||||
|         /// <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("{surveyId}/{locationId}")] | ||||
|         public async Task<ActionResult> GetSurveyResponsesBySurveyAndLocationAsync(int surveyId, string locationId) | ||||
|         { | ||||
|             var result = await this.surveyResponseProvider.GetSurveyResponsesBySurveyAndLocationAsync(surveyId, locationId); | ||||
| @ -72,7 +72,7 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers | ||||
|         /// <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("ByAnswers/{surveyId}/{questionId}/{answer}")] | ||||
|         public async Task<ActionResult> GetSurveyResponsesByAnswerAsyncAsync(int surveyId, int questionId, string answer) | ||||
|         {        | ||||
|             var result = await surveyResponseProvider.GetResponsesByAnswerAsync(surveyId, questionId, answer); | ||||
| @ -88,7 +88,7 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers | ||||
|         /// </summary> | ||||
|         /// <param name="surveyId">The ID of the survey for which answers are to be retrieved.</param> | ||||
|  | ||||
|         [HttpGet("AnswersByRegion/{surveyId}")] | ||||
|         [HttpGet("ByRegion/{surveyId}")] | ||||
|         public async Task<ActionResult> GetAnswersByRegionAsync(int surveyId) | ||||
|         { | ||||
|             var result = await this.surveyResponseProvider.GetAnswersByRegionAsync(surveyId); | ||||
| @ -103,7 +103,7 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers | ||||
|         /// </summary> | ||||
|         /// <param name="surveyId">The ID of the survey for which responses are to be retrieved.</param> | ||||
|  | ||||
|         [HttpGet("AnswersByMaintenanceCenter/{surveyId}")] | ||||
|         [HttpGet("ByMaintenanceCenter/{surveyId}")] | ||||
|         public async Task<ActionResult> GetAnswersByMaintenaceCentersync(int surveyId) | ||||
|         { | ||||
|             var result = await this.surveyResponseProvider.GetSurveyResponsesByMaintenanceCenterAsync(surveyId); | ||||
| @ -118,7 +118,7 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers | ||||
|         /// </summary> | ||||
|         /// <param name="responseId">The ID of the survey response to be retrieved.</param> | ||||
|  | ||||
|         [HttpGet("SurveyResponse/{responseId}")] | ||||
|         [HttpGet("{responseId}")] | ||||
|         public async Task<ActionResult> GetSurveyResponseByIdAsync(int responseId) | ||||
|         { | ||||
|             var result = await this.surveyResponseProvider.GetSurveyResponseByIdAsync(responseId); | ||||
| @ -134,7 +134,7 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers | ||||
|         /// </summary> | ||||
|         /// <param name="surveyResponse">The survey response object to be created.</param> | ||||
|  | ||||
|         [HttpPost("SurveyResponses")] | ||||
|         [HttpPost] | ||||
|         public async Task<ActionResult> PostSurveysAsync(Models.SurveyResponse surveyResponse) | ||||
|         { | ||||
|             var result = await this.surveyResponseProvider.PostSurveyResponseAsync(surveyResponse); | ||||
| @ -150,7 +150,7 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers | ||||
|         /// <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("{Id}")] | ||||
|         public async Task<ActionResult> PutSurveyResponseAsync(int Id, Models.SurveyResponse surveyResponse) | ||||
|         { | ||||
|             var result = await this.surveyResponseProvider.PutSurveyResponseAsync(Id, surveyResponse); | ||||
| @ -167,7 +167,7 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers | ||||
|         /// DELETE request for deleting an existing survey response. | ||||
|         /// </summary> | ||||
|         | ||||
|         [HttpDelete("SurveyResponses/{Id}")] | ||||
|         [HttpDelete("{Id}")] | ||||
|         public async Task<ActionResult> DeleteSurveyResponseAsync(int Id) | ||||
|         { | ||||
|             var result = await this.surveyResponseProvider.DeleteSurveyResponseAsync(Id); | ||||
| @ -182,7 +182,7 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers | ||||
|         /// </summary> | ||||
|         /// <param name="request">The answers to be submitted for the survey.</param> | ||||
|  | ||||
|         [HttpPost("SurveyResponses/Answers")] | ||||
|         [HttpPost("Answers")] | ||||
|         public async Task<ActionResult> PostSurveyAnswersAsync(Request request) | ||||
|         { | ||||
|             /* var result = await this.surveyResponseProvider.PostSurveyAnswersAsync(surveyAnswers); | ||||
|  | ||||
| @ -70,7 +70,12 @@ var app = builder.Build(); | ||||
| if (app.Environment.IsDevelopment()) | ||||
| { | ||||
|     app.UseSwagger(); | ||||
|     app.UseSwaggerUI(options => { options.SwaggerEndpoint("/surveyresponses/swagger/v1/swagger.json", ""); }); | ||||
|     app.UseSwaggerUI(options => {  | ||||
|         //switch for local environment | ||||
|         options.SwaggerEndpoint("/swagger/v1/swagger.json", "");  | ||||
|        // options.SwaggerEndpoint("/surveyresponses/swagger/v1/swagger.json", "");  | ||||
|      | ||||
|     }); | ||||
| } | ||||
|  | ||||
| app.UseAuthorization(); | ||||
|  | ||||
| @ -29,13 +29,13 @@ namespace DamageAssesment.Api.SurveyResponses.Providers | ||||
|                 var answers = JsonConvert.DeserializeObject<List<Answer>>(responseString); | ||||
|  | ||||
|                 if (answers == null || !answers.Any()) | ||||
|                     return null; | ||||
|                     return new List<Answer>(); | ||||
|                 else return answers; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger?.LogError($"Exception Found : {ex.Message} - Ref: AnswerServiceProvider.getAnswersAsync()"); | ||||
|                 return null; | ||||
|                 return new List<Answer>(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @ -45,19 +45,19 @@ namespace DamageAssesment.Api.SurveyResponses.Providers | ||||
|             { | ||||
|                 httpClient.BaseAddress = new Uri(urlBase); | ||||
|  | ||||
|                 var response = await httpClient.GetAsync("/api/AnswersByResponse/" + responseId); | ||||
|                 var response = await httpClient.GetAsync("/AnswersByResponse/" + responseId); | ||||
|                 response.EnsureSuccessStatusCode(); | ||||
|                 var responseString = await response.Content.ReadAsStringAsync(); | ||||
|                 var answers = JsonConvert.DeserializeObject<List<Answer>>(responseString); | ||||
|  | ||||
|                 if (answers == null || !answers.Any()) | ||||
|                     return null; | ||||
|                     return new List<Answer>(); | ||||
|                 else return answers; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger?.LogError($"Exception Found : {ex.Message} - Ref: AnswerServiceProvider.GetAnswersByResponseId()"); | ||||
|                 return null; | ||||
|                 return new List<Answer>();  | ||||
|             } | ||||
|         } | ||||
|  | ||||
|  | ||||
| @ -12,7 +12,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers | ||||
| { | ||||
|     public class AttachmentServiceProvider : ServiceProviderBase, IAttachmentServiceProvider | ||||
|     { | ||||
|         public AttachmentServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<AttachmentServiceProvider> logger) : base(configuration, httpClient, logger, "/api/Attachments", configuration.GetValue<string>("EndPointSettings:AttachmentUrlBase")) | ||||
|         public AttachmentServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<AttachmentServiceProvider> logger) : base(configuration, httpClient, logger, "/Attachments", configuration.GetValue<string>("EndPointSettings:AttachmentUrlBase")) | ||||
|         { | ||||
|         } | ||||
|  | ||||
| @ -27,13 +27,13 @@ namespace DamageAssesment.Api.SurveyResponses.Providers | ||||
|                 var attachments = JsonConvert.DeserializeObject<List<Attachment>>(responseString); | ||||
|  | ||||
|                 if (attachments == null || !attachments.Any()) | ||||
|                     return null; | ||||
|                     return new List<Attachment>(); | ||||
|                 else return attachments; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger?.LogError($"Exception Found : {ex.Message} - Ref: AttachmentServiceProvider.getAttachmentsAsync()"); | ||||
|                 return null; | ||||
|                 return new List<Attachment>();  | ||||
|             } | ||||
|         } | ||||
|  | ||||
|  | ||||
| @ -8,7 +8,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers | ||||
| { | ||||
|     public class EmployeeServiceProvider :ServiceProviderBase, IEmployeeServiceProvider | ||||
|     { | ||||
|         public EmployeeServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<EmployeeServiceProvider> logger) : base(configuration, httpClient, logger, "/api/Employees", configuration.GetValue<string>("EndPointSettings:EmployeeUrlBase")) | ||||
|         public EmployeeServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<EmployeeServiceProvider> logger) : base(configuration, httpClient, logger, "/Employees", configuration.GetValue<string>("EndPointSettings:EmployeeUrlBase")) | ||||
|         { | ||||
|         } | ||||
|  | ||||
| @ -23,13 +23,13 @@ namespace DamageAssesment.Api.SurveyResponses.Providers | ||||
|                 var employees = JsonConvert.DeserializeObject<List<Employee>>(responseString); | ||||
|  | ||||
|                 if (employees == null || !employees.Any()) | ||||
|                     return null; | ||||
|                     return new List<Employee>(); | ||||
|                 else return employees; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger?.LogError($"Exception Found : {ex.Message} - Ref: EmployeeServiceProvider.getEmployeesAsync()"); | ||||
|                 return null; | ||||
|                 return new List<Employee>(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @ -39,7 +39,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers | ||||
|             { | ||||
|                 httpClient.BaseAddress = new Uri(urlBase); | ||||
|                 //ressource = ressource + "/" + employeeID; | ||||
|                 var response = await httpClient.GetAsync("/api/Employees/"+ employeeID); | ||||
|                 var response = await httpClient.GetAsync("/Employees/"+ employeeID); | ||||
|                 response.EnsureSuccessStatusCode(); | ||||
|                 var responseString = await response.Content.ReadAsStringAsync(); | ||||
|                 var employee = JsonConvert.DeserializeObject<Employee>(responseString); | ||||
|  | ||||
| @ -7,7 +7,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers | ||||
| { | ||||
|     public class LocationServiceProvider :ServiceProviderBase, ILocationServiceProvider | ||||
|     { | ||||
|         public LocationServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<LocationServiceProvider> logger) : base(configuration, httpClient, logger, "/api/Locations", configuration.GetValue<string>("EndPointSettings:LocationUrlBase")) | ||||
|         public LocationServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<LocationServiceProvider> logger) : base(configuration, httpClient, logger, "/Locations", configuration.GetValue<string>("EndPointSettings:LocationUrlBase")) | ||||
|         { | ||||
|         } | ||||
|  | ||||
| @ -22,13 +22,13 @@ namespace DamageAssesment.Api.SurveyResponses.Providers | ||||
|                 var locations = JsonConvert.DeserializeObject<List<Location>>(responseString); | ||||
|  | ||||
|                 if (locations == null || !locations.Any()) | ||||
|                     return null; | ||||
|                     return new List<Location>(); | ||||
|                 else return locations; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger?.LogError($"Exception Found : {ex.Message} - Ref: LocationServiceProvider.getLocationsAsync()"); | ||||
|                 return null; | ||||
|                 return new List<Location>(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -9,7 +9,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers | ||||
| { | ||||
|     public class QuestionServiceProvider : ServiceProviderBase, IQuestionServiceProvider | ||||
|     { | ||||
|         public QuestionServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<QuestionServiceProvider> logger) : base(configuration, httpClient, logger, "/api/Questions", configuration.GetValue<string>("EndPointSettings:QuestionUrlBase")) | ||||
|         public QuestionServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<QuestionServiceProvider> logger) : base(configuration, httpClient, logger, "/Questions", configuration.GetValue<string>("EndPointSettings:QuestionUrlBase")) | ||||
|         { | ||||
|         } | ||||
|  | ||||
| @ -24,13 +24,13 @@ namespace DamageAssesment.Api.SurveyResponses.Providers | ||||
|                 var questions = JsonConvert.DeserializeObject<List<Question>>(responseString); | ||||
|  | ||||
|                 if (questions == null || !questions.Any()) | ||||
|                     return null; | ||||
|                     return new List<Question>(); | ||||
|                 else return questions; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger?.LogError($"Exception Found : {ex.Message} - Ref: QuestionServiceProvider.getQuestionsAsync()"); | ||||
|                 return null; | ||||
|                 return new List<Question>(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @ -39,19 +39,19 @@ namespace DamageAssesment.Api.SurveyResponses.Providers | ||||
|             try | ||||
|             { | ||||
|                 httpClient.BaseAddress = new Uri(urlBase); | ||||
|                 var response = await httpClient.GetAsync("/api/GetSurveyQuestions/" + surveyId); | ||||
|                 var response = await httpClient.GetAsync("/GetSurveyQuestions/" + surveyId); | ||||
|                 response.EnsureSuccessStatusCode(); | ||||
|                 var responseString = await response.Content.ReadAsStringAsync(); | ||||
|                 var questions = JsonConvert.DeserializeObject<List<SurveyQuestions>>(responseString); | ||||
|  | ||||
|                 if (questions == null || !questions.Any()) | ||||
|                     return null; | ||||
|                     return new List<SurveyQuestions>(); | ||||
|                 else return questions; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger?.LogError($"Exception Found : {ex.Message} - Ref: QuestionServiceProvider.getSurveyQuestionsAsync()"); | ||||
|                 return null; | ||||
|                 return new List<SurveyQuestions>(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|  | ||||
| @ -7,7 +7,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers | ||||
| { | ||||
|     public class RegionServiceProvider : ServiceProviderBase, IRegionServiceProvider | ||||
|     { | ||||
|         public RegionServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<RegionServiceProvider> logger) : base(configuration, httpClient, logger, "/api/Regions", configuration.GetValue<string>("EndPointSettings:LocationUrlBase")) | ||||
|         public RegionServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<RegionServiceProvider> logger) : base(configuration, httpClient, logger, "/Regions", configuration.GetValue<string>("EndPointSettings:LocationUrlBase")) | ||||
|         { | ||||
|         } | ||||
|         public async Task<List<Region>> getRegionsAsync() | ||||
| @ -21,13 +21,13 @@ namespace DamageAssesment.Api.SurveyResponses.Providers | ||||
|                 var regions = JsonConvert.DeserializeObject<List<Region>>(responseString); | ||||
|  | ||||
|                 if (regions == null || !regions.Any()) | ||||
|                     return null; | ||||
|                     return new List<Region>(); | ||||
|                 else return regions; | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 logger?.LogError($"Exception Found : {ex.Message} - Ref: RegionServiceProvider.getRegionsAsync()"); | ||||
|                 return null; | ||||
|                 return new List<Region>(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -37,7 +37,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers | ||||
|             this.surveyServiceProvider = surveyServiceProvider; | ||||
|             this.mapper = mapper; | ||||
|  | ||||
|             seedData(); | ||||
|             //seedData(); | ||||
|         } | ||||
|  | ||||
|         private void seedData() | ||||
|  | ||||
| @ -8,7 +8,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers | ||||
| { | ||||
|     public class SurveyServiceProvider :ServiceProviderBase, ISurveyServiceProvider | ||||
|     { | ||||
|         public SurveyServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<EmployeeServiceProvider> logger) : base(configuration, httpClient, logger, "/api/Surveys", configuration.GetValue<string>("EndPointSettings:SurveyUrlBase")) | ||||
|         public SurveyServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<EmployeeServiceProvider> logger) : base(configuration, httpClient, logger, "/Surveys", configuration.GetValue<string>("EndPointSettings:SurveyUrlBase")) | ||||
|         { | ||||
|         } | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user