Fix for Data seed issue,Url Correction for SurveyResponses

This commit is contained in:
Santhosh S 2023-09-04 15:40:10 -04:00
parent af004ce565
commit a52f6e0cf9
30 changed files with 146 additions and 76 deletions

View File

@ -9,5 +9,6 @@
Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> PostAnswerAsync(Models.Answer Answer);
Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> UpdateAnswerAsync(Models.Answer Answer);
Task<(bool IsSuccess, Models.Answer Answer, string ErrorMessage)> DeleteAnswerAsync(int Id);
void SeedData();
}
}

View File

@ -35,12 +35,21 @@ var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(options =>
using (var serviceScope = app.Services.CreateScope())
{
var services = serviceScope.ServiceProvider;
var surveyProvider = services.GetRequiredService<IAnswersProvider>();
surveyProvider.SeedData();
}
app.UseSwagger();
app.UseSwaggerUI(
options =>
{
//switch for local environment
//options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
options.SwaggerEndpoint("/answers/swagger/v1/swagger.json","" );
});
} );
}
app.UseAuthorization();

View File

@ -18,7 +18,7 @@ namespace DamageAssesment.Api.Answers.Providers
this.answerDbContext = answerDbContext;
this.logger = logger;
this.mapper = mapper;
SeedData();
//SeedData();
}
public async Task<(bool IsSuccess, IEnumerable<Models.Answer> Answers, string ErrorMessage)> GetAnswersAsync()
@ -188,7 +188,7 @@ namespace DamageAssesment.Api.Answers.Providers
return answerDbContext.Answers.AsNoTracking().Count(e => e.Id == id) > 0;
}
private void SeedData()
public void SeedData()
{
if (!answerDbContext.Answers.Any())
{

View File

@ -42,7 +42,14 @@ var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(options => { options.SwaggerEndpoint("/attachments/swagger/v1/swagger.json", ""); });
app.UseSwaggerUI(options => {
//switch for local environment
// options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
options.SwaggerEndpoint("/attachments/swagger/v1/swagger.json", "");
});
}
app.UseAuthorization();

View File

@ -7,5 +7,6 @@
Task<(bool IsSuccess, Models.Employee Employee, string ErrorMessage)> PostEmployeeAsync(Models.Employee Employee);
Task<(bool IsSuccess, Models.Employee Employee, string ErrorMessage)> UpdateEmployeeAsync(string Id, Models.Employee Employee);
Task<(bool IsSuccess, Models.Employee Employee, string ErrorMessage)> DeleteEmployeeAsync(string Id);
void SeedData();
}
}

View File

@ -32,11 +32,20 @@ var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
using (var serviceScope = app.Services.CreateScope())
{
var services = serviceScope.ServiceProvider;
var surveyProvider = services.GetRequiredService<IEmployeesProvider>();
surveyProvider.SeedData();
}
app.UseSwagger();
app.UseSwaggerUI(options =>
{
//switch for local environment
//options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
options.SwaggerEndpoint("/employees/swagger/v1/swagger.json", "");
// options.RoutePrefix = ""; // Serve Swagger UI at the root URL
});
}

View File

