Merge with dev branch
This commit is contained in:
commit
a8105ab0f2
@ -30,8 +30,10 @@ builder.Services.AddDbContext<AnswerDbContext>(option =>
|
|||||||
{
|
{
|
||||||
option.UseInMemoryDatabase("Answers");
|
option.UseInMemoryDatabase("Answers");
|
||||||
});
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
@ -46,8 +48,8 @@ if (app.Environment.IsDevelopment())
|
|||||||
options =>
|
options =>
|
||||||
{
|
{
|
||||||
//switch for local environment
|
//switch for local environment
|
||||||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
|
//options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
|
||||||
//options.SwaggerEndpoint("/answers/swagger/v1/swagger.json","" );
|
options.SwaggerEndpoint("/answers/swagger/v1/swagger.json","" );
|
||||||
|
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ namespace DamageAssesment.Api.Answers.Providers
|
|||||||
|
|
||||||
public async Task<(bool IsSuccess, IEnumerable<Models.Answer> Answers, string ErrorMessage)> GetAnswersAsync()
|
public async Task<(bool IsSuccess, IEnumerable<Models.Answer> Answers, string ErrorMessage)> GetAnswersAsync()
|
||||||
{
|
{
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
logger?.LogInformation("Query Question");
|
logger?.LogInformation("Query Question");
|
||||||
|
@ -44,8 +44,8 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI(options => {
|
app.UseSwaggerUI(options => {
|
||||||
//switch for local environment
|
//switch for local environment
|
||||||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
|
// options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
|
||||||
// options.SwaggerEndpoint("/attachments/swagger/v1/swagger.json", "");
|
options.SwaggerEndpoint("/attachments/swagger/v1/swagger.json", "");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -43,8 +43,8 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwaggerUI(options =>
|
app.UseSwaggerUI(options =>
|
||||||
{
|
{
|
||||||
//switch for local environment
|
//switch for local environment
|
||||||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
|
// options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
|
||||||
// options.SwaggerEndpoint("/employees/swagger/v1/swagger.json", "");
|
options.SwaggerEndpoint("/employees/swagger/v1/swagger.json", "");
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,6 @@
|
|||||||
using AutoMapper;
|
|
||||||
using DamageAssesment.Api.Locations.Controllers;
|
using DamageAssesment.Api.Locations.Controllers;
|
||||||
using DamageAssesment.Api.Locations.Db;
|
|
||||||
using DamageAssesment.Api.Locations.Interfaces;
|
using DamageAssesment.Api.Locations.Interfaces;
|
||||||
using DamageAssesment.Api.Locations.Profiles;
|
|
||||||
using DamageAssesment.Api.Locations.Providers;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ namespace DamageAssesment.Api.Locations.Controllers
|
|||||||
this.regionProvider = regionProvider;
|
this.regionProvider = regionProvider;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get all regions.
|
/// Get all regions.2
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
@ -45,8 +45,8 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwaggerUI(options =>
|
app.UseSwaggerUI(options =>
|
||||||
{
|
{
|
||||||
//switch for local environment
|
//switch for local environment
|
||||||
options.SwaggerEndpoint("/swagger/v1/swagger.json","");
|
// options.SwaggerEndpoint("/swagger/v1/swagger.json","");
|
||||||
//options.SwaggerEndpoint("locations/swagger/v1/swagger.json", "");
|
options.SwaggerEndpoint("locations/swagger/v1/swagger.json", "");
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using DamageAssesment.Api.Locations.Db;
|
using DamageAssesment.Api.Locations.Db;
|
||||||
using DamageAssesment.Api.Locations.Interfaces;
|
using DamageAssesment.Api.Locations.Interfaces;
|
||||||
using DamageAssesment.Api.Locations.Models;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.Locations.Providers
|
namespace DamageAssesment.Api.Locations.Providers
|
||||||
|
@ -45,8 +45,8 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI(options => {
|
app.UseSwaggerUI(options => {
|
||||||
//switch for local environment
|
//switch for local environment
|
||||||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
|
// options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
|
||||||
// options.SwaggerEndpoint("/questions/swagger/v1/swagger.json", "");
|
options.SwaggerEndpoint("/questions/swagger/v1/swagger.json", "");
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -118,10 +118,10 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="responseId">The ID of the survey response to be retrieved.</param>
|
/// <param name="responseId">The ID of the survey response to be retrieved.</param>
|
||||||
|
|
||||||
[HttpGet("{responseId}")]
|
[HttpGet("SurveyResponse/{Id}")]
|
||||||
public async Task<ActionResult> GetSurveyResponseByIdAsync(int responseId)
|
public async Task<ActionResult> GetSurveyResponseByIdAsync(int Id)
|
||||||
{
|
{
|
||||||
var result = await this.surveyResponseProvider.GetSurveyResponseByIdAsync(responseId);
|
var result = await this.surveyResponseProvider.GetSurveyResponseByIdAsync(Id);
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
{
|
{
|
||||||
return Ok(result.SurveyResponse);
|
return Ok(result.SurveyResponse);
|
||||||
@ -185,12 +185,6 @@ namespace DamageAssesment.Api.SurveyResponses.Controllers
|
|||||||
[HttpPost("Answers")]
|
[HttpPost("Answers")]
|
||||||
public async Task<ActionResult> PostSurveyAnswersAsync(Request request)
|
public async Task<ActionResult> PostSurveyAnswersAsync(Request request)
|
||||||
{
|
{
|
||||||
/* var result = await this.surveyResponseProvider.PostSurveyAnswersAsync(surveyAnswers);
|
|
||||||
if (result.IsSuccess)
|
|
||||||
{
|
|
||||||
return Ok(result.SurveyResponse);
|
|
||||||
}
|
|
||||||
return BadRequest(result.ErrorMessage);*/
|
|
||||||
var result = await this.surveyResponseProvider.PostSurveyAnswersAsync(request);
|
var result = await this.surveyResponseProvider.PostSurveyAnswersAsync(request);
|
||||||
|
|
||||||
if (result.IsSuccess)
|
if (result.IsSuccess)
|
||||||
|
@ -19,12 +19,15 @@ namespace DamageAssesment.Api.SurveyResponses.Db
|
|||||||
[ForeignKey("Employee")]
|
[ForeignKey("Employee")]
|
||||||
public string EmployeeId { get; set; }
|
public string EmployeeId { get; set; }
|
||||||
|
|
||||||
//public DateTime? CreatedDate { get; set; }
|
public DateTime? CreatedDate { get; set; } = DateTime.Now;
|
||||||
|
|
||||||
//[StringLength(50)]
|
[StringLength(50)]
|
||||||
// public string ClientDevice { get; set; }
|
public string? ClientDevice { get; set; }
|
||||||
|
|
||||||
|
[StringLength(250)]
|
||||||
|
public string? KeyAnswerResult { get; set; }
|
||||||
|
public double? Longitute { get; set; }
|
||||||
|
public double? Latitude { get; set; }
|
||||||
|
|
||||||
// [StringLength(250)]
|
|
||||||
//public string KeyAnswerResult { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
using DamageAssesment.Api.SurveyResponses.Models;
|
||||||
|
|
||||||
|
namespace DamageAssesment.Api.SurveyResponses.Interfaces
|
||||||
|
{
|
||||||
|
public interface IHttpUtil
|
||||||
|
{
|
||||||
|
Task<string> SendAsync(HttpMethod method, string url, string JsonInput);
|
||||||
|
}
|
||||||
|
}
|
@ -5,24 +5,14 @@ namespace DamageAssesment.Api.SurveyResponses.Models
|
|||||||
{
|
{
|
||||||
public class SurveyResponse
|
public class SurveyResponse
|
||||||
{
|
{
|
||||||
[Key]
|
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
[ForeignKey("Survey")]
|
|
||||||
public int SurveyId { get; set; }
|
public int SurveyId { get; set; }
|
||||||
|
|
||||||
[ForeignKey("Location")]
|
|
||||||
public string LocationId { get; set; }
|
public string LocationId { get; set; }
|
||||||
|
|
||||||
[ForeignKey("Employee")]
|
|
||||||
public string EmployeeId { get; set; }
|
public string EmployeeId { get; set; }
|
||||||
|
public DateTime? CreatedDate { get; set; }
|
||||||
//public DateTime? CreatedDate { get; set; }
|
public string? ClientDevice { get; set; }
|
||||||
|
public string? KeyAnswerResult { get; set; }
|
||||||
//[StringLength(50)]
|
public double? Longitute { get; set; }
|
||||||
//public string ClientDevice { get; set; }
|
public double? Latitude { get; set; }
|
||||||
|
|
||||||
//[StringLength(250)]
|
|
||||||
//public string KeyAnswerResult { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
using DamageAssesment.Api.SurveyResponses.Db;
|
using DamageAssesment.Api.SurveyResponses.Db;
|
||||||
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
||||||
|
using DamageAssesment.Api.SurveyResponses.Services;
|
||||||
using DamageAssesment.Api.SurveyResponses.Providers;
|
using DamageAssesment.Api.SurveyResponses.Providers;
|
||||||
using Microsoft.AspNetCore.DataProtection.XmlEncryption;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Polly;
|
using Polly;
|
||||||
using System.Net.Http;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@ -20,35 +19,18 @@ builder.Services.AddControllers();
|
|||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
|
|
||||||
builder.Services.AddScoped<ISurveysResponse, SurveyResponsesProvider>();
|
builder.Services.AddScoped<ISurveysResponse, SurveyResponsesProvider>();
|
||||||
//builder.Services.AddScoped<ILogger, Logger>();
|
builder.Services.AddScoped<IAnswerServiceProvider, AnswerServiceProvider>();
|
||||||
|
builder.Services.AddScoped<ILocationServiceProvider, LocationServiceProvider>();
|
||||||
|
builder.Services.AddScoped<IRegionServiceProvider, RegionServiceProvider>();
|
||||||
|
builder.Services.AddScoped<IQuestionServiceProvider, QuestionServiceProvider>();
|
||||||
|
builder.Services.AddScoped<IEmployeeServiceProvider, EmployeeServiceProvider>();
|
||||||
|
builder.Services.AddScoped<IAttachmentServiceProvider, AttachmentServiceProvider>();
|
||||||
|
builder.Services.AddScoped<ISurveyServiceProvider, SurveyServiceProvider>();
|
||||||
|
|
||||||
builder.Services.AddHttpClient<IAnswerServiceProvider, AnswerServiceProvider>().
|
builder.Services.AddHttpClient<IHttpUtil, HttpUtil>().
|
||||||
AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(maxApiCallRetries, _ => TimeSpan.FromSeconds(intervalToRetry))).
|
|
||||||
AddTransientHttpErrorPolicy(policy => policy.CircuitBreakerAsync(maxRetryForCircuitBraker, TimeSpan.FromSeconds(intervalForCircuitBraker) ));
|
|
||||||
|
|
||||||
builder.Services.AddHttpClient<ILocationServiceProvider, LocationServiceProvider>().
|
|
||||||
AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(maxApiCallRetries, _ => TimeSpan.FromSeconds(intervalToRetry))).
|
AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(maxApiCallRetries, _ => TimeSpan.FromSeconds(intervalToRetry))).
|
||||||
AddTransientHttpErrorPolicy(policy => policy.CircuitBreakerAsync(maxRetryForCircuitBraker, TimeSpan.FromSeconds(intervalForCircuitBraker)));
|
AddTransientHttpErrorPolicy(policy => policy.CircuitBreakerAsync(maxRetryForCircuitBraker, TimeSpan.FromSeconds(intervalForCircuitBraker)));
|
||||||
|
|
||||||
builder.Services.AddHttpClient<IRegionServiceProvider, RegionServiceProvider>().
|
|
||||||
AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(maxApiCallRetries, _ => TimeSpan.FromSeconds(intervalToRetry))).
|
|
||||||
AddTransientHttpErrorPolicy(policy => policy.CircuitBreakerAsync(maxRetryForCircuitBraker, TimeSpan.FromSeconds(intervalForCircuitBraker)));
|
|
||||||
|
|
||||||
builder.Services.AddHttpClient<IQuestionServiceProvider, QuestionServiceProvider>().
|
|
||||||
AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(maxApiCallRetries, _ => TimeSpan.FromSeconds(intervalToRetry))).
|
|
||||||
AddTransientHttpErrorPolicy(policy => policy.CircuitBreakerAsync(maxRetryForCircuitBraker, TimeSpan.FromSeconds(intervalForCircuitBraker)));
|
|
||||||
|
|
||||||
builder.Services.AddHttpClient<IEmployeeServiceProvider, EmployeeServiceProvider>().
|
|
||||||
AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(maxApiCallRetries, _ => TimeSpan.FromSeconds(intervalToRetry))).
|
|
||||||
AddTransientHttpErrorPolicy(policy => policy.CircuitBreakerAsync(maxRetryForCircuitBraker, TimeSpan.FromSeconds(intervalForCircuitBraker)));
|
|
||||||
|
|
||||||
builder.Services.AddHttpClient<IAttachmentServiceProvider, AttachmentServiceProvider>().
|
|
||||||
AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(maxApiCallRetries, _ => TimeSpan.FromSeconds(intervalToRetry))).
|
|
||||||
AddTransientHttpErrorPolicy(policy => policy.CircuitBreakerAsync(maxRetryForCircuitBraker, TimeSpan.FromSeconds(intervalForCircuitBraker)));
|
|
||||||
|
|
||||||
builder.Services.AddHttpClient<ISurveyServiceProvider, SurveyServiceProvider>().
|
|
||||||
AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(maxApiCallRetries, _ => TimeSpan.FromSeconds(intervalToRetry))).
|
|
||||||
AddTransientHttpErrorPolicy(policy => policy.CircuitBreakerAsync(maxRetryForCircuitBraker, TimeSpan.FromSeconds(intervalForCircuitBraker)));
|
|
||||||
|
|
||||||
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
@ -72,8 +54,8 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI(options => {
|
app.UseSwaggerUI(options => {
|
||||||
//switch for local environment
|
//switch for local environment
|
||||||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
|
// options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
|
||||||
// options.SwaggerEndpoint("/surveyresponses/swagger/v1/swagger.json", "");
|
options.SwaggerEndpoint("/surveyresponses/swagger/v1/swagger.json", "");
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,96 +0,0 @@
|
|||||||
using DamageAssesment.Api.SurveyResponses.Bases;
|
|
||||||
using DamageAssesment.Api.SurveyResponses.Db;
|
|
||||||
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
|
||||||
using DamageAssesment.Api.SurveyResponses.Models;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Data.Common;
|
|
||||||
using System.Security.Cryptography;
|
|
||||||
using System.Text.Json.Nodes;
|
|
||||||
using System.Text;
|
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace DamageAssesment.Api.SurveyResponses.Providers
|
|
||||||
{
|
|
||||||
public class AnswerServiceProvider : ServiceProviderBase, IAnswerServiceProvider
|
|
||||||
{
|
|
||||||
|
|
||||||
public AnswerServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<AnswerServiceProvider> logger, IRegionServiceProvider regionServiceProvider, ILocationServiceProvider locationServiceProvider) : base(configuration, httpClient, logger, "/api/Answers", configuration.GetValue<string>("EndPointSettings:AnswerUrlBase"))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
public async Task<List<Answer>> getAnswersAsync()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
httpClient.BaseAddress = new Uri(urlBase);
|
|
||||||
var response = await httpClient.GetAsync(ressource);
|
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
var responseString = await response.Content.ReadAsStringAsync();
|
|
||||||
var answers = JsonConvert.DeserializeObject<List<Answer>>(responseString);
|
|
||||||
|
|
||||||
if (answers == null || !answers.Any())
|
|
||||||
return new List<Answer>();
|
|
||||||
else return answers;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger?.LogError($"Exception Found : {ex.Message} - Ref: AnswerServiceProvider.getAnswersAsync()");
|
|
||||||
return new List<Answer>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<List<Answer>> GetAnswersByResponseIdAsync(int responseId)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
httpClient.BaseAddress = new Uri(urlBase);
|
|
||||||
|
|
||||||
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 new List<Answer>();
|
|
||||||
else return answers;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger?.LogError($"Exception Found : {ex.Message} - Ref: AnswerServiceProvider.GetAnswersByResponseId()");
|
|
||||||
return new List<Answer>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<Answer> PostAnswersAsync(Answer answer)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var url = urlBase + ressource;
|
|
||||||
var request = new HttpRequestMessage(HttpMethod.Post, url);
|
|
||||||
request.Headers.Accept.Clear();
|
|
||||||
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
|
||||||
//request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
||||||
|
|
||||||
var jsonObject = JsonConvert.SerializeObject(answer);
|
|
||||||
request.Content = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json");
|
|
||||||
var response = await httpClient.SendAsync(request, CancellationToken.None);
|
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
var responseString = await response.Content.ReadAsStringAsync();
|
|
||||||
var answers = JsonConvert.DeserializeObject<Answer>(responseString);
|
|
||||||
|
|
||||||
if (answers == null)
|
|
||||||
{
|
|
||||||
logger?.LogError($"Answer cannot be added - Ref: AnswerServiceProvider.PostAnswersAsync()");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else return answers;
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger?.LogError($"Exception Found : {ex.Message} - Ref: AnswerServiceProvider.PostAnswersAsync()");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
using DamageAssesment.Api.SurveyResponses.Bases;
|
|
||||||
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
|
||||||
using DamageAssesment.Api.SurveyResponses.Models;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Runtime.Intrinsics.Arm;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace DamageAssesment.Api.SurveyResponses.Providers
|
|
||||||
{
|
|
||||||
public class AttachmentServiceProvider : ServiceProviderBase, IAttachmentServiceProvider
|
|
||||||
{
|
|
||||||
public AttachmentServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<AttachmentServiceProvider> logger) : base(configuration, httpClient, logger, "/Attachments", configuration.GetValue<string>("EndPointSettings:AttachmentUrlBase"))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<List<Attachment>> getAttachmentsAsync()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
httpClient.BaseAddress = new Uri(urlBase);
|
|
||||||
var response = await httpClient.GetAsync(ressource);
|
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
var responseString = await response.Content.ReadAsStringAsync();
|
|
||||||
var attachments = JsonConvert.DeserializeObject<List<Attachment>>(responseString);
|
|
||||||
|
|
||||||
if (attachments == null || !attachments.Any())
|
|
||||||
return new List<Attachment>();
|
|
||||||
else return attachments;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger?.LogError($"Exception Found : {ex.Message} - Ref: AttachmentServiceProvider.getAttachmentsAsync()");
|
|
||||||
return new List<Attachment>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IEnumerable<Attachment>> PostAttachmentsAsync(AttachmentInfo attachmentInfo)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
|
|
||||||
var url = urlBase + ressource;
|
|
||||||
var request = new HttpRequestMessage(HttpMethod.Post, url);
|
|
||||||
request.Headers.Accept.Clear();
|
|
||||||
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
|
||||||
//request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
|
||||||
|
|
||||||
var jsonObject = JsonConvert.SerializeObject(attachmentInfo);
|
|
||||||
request.Content = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json");
|
|
||||||
var response = await httpClient.SendAsync(request, CancellationToken.None);
|
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
var responseString = await response.Content.ReadAsStringAsync();
|
|
||||||
var attachments = JsonConvert.DeserializeObject<IEnumerable<Attachment>>(responseString);
|
|
||||||
|
|
||||||
if (attachments == null)
|
|
||||||
{
|
|
||||||
logger?.LogError($"Attachments cannot be added - Ref: AttachmentServiceProvider.PostAttachmentsAsync()");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else return attachments;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger?.LogError($"Exception Found : {ex.Message} - Ref: AttachmentServiceProvider.PostAttachmentsAsync()");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -3,11 +3,6 @@ using DamageAssesment.Api.SurveyResponses.Db;
|
|||||||
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
||||||
using DamageAssesment.Api.SurveyResponses.Models;
|
using DamageAssesment.Api.SurveyResponses.Models;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Internal;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Text;
|
|
||||||
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
|
||||||
|
|
||||||
namespace DamageAssesment.Api.SurveyResponses.Providers
|
namespace DamageAssesment.Api.SurveyResponses.Providers
|
||||||
{
|
{
|
||||||
@ -44,13 +39,12 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
{
|
{
|
||||||
if (!surveyResponseDbContext.SurveyResponses.Any())
|
if (!surveyResponseDbContext.SurveyResponses.Any())
|
||||||
{
|
{
|
||||||
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 1, SurveyId = 1, EmployeeId = "Emp1", LocationId = "Loc1" });
|
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 1, SurveyId = 1, EmployeeId = "Emp1", LocationId = "Loc1", ClientDevice = "Mobile", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "", CreatedDate = DateTime.Now });
|
||||||
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 2, SurveyId = 1, EmployeeId = "Emp2", LocationId = "Loc2" });
|
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 2, SurveyId = 1, EmployeeId = "Emp2", LocationId = "Loc2", ClientDevice = "Desktop", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "", CreatedDate = DateTime.Now });
|
||||||
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 3, SurveyId = 3, EmployeeId = "Emp4", LocationId = "Loc1" });
|
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 3, SurveyId = 3, EmployeeId = "Emp4", LocationId = "Loc1", ClientDevice = "Mobile", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "", CreatedDate = DateTime.Now });
|
||||||
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 4, SurveyId = 4, EmployeeId = "Emp1", LocationId = "Loc2" });
|
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 4, SurveyId = 4, EmployeeId = "Emp1", LocationId = "Loc2", ClientDevice = "Desktop", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "", CreatedDate = DateTime.Now });
|
||||||
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 5, SurveyId = 1, EmployeeId = "Emp3", LocationId = "Loc3" });
|
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 6, SurveyId = 1, EmployeeId = "Emp4", LocationId = "Loc2", ClientDevice = "Desktop", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "", CreatedDate = DateTime.Now });
|
||||||
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 6, SurveyId = 1, EmployeeId = "Emp4", LocationId = "Loc2" });
|
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 7, SurveyId = 1, EmployeeId = "Emp4", LocationId = "Loc3", ClientDevice = "Desktop", Latitude = 98.8767, Longitute = -129.9897, KeyAnswerResult = "", CreatedDate = DateTime.Now });
|
||||||
surveyResponseDbContext.SurveyResponses.Add(new Db.SurveyResponse { Id = 7, SurveyId = 1, EmployeeId = "Emp4", LocationId = "Loc3" });
|
|
||||||
surveyResponseDbContext.SaveChanges();
|
surveyResponseDbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -214,7 +208,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
var question = await questionServiceProvider.getQuestionsAsync(questionId);
|
var question = await questionServiceProvider.getQuestionsAsync(questionId);
|
||||||
bool IsCorrectAnswer = answer.ToLower().Equals("yes") || answer.ToLower().Equals("no") ? true : false;
|
bool IsCorrectAnswer = answer.ToLower().Equals("yes") || answer.ToLower().Equals("no") ? true : false;
|
||||||
|
|
||||||
|
|
||||||
if (survey != null && question != null && IsCorrectAnswer)
|
if (survey != null && question != null && IsCorrectAnswer)
|
||||||
{
|
{
|
||||||
var answers = await getSurveyResponsesByAnswerAsync(survey, question, answer);
|
var answers = await getSurveyResponsesByAnswerAsync(survey, question, answer);
|
||||||
@ -230,7 +224,7 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
return (false, null, "Not found");
|
return (false, null, "Not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -300,6 +294,10 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
_SurveyResponse.SurveyId = SurveyResponse.SurveyId;
|
_SurveyResponse.SurveyId = SurveyResponse.SurveyId;
|
||||||
_SurveyResponse.EmployeeId = SurveyResponse.EmployeeId;
|
_SurveyResponse.EmployeeId = SurveyResponse.EmployeeId;
|
||||||
_SurveyResponse.LocationId = SurveyResponse.LocationId;
|
_SurveyResponse.LocationId = SurveyResponse.LocationId;
|
||||||
|
_SurveyResponse.ClientDevice = SurveyResponse.ClientDevice;
|
||||||
|
_SurveyResponse.KeyAnswerResult = SurveyResponse.KeyAnswerResult;
|
||||||
|
_SurveyResponse.Longitute = SurveyResponse.Longitute;
|
||||||
|
_SurveyResponse.Latitude = SurveyResponse.Latitude;
|
||||||
await surveyResponseDbContext.SaveChangesAsync();
|
await surveyResponseDbContext.SaveChangesAsync();
|
||||||
return (true, mapper.Map<Db.SurveyResponse, Models.SurveyResponse>(_SurveyResponse), "Successful");
|
return (true, mapper.Map<Db.SurveyResponse, Models.SurveyResponse>(_SurveyResponse), "Successful");
|
||||||
}
|
}
|
||||||
@ -340,7 +338,6 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
logger?.LogInformation($"SurveyReponseId = {Id} Not found");
|
logger?.LogInformation($"SurveyReponseId = {Id} Not found");
|
||||||
return (false, null, "Not Found");
|
return (false, null, "Not Found");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -435,35 +432,35 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var surveyResonses = await surveyResponseDbContext.SurveyResponses.Where(x => x.Id == surveyResponse.Id).ToListAsync();
|
|
||||||
//var surveyResponse = surveyResonses.SingleOrDefault();
|
|
||||||
var employee = await employeeServiceProvider.getEmployeeAsync(surveyResponse.EmployeeId);
|
var employee = await employeeServiceProvider.getEmployeeAsync(surveyResponse.EmployeeId);
|
||||||
var answers = await answerServiceProvider.GetAnswersByResponseIdAsync(surveyResponse.Id);
|
var answers = await answerServiceProvider.GetAnswersByResponseIdAsync(surveyResponse.Id);
|
||||||
var allQuestions = await questionServiceProvider.getQuestionsAsync();
|
var allQuestions = await questionServiceProvider.getQuestionsAsync();
|
||||||
var questions = allQuestions.Where(s=> s.SurveyId == surveyResponse.Id);
|
var questions = allQuestions.Where(s => s.SurveyId == surveyResponse.SurveyId);
|
||||||
var attachments = await attachmentServiceProvider.getAttachmentsAsync();
|
var attachments = await attachmentServiceProvider.getAttachmentsAsync();
|
||||||
|
|
||||||
|
var result = new
|
||||||
var result = from r in surveyResonses
|
{
|
||||||
select new
|
surveyResponse.Id,
|
||||||
{
|
surveyResponse.SurveyId,
|
||||||
r.Id,
|
surveyResponse.LocationId,
|
||||||
r.SurveyId,
|
surveyResponse.EmployeeId,
|
||||||
r.LocationId,
|
surveyResponse.ClientDevice,
|
||||||
r.EmployeeId,
|
surveyResponse.KeyAnswerResult,
|
||||||
Employee = employee,
|
surveyResponse.Longitute,
|
||||||
answers = from ans in answers
|
surveyResponse.Latitude,
|
||||||
select new
|
Employee = employee,
|
||||||
{
|
answers = from ans in answers
|
||||||
ans.QuestionId,
|
select new
|
||||||
ans.Id,
|
{
|
||||||
ans.AnswerText,
|
ans.QuestionId,
|
||||||
ans.Comment,
|
ans.Id,
|
||||||
Questions = (from q in questions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.CategoryId, q.Questions }).SingleOrDefault(),
|
ans.AnswerText,
|
||||||
Attachments = from att in attachments where att.AnswerId == ans.Id select new { att.Id, att.URI }
|
ans.Comment,
|
||||||
}
|
Questions = (from q in questions where q.Id == ans.QuestionId select new { q.Id, q.QuestionNumber, q.CategoryId, q.Questions }).SingleOrDefault(),
|
||||||
};
|
Attachments = from att in attachments where att.AnswerId == ans.Id select new { att.Id, att.URI }
|
||||||
return result.SingleOrDefault();
|
}
|
||||||
|
};
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -495,6 +492,10 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
r.SurveyId,
|
r.SurveyId,
|
||||||
r.LocationId,
|
r.LocationId,
|
||||||
r.EmployeeId,
|
r.EmployeeId,
|
||||||
|
r.ClientDevice,
|
||||||
|
r.KeyAnswerResult,
|
||||||
|
r.Longitute,
|
||||||
|
r.Latitude,
|
||||||
Employee = (from e in employees where e.Id == r.EmployeeId select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(),
|
Employee = (from e in employees where e.Id == r.EmployeeId select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(),
|
||||||
answers = from ans in answers
|
answers = from ans in answers
|
||||||
where ans.SurveyResponseId == r.Id
|
where ans.SurveyResponseId == r.Id
|
||||||
@ -531,6 +532,8 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
var questions = await questionServiceProvider.getQuestionsAsync();
|
var questions = await questionServiceProvider.getQuestionsAsync();
|
||||||
var attachments = await attachmentServiceProvider.getAttachmentsAsync();
|
var attachments = await attachmentServiceProvider.getAttachmentsAsync();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var result = from r in surveyResonses
|
var result = from r in surveyResonses
|
||||||
select new
|
select new
|
||||||
{
|
{
|
||||||
@ -538,6 +541,10 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
r.SurveyId,
|
r.SurveyId,
|
||||||
r.LocationId,
|
r.LocationId,
|
||||||
r.EmployeeId,
|
r.EmployeeId,
|
||||||
|
r.ClientDevice,
|
||||||
|
r.KeyAnswerResult,
|
||||||
|
r.Longitute,
|
||||||
|
r.Latitude,
|
||||||
Employee = (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(),
|
Employee = (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(),
|
||||||
answers = from ans in answers
|
answers = from ans in answers
|
||||||
where ans.SurveyResponseId == r.Id
|
where ans.SurveyResponseId == r.Id
|
||||||
@ -641,6 +648,10 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
r.SurveyId,
|
r.SurveyId,
|
||||||
r.LocationId,
|
r.LocationId,
|
||||||
r.EmployeeId,
|
r.EmployeeId,
|
||||||
|
r.ClientDevice,
|
||||||
|
r.KeyAnswerResult,
|
||||||
|
r.Longitute,
|
||||||
|
r.Latitude,
|
||||||
Employee = (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(),
|
Employee = (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(),
|
||||||
answers = from ans in answers
|
answers = from ans in answers
|
||||||
where ans.SurveyResponseId == r.Id
|
where ans.SurveyResponseId == r.Id
|
||||||
@ -671,8 +682,6 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var surveyResponses = await surveyResponseDbContext.SurveyResponses.Where(x => x.SurveyId == survey.Id).ToListAsync();
|
var surveyResponses = await surveyResponseDbContext.SurveyResponses.Where(x => x.SurveyId == survey.Id).ToListAsync();
|
||||||
//var questions = await questionServiceProvider.getQuestionsAsync();
|
|
||||||
|
|
||||||
var answers = await answerServiceProvider.getAnswersAsync();
|
var answers = await answerServiceProvider.getAnswersAsync();
|
||||||
var employees = await employeeServiceProvider.getEmployeesAsync();
|
var employees = await employeeServiceProvider.getEmployeesAsync();
|
||||||
var attachments = await attachmentServiceProvider.getAttachmentsAsync();
|
var attachments = await attachmentServiceProvider.getAttachmentsAsync();
|
||||||
@ -684,6 +693,10 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
r.SurveyId,
|
r.SurveyId,
|
||||||
r.LocationId,
|
r.LocationId,
|
||||||
r.EmployeeId,
|
r.EmployeeId,
|
||||||
|
r.ClientDevice,
|
||||||
|
r.KeyAnswerResult,
|
||||||
|
r.Longitute,
|
||||||
|
r.Latitude,
|
||||||
Employee = (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(),
|
Employee = (from e in employees where r.EmployeeId == e.Id select new { e.Id, e.Name, e.BirthDate, e.Email, e.OfficePhoneNumber }).SingleOrDefault(),
|
||||||
answers = from ans in answers
|
answers = from ans in answers
|
||||||
where ans.SurveyResponseId == r.Id
|
where ans.SurveyResponseId == r.Id
|
||||||
@ -714,23 +727,23 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
{
|
{
|
||||||
if (answerRequest != null)
|
if (answerRequest != null)
|
||||||
{
|
{
|
||||||
var answer = await answerServiceProvider.PostAnswersAsync(new Models.Answer {QuestionId = answerRequest.QuestionId, AnswerText = answerRequest.AnswerText, Comment = answerRequest.Comment, SurveyResponseId = surveyResponseId });
|
var answer = await answerServiceProvider.PostAnswersAsync(new Models.Answer { QuestionId = answerRequest.QuestionId, AnswerText = answerRequest.AnswerText, Comment = answerRequest.Comment, SurveyResponseId = surveyResponseId });
|
||||||
if (answer != null)
|
if (answer != null)
|
||||||
{
|
{
|
||||||
List<AnswerInfo> listAnswerInfo = new List<AnswerInfo>();
|
List<AnswerInfo> listAnswerInfo = new List<AnswerInfo>();
|
||||||
listAnswerInfo.Add(new AnswerInfo { AnswerId = answer.Id, postedFiles = answerRequest.PostedFiles });
|
listAnswerInfo.Add(new AnswerInfo { AnswerId = answer.Id, postedFiles = answerRequest.PostedFiles });
|
||||||
var attachments = attachmentServiceProvider.PostAttachmentsAsync(new AttachmentInfo { ResponseId = surveyResponseId, Answers = listAnswerInfo });
|
var attachments = attachmentServiceProvider.PostAttachmentsAsync(new AttachmentInfo { ResponseId = surveyResponseId, Answers = listAnswerInfo });
|
||||||
|
|
||||||
string message = $"Answer for question {answerRequest.QuestionId} saved to the database";
|
string message = $"Answer for question {answerRequest.QuestionId} saved to the database";
|
||||||
logger?.LogInformation(message);
|
logger?.LogInformation(message);
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string message = $"Answer for question {answerRequest.QuestionId} cannot be saved to the database";
|
string message = $"Answer for question {answerRequest.QuestionId} cannot be saved to the database";
|
||||||
logger?.LogInformation(message);
|
logger?.LogInformation(message);
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -747,37 +760,12 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
{
|
{
|
||||||
if (request != null)
|
if (request != null)
|
||||||
{
|
{
|
||||||
var response = await PostSurveyResponseAsync(new Models.SurveyResponse {SurveyId = request.SurveyId, EmployeeId = request.EmployeeId, LocationId = request.LocationId });
|
var response = await PostSurveyResponseAsync(new Models.SurveyResponse { SurveyId = request.SurveyId, EmployeeId = request.EmployeeId, LocationId = request.LocationId });
|
||||||
|
|
||||||
if (response.IsSuccess)
|
if (response.IsSuccess)
|
||||||
{
|
{
|
||||||
var surveyResponse = response.SurveyResponse;
|
var surveyResponse = response.SurveyResponse;
|
||||||
var tasks = request.Answers.Select(x => ProcessAnswers(x,surveyResponse.Id));
|
var tasks = request.Answers.Select(x => ProcessAnswers(x, surveyResponse.Id));
|
||||||
|
|
||||||
// foreach (AnswerRequest ans in request.Answers)
|
|
||||||
// {
|
|
||||||
// answer = new Models.Answer { QuestionId = ans.QuestionId, AnswerText = ans.AnswerText, Comment = ans.Comment, SurveyResponseId = surveyResponse.Id };
|
|
||||||
|
|
||||||
//var content = new StringContent(jsonObject.ToString(), Encoding.UTF8, "application/json");
|
|
||||||
|
|
||||||
//await Task.Delay(500);
|
|
||||||
// var rep = await answerServiceProvider.PostAnswersAsync(answer);
|
|
||||||
// var jsonObject = JsonConvert.SerializeObject(rep);
|
|
||||||
//x = x + jsonObject.ToString() + " ";
|
|
||||||
//i++;
|
|
||||||
// answer = new Models.Answer { QuestionId = ans.QuestionId, AnswerText = ans.AnswerText, Comment = ans.Comment, SurveyResponseId = surveyResponse.Id };
|
|
||||||
// await answerServiceProvider.PostAnswersAsync(answer);
|
|
||||||
//ProcessAnswers(ans, surveyResponse.Id);
|
|
||||||
//var stopwatch = new Stopwatch();
|
|
||||||
//stopwatch.Start();
|
|
||||||
// var task = Task.Run(() => ProcessAnswers(ans, surveyResponse.Id));
|
|
||||||
//var task = await ProcessAnswers(ans, surveyResponse.Id);
|
|
||||||
//answerTasks.Add(task);
|
|
||||||
|
|
||||||
|
|
||||||
//stopwatch.Stop();
|
|
||||||
//answerTasks.Add(ProcessAnswers(ans, surveyResponse.Id));
|
|
||||||
// }
|
|
||||||
await Task.WhenAll(tasks);
|
await Task.WhenAll(tasks);
|
||||||
return (true, surveyResponse, null);
|
return (true, surveyResponse, null);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,74 @@
|
|||||||
|
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
||||||
|
using DamageAssesment.Api.SurveyResponses.Models;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
|
||||||
|
namespace DamageAssesment.Api.SurveyResponses.Services
|
||||||
|
{
|
||||||
|
public class AnswerServiceProvider : ServiceProviderBase, IAnswerServiceProvider
|
||||||
|
{
|
||||||
|
public AnswerServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<AnswerServiceProvider> logger) : base(configuration, httpUtil, logger, "/api/Answers", configuration.GetValue<string>("EndPointSettings:AnswerUrlBase"))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public async Task<List<Answer>> getAnswersAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var url = urlBase + ressource;
|
||||||
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
||||||
|
var answers = JsonConvert.DeserializeObject<List<Answer>>(responseJsonString);
|
||||||
|
|
||||||
|
if (answers == null || !answers.Any())
|
||||||
|
return new List<Answer>();
|
||||||
|
else return answers;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: AnswerServiceProvider.getAnswersAsync()");
|
||||||
|
return new List<Answer>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<Answer>> GetAnswersByResponseIdAsync(int responseId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var url = urlBase + "/api/AnswersByResponse/" + responseId;
|
||||||
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
||||||
|
var answers = JsonConvert.DeserializeObject<List<Answer>>(responseJsonString);
|
||||||
|
|
||||||
|
if (answers == null || !answers.Any())
|
||||||
|
return new List<Answer>();
|
||||||
|
else return answers;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: AnswerServiceProvider.GetAnswersByResponseId()");
|
||||||
|
return new List<Answer>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Answer> PostAnswersAsync(Answer answer)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var url = urlBase + ressource;
|
||||||
|
var requestJsonString = JsonConvert.SerializeObject(answer);
|
||||||
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Post, url, requestJsonString);
|
||||||
|
var answers = JsonConvert.DeserializeObject<Answer>(responseJsonString);
|
||||||
|
|
||||||
|
if (answers == null)
|
||||||
|
{
|
||||||
|
logger?.LogError($"Answers cannot be added - Ref: AnswerServiceProvider.PostAnswersAsync()");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else return answers;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: AnswerServiceProvider.PostAnswersAsync()");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
||||||
|
using DamageAssesment.Api.SurveyResponses.Models;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace DamageAssesment.Api.SurveyResponses.Services
|
||||||
|
{
|
||||||
|
public class AttachmentServiceProvider : ServiceProviderBase, IAttachmentServiceProvider
|
||||||
|
{
|
||||||
|
public AttachmentServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<AttachmentServiceProvider> logger) : base(configuration, httpUtil, logger, "/api/Attachments", configuration.GetValue<string>("EndPointSettings:AttachmentUrlBase"))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<Attachment>> getAttachmentsAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var url = urlBase + ressource;
|
||||||
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
||||||
|
var attachments = JsonConvert.DeserializeObject<List<Attachment>>(responseJsonString);
|
||||||
|
|
||||||
|
if (attachments == null || !attachments.Any())
|
||||||
|
return new List<Attachment>();
|
||||||
|
else return attachments;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: AttachmentServiceProvider.getAttachmentsAsync()");
|
||||||
|
return new List<Attachment>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<Attachment>> PostAttachmentsAsync(AttachmentInfo attachmentInfo)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var url = urlBase + ressource;
|
||||||
|
var requestJsonString = JsonConvert.SerializeObject(attachmentInfo);
|
||||||
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Post, url, requestJsonString);
|
||||||
|
var attachments = JsonConvert.DeserializeObject<IEnumerable<Attachment>>(responseJsonString);
|
||||||
|
|
||||||
|
if (attachments == null)
|
||||||
|
{
|
||||||
|
logger?.LogError($"Attachments cannot be added - Ref: AttachmentServiceProvider.PostAttachmentsAsync()");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else return attachments;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: AttachmentServiceProvider.PostAttachmentsAsync()");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,14 +1,12 @@
|
|||||||
using DamageAssesment.Api.SurveyResponses.Bases;
|
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
||||||
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
|
||||||
using DamageAssesment.Api.SurveyResponses.Models;
|
using DamageAssesment.Api.SurveyResponses.Models;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace DamageAssesment.Api.SurveyResponses.Providers
|
namespace DamageAssesment.Api.SurveyResponses.Services
|
||||||
{
|
{
|
||||||
public class EmployeeServiceProvider :ServiceProviderBase, IEmployeeServiceProvider
|
public class EmployeeServiceProvider :ServiceProviderBase, IEmployeeServiceProvider
|
||||||
{
|
{
|
||||||
public EmployeeServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<EmployeeServiceProvider> logger) : base(configuration, httpClient, logger, "/Employees", configuration.GetValue<string>("EndPointSettings:EmployeeUrlBase"))
|
public EmployeeServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<EmployeeServiceProvider> logger) : base(configuration, httpUtil, logger, "/api/Employees", configuration.GetValue<string>("EndPointSettings:EmployeeUrlBase"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,11 +14,9 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
httpClient.BaseAddress = new Uri(urlBase);
|
var url = urlBase + ressource;
|
||||||
var response = await httpClient.GetAsync(ressource);
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
||||||
response.EnsureSuccessStatusCode();
|
var employees = JsonConvert.DeserializeObject<List<Employee>>(responseJsonString);
|
||||||
var responseString = await response.Content.ReadAsStringAsync();
|
|
||||||
var employees = JsonConvert.DeserializeObject<List<Employee>>(responseString);
|
|
||||||
|
|
||||||
if (employees == null || !employees.Any())
|
if (employees == null || !employees.Any())
|
||||||
return new List<Employee>();
|
return new List<Employee>();
|
||||||
@ -33,16 +29,13 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Employee> getEmployeeAsync(string employeeID)
|
public async Task<Employee> getEmployeeAsync(string employeeId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
httpClient.BaseAddress = new Uri(urlBase);
|
var url = urlBase + "/api/Employees/" + employeeId;
|
||||||
//ressource = ressource + "/" + employeeID;
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
||||||
var response = await httpClient.GetAsync("/Employees/"+ employeeID);
|
var employee = JsonConvert.DeserializeObject<Employee>(responseJsonString);
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
var responseString = await response.Content.ReadAsStringAsync();
|
|
||||||
var employee = JsonConvert.DeserializeObject<Employee>(responseString);
|
|
||||||
|
|
||||||
if (employee == null )
|
if (employee == null )
|
||||||
return null;
|
return null;
|
@ -0,0 +1,43 @@
|
|||||||
|
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace DamageAssesment.Api.SurveyResponses.Services
|
||||||
|
{
|
||||||
|
public class HttpUtil : IHttpUtil
|
||||||
|
{
|
||||||
|
private readonly HttpClient httpClient;
|
||||||
|
private readonly ILogger<HttpUtil> logger;
|
||||||
|
|
||||||
|
public HttpUtil(HttpClient httpClient, ILogger<HttpUtil> logger)
|
||||||
|
{
|
||||||
|
this.httpClient = httpClient;
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
|
public async Task<string> SendAsync(HttpMethod method, string url, string JsonInput)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var request = new HttpRequestMessage(method, url);
|
||||||
|
request.Headers.Accept.Clear();
|
||||||
|
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
|
||||||
|
//request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
|
||||||
|
if (method == HttpMethod.Post)
|
||||||
|
{
|
||||||
|
request.Content = new StringContent(JsonInput, Encoding.UTF8, "application/json");
|
||||||
|
}
|
||||||
|
|
||||||
|
var response = await httpClient.SendAsync(request, CancellationToken.None);
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
var responseString = await response.Content.ReadAsStringAsync();
|
||||||
|
return responseString;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
logger?.LogError($"Exception Message : {ex.Message} - Ref: HttpUtil.SendAsync()");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,12 @@
|
|||||||
using DamageAssesment.Api.SurveyResponses.Bases;
|
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
||||||
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
|
||||||
using DamageAssesment.Api.SurveyResponses.Models;
|
using DamageAssesment.Api.SurveyResponses.Models;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.SurveyResponses.Providers
|
namespace DamageAssesment.Api.SurveyResponses.Services
|
||||||
{
|
{
|
||||||
public class LocationServiceProvider :ServiceProviderBase, ILocationServiceProvider
|
public class LocationServiceProvider :ServiceProviderBase, ILocationServiceProvider
|
||||||
{
|
{
|
||||||
public LocationServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<LocationServiceProvider> logger) : base(configuration, httpClient, logger, "/Locations", configuration.GetValue<string>("EndPointSettings:LocationUrlBase"))
|
public LocationServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<LocationServiceProvider> logger) : base(configuration, httpUtil, logger, "/api/Locations", configuration.GetValue<string>("EndPointSettings:LocationUrlBase"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,11 +14,9 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
httpClient.BaseAddress = new Uri(urlBase);
|
var url = urlBase + ressource;
|
||||||
var response = await httpClient.GetAsync(ressource);
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
||||||
response.EnsureSuccessStatusCode();
|
var locations = JsonConvert.DeserializeObject<List<Location>>(responseJsonString);
|
||||||
var responseString = await response.Content.ReadAsStringAsync();
|
|
||||||
var locations = JsonConvert.DeserializeObject<List<Location>>(responseString);
|
|
||||||
|
|
||||||
if (locations == null || !locations.Any())
|
if (locations == null || !locations.Any())
|
||||||
return new List<Location>();
|
return new List<Location>();
|
@ -1,15 +1,12 @@
|
|||||||
using DamageAssesment.Api.SurveyResponses.Bases;
|
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
||||||
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
|
||||||
using DamageAssesment.Api.SurveyResponses.Models;
|
using DamageAssesment.Api.SurveyResponses.Models;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace DamageAssesment.Api.SurveyResponses.Services
|
||||||
|
|
||||||
namespace DamageAssesment.Api.SurveyResponses.Providers
|
|
||||||
{
|
{
|
||||||
public class QuestionServiceProvider : ServiceProviderBase, IQuestionServiceProvider
|
public class QuestionServiceProvider : ServiceProviderBase, IQuestionServiceProvider
|
||||||
{
|
{
|
||||||
public QuestionServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<QuestionServiceProvider> logger) : base(configuration, httpClient, logger, "/Questions", configuration.GetValue<string>("EndPointSettings:QuestionUrlBase"))
|
public QuestionServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<QuestionServiceProvider> logger) : base(configuration, httpUtil, logger, "/api/Questions", configuration.GetValue<string>("EndPointSettings:QuestionUrlBase"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,11 +14,9 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
httpClient.BaseAddress = new Uri(urlBase);
|
var url = urlBase + ressource;
|
||||||
var response = await httpClient.GetAsync(ressource);
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
||||||
response.EnsureSuccessStatusCode();
|
var questions = JsonConvert.DeserializeObject<List<Question>>(responseJsonString);
|
||||||
var responseString = await response.Content.ReadAsStringAsync();
|
|
||||||
var questions = JsonConvert.DeserializeObject<List<Question>>(responseString);
|
|
||||||
|
|
||||||
if (questions == null || !questions.Any())
|
if (questions == null || !questions.Any())
|
||||||
return new List<Question>();
|
return new List<Question>();
|
||||||
@ -38,14 +33,12 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
httpClient.BaseAddress = new Uri(urlBase);
|
var url = urlBase + "/api/GetSurveyQuestions/" + surveyId;
|
||||||
var response = await httpClient.GetAsync("/GetSurveyQuestions/" + surveyId);
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
||||||
response.EnsureSuccessStatusCode();
|
var questions = JsonConvert.DeserializeObject<List<SurveyQuestions>>(responseJsonString);
|
||||||
var responseString = await response.Content.ReadAsStringAsync();
|
|
||||||
var questions = JsonConvert.DeserializeObject<List<SurveyQuestions>>(responseString);
|
|
||||||
|
|
||||||
if (questions == null || !questions.Any())
|
if (questions == null || !questions.Any())
|
||||||
return new List<SurveyQuestions>();
|
return new List<SurveyQuestions>() ;
|
||||||
else return questions;
|
else return questions;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -60,11 +53,9 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
httpClient.BaseAddress = new Uri(urlBase);
|
var url = urlBase + "/api/Questions/" + questionId;
|
||||||
var response = await httpClient.GetAsync("/api/Questions/" + questionId);
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
||||||
response.EnsureSuccessStatusCode();
|
var question = JsonConvert.DeserializeObject<Question>(responseJsonString);
|
||||||
var responseString = await response.Content.ReadAsStringAsync();
|
|
||||||
var question = JsonConvert.DeserializeObject<Question>(responseString);
|
|
||||||
|
|
||||||
if (question == null)
|
if (question == null)
|
||||||
return null;
|
return null;
|
@ -1,24 +1,21 @@
|
|||||||
using DamageAssesment.Api.SurveyResponses.Bases;
|
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
||||||
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
|
||||||
using DamageAssesment.Api.SurveyResponses.Models;
|
using DamageAssesment.Api.SurveyResponses.Models;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace DamageAssesment.Api.SurveyResponses.Providers
|
namespace DamageAssesment.Api.SurveyResponses.Services
|
||||||
{
|
{
|
||||||
public class RegionServiceProvider : ServiceProviderBase, IRegionServiceProvider
|
public class RegionServiceProvider : ServiceProviderBase, IRegionServiceProvider
|
||||||
{
|
{
|
||||||
public RegionServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<RegionServiceProvider> logger) : base(configuration, httpClient, logger, "/Regions", configuration.GetValue<string>("EndPointSettings:LocationUrlBase"))
|
public RegionServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<RegionServiceProvider> logger) : base(configuration, httpUtil, logger, "/api/Regions", configuration.GetValue<string>("EndPointSettings:LocationUrlBase"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
public async Task<List<Region>> getRegionsAsync()
|
public async Task<List<Region>> getRegionsAsync()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
httpClient.BaseAddress = new Uri(urlBase);
|
var url = urlBase + ressource;
|
||||||
var response = await httpClient.GetAsync(ressource);
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
||||||
response.EnsureSuccessStatusCode();
|
var regions = JsonConvert.DeserializeObject<List<Region>>(responseJsonString);
|
||||||
var responseString = await response.Content.ReadAsStringAsync();
|
|
||||||
var regions = JsonConvert.DeserializeObject<List<Region>>(responseString);
|
|
||||||
|
|
||||||
if (regions == null || !regions.Any())
|
if (regions == null || !regions.Any())
|
||||||
return new List<Region>();
|
return new List<Region>();
|
@ -1,18 +1,20 @@
|
|||||||
namespace DamageAssesment.Api.SurveyResponses.Bases
|
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
||||||
|
|
||||||
|
namespace DamageAssesment.Api.SurveyResponses.Services
|
||||||
{
|
{
|
||||||
public class ServiceProviderBase
|
public class ServiceProviderBase
|
||||||
{
|
{
|
||||||
protected readonly IConfiguration configuration;
|
protected readonly IConfiguration configuration;
|
||||||
protected readonly HttpClient httpClient;
|
protected readonly IHttpUtil httpUtil;
|
||||||
protected private readonly ILogger<ServiceProviderBase> logger;
|
protected readonly ILogger<ServiceProviderBase> logger;
|
||||||
protected string ressource;
|
protected string ressource;
|
||||||
protected string urlBase;
|
protected string urlBase;
|
||||||
|
|
||||||
|
|
||||||
public ServiceProviderBase(IConfiguration configuration, HttpClient httpClient, ILogger<ServiceProviderBase> logger, string ressource, string urlBase)
|
public ServiceProviderBase(IConfiguration configuration, IHttpUtil httpUtil, ILogger<ServiceProviderBase> logger, string ressource, string urlBase)
|
||||||
{
|
{
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
this.httpClient = httpClient;
|
this.httpUtil = httpUtil;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.ressource = ressource;
|
this.ressource = ressource;
|
||||||
this.urlBase = urlBase;
|
this.urlBase = urlBase;
|
@ -1,14 +1,12 @@
|
|||||||
using DamageAssesment.Api.SurveyResponses.Bases;
|
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
||||||
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
|
||||||
using DamageAssesment.Api.SurveyResponses.Models;
|
using DamageAssesment.Api.SurveyResponses.Models;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace DamageAssesment.Api.SurveyResponses.Providers
|
namespace DamageAssesment.Api.SurveyResponses.Services
|
||||||
{
|
{
|
||||||
public class SurveyServiceProvider :ServiceProviderBase, ISurveyServiceProvider
|
public class SurveyServiceProvider :ServiceProviderBase, ISurveyServiceProvider
|
||||||
{
|
{
|
||||||
public SurveyServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<EmployeeServiceProvider> logger) : base(configuration, httpClient, logger, "/Surveys", configuration.GetValue<string>("EndPointSettings:SurveyUrlBase"))
|
public SurveyServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<EmployeeServiceProvider> logger) : base(configuration, httpUtil, logger, "/api/Surveys", configuration.GetValue<string>("EndPointSettings:SurveyUrlBase"))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,20 +14,19 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
httpClient.BaseAddress = new Uri(urlBase);
|
|
||||||
var response = await httpClient.GetAsync(ressource);
|
var url = urlBase + ressource;
|
||||||
response.EnsureSuccessStatusCode();
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
||||||
var responseString = await response.Content.ReadAsStringAsync();
|
var surveys = JsonConvert.DeserializeObject<List<Survey>>(responseJsonString);
|
||||||
var surveys = JsonConvert.DeserializeObject<List<Survey>>(responseString);
|
|
||||||
|
|
||||||
if (surveys == null || !surveys.Any())
|
if (surveys == null || !surveys.Any())
|
||||||
return null;
|
return new List<Survey>();
|
||||||
else return surveys;
|
else return surveys;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger?.LogError($"Exception Found : {ex.Message} - Ref: SurveyServiceProvider.getSurveysAsync()");
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: SurveyServiceProvider.getSurveysAsync()");
|
||||||
return null;
|
return new List<Survey>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,11 +34,9 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
httpClient.BaseAddress = new Uri(urlBase);
|
var url = urlBase + ressource + "/" + surveyId;
|
||||||
var response = await httpClient.GetAsync(ressource+"/"+ surveyId);
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
||||||
response.EnsureSuccessStatusCode();
|
var survey = JsonConvert.DeserializeObject<Survey>(responseJsonString);
|
||||||
var responseString = await response.Content.ReadAsStringAsync();
|
|
||||||
var survey = JsonConvert.DeserializeObject<Survey>(responseString);
|
|
||||||
|
|
||||||
if (survey == null )
|
if (survey == null )
|
||||||
return null;
|
return null;
|
||||||
@ -53,7 +48,5 @@ namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,6 +7,7 @@
|
|||||||
Task<(bool IsSuccess, Models.Survey Survey, string ErrorMessage)> PostSurveyAsync(Models.Survey Survey);
|
Task<(bool IsSuccess, Models.Survey Survey, string ErrorMessage)> PostSurveyAsync(Models.Survey Survey);
|
||||||
Task<(bool IsSuccess, Models.Survey Survey, string ErrorMessage)> PutSurveyAsync(int Id,Models.Survey Survey);
|
Task<(bool IsSuccess, Models.Survey Survey, string ErrorMessage)> PutSurveyAsync(int Id,Models.Survey Survey);
|
||||||
Task<(bool IsSuccess, Models.Survey Survey, string ErrorMessage)> DeleteSurveyAsync(int Id);
|
Task<(bool IsSuccess, Models.Survey Survey, string ErrorMessage)> DeleteSurveyAsync(int Id);
|
||||||
|
void seedData();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,10 +55,18 @@ if (app.Environment.IsDevelopment())
|
|||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI(options => {
|
app.UseSwaggerUI(options => {
|
||||||
//switch for local environment
|
//switch for local environment
|
||||||
options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
|
// options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
|
||||||
//options.SwaggerEndpoint("/surveys/swagger/v1/swagger.json", "");
|
options.SwaggerEndpoint("/surveys/swagger/v1/swagger.json", "");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
app.UseSwaggerUI();
|
||||||
|
|
||||||
|
using (var serviceScope = app.Services.CreateScope())
|
||||||
|
{
|
||||||
|
var services = serviceScope.ServiceProvider;
|
||||||
|
var surveyProvider = services.GetRequiredService<ISurveyProvider>();
|
||||||
|
surveyProvider.seedData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
|
@ -18,10 +18,10 @@ namespace DamageAssesment.Api.Surveys.Providers
|
|||||||
this.surveyDbContext = surveysDbContext;
|
this.surveyDbContext = surveysDbContext;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
seedData();
|
//seedData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void seedData()
|
public void seedData()
|
||||||
{
|
{
|
||||||
if (!surveyDbContext.Surveys.Any())
|
if (!surveyDbContext.Surveys.Any())
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user