@ -19,7 +19,7 @@ namespace DamageAssesment.Api.Employees.Providers
this.EmployeeDbContext = EmployeeDbContext;
this.logger = logger;
this.mapper = mapper;
SeedData();
// SeedData();
}
public async Task<(bool IsSuccess, IEnumerable<Models.Employee> Employees, string ErrorMessage)> GetEmployeesAsync()
@ -145,7 +145,7 @@ namespace DamageAssesment.Api.Employees.Providers
return EmployeeDbContext.Employees.AsNoTracking().Count(e => e.Id.ToLower() == id.ToLower()) > 0;
}
private void SeedData()
public void SeedData()
{
if (!EmployeeDbContext.Employees.Any())
{

View File

@ -4,7 +4,8 @@ using Microsoft.AspNetCore.Mvc;
namespace DamageAssesment.Api.Locations.Controllers
{
//[Route("api")]
[Route("Locations")]
//[Route("[controller]")]
[ApiController]
public class LocationsController : ControllerBase
{
@ -18,7 +19,8 @@ namespace DamageAssesment.Api.Locations.Controllers
/// Get all locations.
/// </summary>
[HttpGet("Locations")]
//[HttpGet("locations")]
[HttpGet]
public async Task<ActionResult> GetLocationsAsync()
{
@ -34,7 +36,7 @@ namespace DamageAssesment.Api.Locations.Controllers
/// Get all locations based on locationdId.
/// </summary>
[HttpGet("Locations/{id}")]
[HttpGet("{id}")]
public async Task<ActionResult> GetLocationByIdAsync(string id)
{
@ -50,12 +52,12 @@ namespace DamageAssesment.Api.Locations.Controllers
/// Update a Location.
/// </summary>
[HttpPut("Locations")]
public async Task<IActionResult> UpdateLocation(Models.Location Location)
[HttpPut("{locations}")]
public async Task<IActionResult> UpdateLocation(Models.Location location)
{
if (Location != null)
if (location != null)
{
var result = await this.LocationProvider.UpdateLocationAsync(Location);
var result = await this.LocationProvider.UpdateLocationAsync(location);
if (result.IsSuccess)
{
return Ok(result.ErrorMessage);
@ -68,7 +70,7 @@ namespace DamageAssesment.Api.Locations.Controllers
/// Save a new location.
/// </summary>
[HttpPost("Locations")]
[HttpPost("{locations}")]
public async Task<IActionResult> CreateLocation(Models.Location Location)
{
if (Location != null)
@ -86,7 +88,7 @@ namespace DamageAssesment.Api.Locations.Controllers
/// Delete an existing location.
/// </summary>
[HttpDelete("Locations/{id}")]
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteLocation(string id)
{
var result = await this.LocationProvider.DeleteLocationAsync(id);

View File

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
namespace DamageAssesment.Api.Locations.Controllers
{
//[Route("api/[controller]")]
[Route("[controller]")]
[ApiController]
public class RegionsController : ControllerBase
{
@ -45,7 +46,7 @@ namespace DamageAssesment.Api.Locations.Controllers
/// POST request for creating a new region.
/// </summary>
[HttpPost]
[HttpPost("{region}")]
public async Task<ActionResult> PostRegionAsync(Models.Region region)
{
var result = await this.regionProvider.PostRegionAsync(region);
@ -59,7 +60,7 @@ namespace DamageAssesment.Api.Locations.Controllers
/// PUT request for updating an existing region.
/// </summary>
[HttpPut]
[HttpPut("{region}")]
public async Task<ActionResult> PutRegionAsync(Models.Region region)
{
var result = await this.regionProvider.PutRegionAsync(region);

View File

@ -9,5 +9,6 @@ namespace DamageAssesment.Api.Locations.Interfaces
Task<(bool IsSuccess, Models.Location Question, string ErrorMessage)> PostLocationAsync(Models.Location Location);
Task<(bool IsSuccess, string ErrorMessage)> UpdateLocationAsync(Models.Location Location);
Task<(bool IsSuccess, string ErrorMessage)> DeleteLocationAsync(string Id);
void SeedData();
}
}

View File

@ -7,5 +7,6 @@
Task<(bool IsSuccess, Models.Region Region, string ErrorMessage)> PostRegionAsync(Models.Region region);
Task<(bool IsSuccess, Models.Region Region, string ErrorMessage)> PutRegionAsync(Models.Region region);
Task<(bool IsSuccess, Models.Region Region, string ErrorMessage)> DeleteRegionAsync(string Id);
void SeedData();
}
}

View File

@ -31,10 +31,24 @@ var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
using (var serviceScope = app.Services.CreateScope())
{
var services = serviceScope.ServiceProvider;
var locationProvider = services.GetRequiredService<ILocationsProvider>();
var regionProvider = services.GetRequiredService<IRegionsProvider>();
locationProvider.SeedData();
regionProvider.SeedData();
}
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/locations/swagger/v1/swagger.json", "");
//switch for local environment
//options.SwaggerEndpoint("/swagger/v1/swagger.json","");
options.SwaggerEndpoint("locations/swagger/v1/swagger.json", "");
});
}

View File

@ -17,7 +17,7 @@ namespace DamageAssesment.Api.Locations.Providers
this.locationDbContext = locationDbContext;
this.logger = logger;
this.mapper = mapper;
SeedData();
//SeedData();
}
public async Task<(bool IsSuccess, IEnumerable<Models.Location> locations, string ErrorMessage)> GetLocationsAsync()
@ -127,7 +127,7 @@ namespace DamageAssesment.Api.Locations.Providers
{
return locationDbContext.Locations.AsNoTracking().Count(e => e.Id == id) > 0;
}
private void SeedData()
public void SeedData()
{
if (!locationDbContext.Locations.Any())
{

View File

@ -17,7 +17,7 @@ namespace DamageAssesment.Api.Locations.Providers
this.locationDbContext = regionDbContext;
this.logger = logger;
this.mapper = mapper;
SeedData();
// SeedData();
}
public async Task<(bool IsSuccess, Models.Region Region, string ErrorMessage)> GetRegionByIdAsync(string Id)
@ -150,7 +150,7 @@ namespace DamageAssesment.Api.Locations.Providers
}
}
private void SeedData()
public void SeedData()
{
if (!locationDbContext.Regions.Any())
{

View File

@ -4,5 +4,6 @@
{
Task<(bool IsSuccess, Db.QuestionType QuestionType, string ErrorMessage)> GetQuestionTypeAsync(int Id);
Task<(bool IsSuccess, IEnumerable<Db.QuestionType> QuestionTypes, string ErrorMessage)> GetQuestionTypesAsync();
}
}

View File

@ -17,5 +17,6 @@ namespace DamageAssesment.Api.Questions.Interfaces
Task<(bool IsSuccess, Models.QuestionCategory QuestionCategory, string ErrorMessage)> PostQuestionCategoryAsync(Models.QuestionCategory QuestionCategory);
Task<(bool IsSuccess, Models.QuestionCategory QuestionCategory, string ErrorMessage)> UpdateQuestionCategoryAsync(Models.QuestionCategory QuestionCategory);
Task<(bool IsSuccess, Models.QuestionCategory QuestionCategory, string ErrorMessage)> DeleteQuestionCategoryAsync(int Id);
void SeedData();
}
}

View File

@ -35,8 +35,20 @@ var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
using (var serviceScope = app.Services.CreateScope())
{
var services = serviceScope.ServiceProvider;
var questionProvider = services.GetRequiredService<IQuestionsProvider>();
questionProvider.SeedData();
}
app.UseSwagger();
app.UseSwaggerUI(options => { options.SwaggerEndpoint("/questions/swagger/v1/swagger.json", ""); });
app.UseSwaggerUI(options => {
//switch for local environment
options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
// options.SwaggerEndpoint("/questions/swagger/v1/swagger.json", "");
});
}
app.UseAuthorization();

View File

@ -21,10 +21,10 @@ namespace DamageAssesment.Api.Questions.Providers
this.questionDbContext = questionDbContext;
this.logger = logger;
this.mapper = mapper;
SeedData();
// SeedData();
}
private void SeedData()
public void SeedData()
{
if (!questionDbContext.QuestionsTranslations.Any())

View File

@ -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);

View File

@ -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();

View File

@ -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>();
}
}

View File

@ -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>();
}
}

View File

@ -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);

View File

@ -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>();
}
}
}

View File

@ -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>();
}
}

View File

@ -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>();
}
}
}

View File

@ -37,7 +37,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
this.surveyServiceProvider = surveyServiceProvider;
this.mapper = mapper;
seedData();
//seedData();
}
private void seedData()

View File

@ -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"))
{
}

View File

@ -18,14 +18,14 @@ namespace DamageAssesment.Api.Surveys.Controllers
/// GET request for retrieving surveys
/// </summary>
/// <remarks>
/// This endpoint retrieves surveys. You can use it to get all surveys or surveys for a specific language.
/// This endpoint retrieves surveys. You can use it to get all surveys or surveys for a specific language(optional).
/// </remarks>
[Route("Surveys")]
[Route("{Language}/Surveys")]
[Route("{language}/Surveys")]
[HttpGet]
public async Task<ActionResult> GetSurveysAsync(string? Language)
public async Task<ActionResult> GetSurveysAsync(string? language)
{
var result = await this.surveyProvider.GetSurveysAsync(Language);
var result = await this.surveyProvider.GetSurveysAsync(language);
if (result.IsSuccess)
{
return Ok(result.Surveys);
@ -37,11 +37,11 @@ namespace DamageAssesment.Api.Surveys.Controllers
/// GET request for retrieving surveys by ID.
/// </summary>
[Route("Surveys/{Id}")]
[Route("{Language}/Surveys/{Id}")]
[Route("{language}/Surveys/{Id}")]
[HttpGet]
public async Task<ActionResult> GetSurveysAsync(int Id, string? Language)
public async Task<ActionResult> GetSurveysAsync(int Id, string? language)
{
var result = await this.surveyProvider.GetSurveysAsync(Id, Language);
var result = await this.surveyProvider.GetSurveysAsync(Id, language);
if (result.IsSuccess)
{
return Ok(result.Surveys);

View File

@ -53,7 +53,12 @@ var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(options => { options.SwaggerEndpoint("/survey/swagger/v1/swagger.json", ""); });
app.UseSwaggerUI(options => {
//switch for local environment
options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
// options.SwaggerEndpoint("/surveys/swagger/v1/swagger.json", "");
});
}
app.UseAuthentication();