forked from MDCPS/DamageAssessment_Backend
		
	merged azure and user access changes to docker azure branch
This commit is contained in:
		| @ -1,5 +1,6 @@ | ||||
| using DamageAssesment.Api.Responses.Interfaces; | ||||
| using DamageAssesment.Api.Responses.Models; | ||||
| using Microsoft.Extensions.Primitives; | ||||
| using Newtonsoft.Json; | ||||
|  | ||||
|  | ||||
| @ -10,11 +11,11 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|         public AnswerServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<AnswerServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Answer"), configuration.GetValue<string>("EndPointSettings:AnswerUrlBase")) | ||||
|         { | ||||
|         } | ||||
|         public async Task<List<Answer>> getAnswersAsync() | ||||
|         public async Task<List<Answer>> getAnswersAsync(string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var answers = JsonConvert.DeserializeObject<List<Answer>>(responseJsonString); | ||||
|  | ||||
|                 if (answers == null || !answers.Any()) | ||||
| @ -28,12 +29,12 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task<List<Answer>> GetAnswersByResponseIdAsync(int responseId) | ||||
|         public async Task<List<Answer>> GetAnswersByResponseIdAsync(int responseId, string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:AnswerByResponse"), responseId); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token); | ||||
|                 var answers = JsonConvert.DeserializeObject<List<Answer>>(responseJsonString); | ||||
|  | ||||
|                 if (answers == null || !answers.Any()) | ||||
| @ -47,12 +48,12 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task<Answer> PostAnswersAsync(Answer answer) | ||||
|         public async Task<Answer> PostAnswersAsync(Answer answer, string token ) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var requestJsonString = JsonConvert.SerializeObject(answer); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Post, url, requestJsonString); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Post, url, requestJsonString, token); | ||||
|                 var answers = JsonConvert.DeserializeObject<Answer>(responseJsonString); | ||||
|  | ||||
|                 if (answers == null) | ||||
|  | ||||
| @ -10,11 +10,11 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         public async Task<List<Attachment>> getAttachmentsAsync() | ||||
|         public async Task<List<Attachment>> getAttachmentsAsync(string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token); | ||||
|                 var attachments = JsonConvert.DeserializeObject<List<Attachment>>(responseJsonString); | ||||
|  | ||||
|                 if (attachments == null || !attachments.Any()) | ||||
| @ -28,12 +28,12 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task<IEnumerable<Attachment>> PostAttachmentsAsync(AttachmentInfo attachmentInfo) | ||||
|         public async Task<IEnumerable<Attachment>> PostAttachmentsAsync(AttachmentInfo attachmentInfo, string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var requestJsonString = JsonConvert.SerializeObject(attachmentInfo); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Post, url, requestJsonString); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Post, url, requestJsonString, token); | ||||
|                 var attachments = JsonConvert.DeserializeObject<IEnumerable<Attachment>>(responseJsonString); | ||||
|  | ||||
|                 if (attachments == null) | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| using DamageAssesment.Api.Responses.Interfaces; | ||||
| using DamageAssesment.Api.Responses.Interfaces; | ||||
| using DamageAssesment.Api.Responses.Models; | ||||
| using Microsoft.AspNetCore.Mvc.Routing; | ||||
| using Newtonsoft.Json; | ||||
| @ -11,11 +11,11 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         public async Task<List<Employee>> getEmployeesAsync() | ||||
|         public async Task<List<Employee>> getEmployeesAsync(string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token); | ||||
|                 var employees = JsonConvert.DeserializeObject<List<Employee>>(responseJsonString); | ||||
|  | ||||
|                 if (employees == null || !employees.Any()) | ||||
| @ -29,12 +29,12 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task<Employee> getEmployeeAsync(int employeeId) | ||||
|         public async Task<Employee> getEmployeeAsync(int employeeId, string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:EmployeeById"), employeeId);  | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var employee = JsonConvert.DeserializeObject<Employee>(responseJsonString); | ||||
|  | ||||
|                 if (employee == null) | ||||
|  | ||||
| @ -1,4 +1,5 @@ | ||||
| using DamageAssesment.Api.Responses.Interfaces; | ||||
| using DamageAssesment.Api.Responses.Interfaces; | ||||
| using DamageAssesment.Api.Responses.Models; | ||||
| using System.Net.Http.Headers; | ||||
| using System.Text; | ||||
|  | ||||
| @ -14,20 +15,18 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|             this.httpClient = httpClient; | ||||
|             this.logger = logger; | ||||
|         } | ||||
|         public async Task<string> SendAsync(HttpMethod method, string url, string JsonInput) | ||||
|         public async Task<string> SendAsync(HttpMethod method, string url, string JsonInput, string token) | ||||
|         { | ||||
|             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); | ||||
|                 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(); | ||||
|  | ||||
| @ -10,11 +10,11 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         public async Task<List<Location>> getLocationsAsync() | ||||
|         public async Task<List<Location>> getLocationsAsync(string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var locations = JsonConvert.DeserializeObject<List<Location>>(responseJsonString); | ||||
|  | ||||
|                 if (locations == null || !locations.Any()) | ||||
|  | ||||
| @ -10,11 +10,11 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         public async Task<List<Question>> getQuestionsAsync() | ||||
|         public async Task<List<Question>> getQuestionsAsync(string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token); | ||||
|                 var questions = JsonConvert.DeserializeObject<List<Question>>(responseJsonString); | ||||
|  | ||||
|                 if (questions == null || !questions.Any()) | ||||
| @ -28,12 +28,12 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task<List<SurveyQuestions>> getSurveyQuestionsAsync(int surveyId) | ||||
|         public async Task<List<SurveyQuestions>> getSurveyQuestionsAsync(int surveyId, string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:SurveyQuestion"), surveyId); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var questions = JsonConvert.DeserializeObject<List<SurveyQuestions>>(responseJsonString); | ||||
|  | ||||
|                 if (questions == null || !questions.Any()) | ||||
| @ -48,12 +48,12 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|         } | ||||
|  | ||||
|  | ||||
|         public async Task<Question> getQuestionsAsync(int questionId) | ||||
|         public async Task<Question> getQuestionsAsync(int questionId, string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:QuestionById"), questionId); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var question = JsonConvert.DeserializeObject<Question>(responseJsonString); | ||||
|  | ||||
|                 if (question == null) | ||||
|  | ||||
| @ -9,11 +9,11 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|         public RegionServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<RegionServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Region"), configuration.GetValue<string>("EndPointSettings:LocationUrlBase")) | ||||
|         { | ||||
|         } | ||||
|         public async Task<List<Region>> getRegionsAsync() | ||||
|         public async Task<List<Region>> getRegionsAsync(string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var regions = JsonConvert.DeserializeObject<List<Region>>(responseJsonString); | ||||
|  | ||||
|                 if (regions == null || !regions.Any()) | ||||
|  | ||||
| @ -4,19 +4,17 @@ using Newtonsoft.Json; | ||||
|  | ||||
| namespace DamageAssesment.Api.Responses.Services | ||||
| { | ||||
|     public class SurveyServiceProvider : ServiceProviderBase, ISurveyServiceProvider | ||||
|     public class SurveyServiceProvider :ServiceProviderBase, ISurveyServiceProvider | ||||
|     { | ||||
|         public SurveyServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<EmployeeServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Survey"), configuration.GetValue<string>("EndPointSettings:SurveyUrlBase")) | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         public async Task<List<Survey>> getSurveysAsync(string language) | ||||
|         public async Task<List<Survey>> getSurveysAsync(string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 if (!string.IsNullOrEmpty(language)) | ||||
|                     url = url + "/" + language; | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var surveys = JsonConvert.DeserializeObject<List<Survey>>(responseJsonString); | ||||
|  | ||||
|                 if (surveys == null || !surveys.Any()) | ||||
| @ -30,15 +28,15 @@ namespace DamageAssesment.Api.Responses.Services | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         public async Task<Survey> getSurveyAsync(int surveyId) | ||||
|         public async Task<Survey> getSurveyAsync(int surveyId, string token) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:SurveyById"), surveyId); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); | ||||
|                 var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); | ||||
|                 var survey = JsonConvert.DeserializeObject<Survey>(responseJsonString); | ||||
|  | ||||
|                 if (survey == null) | ||||
|                 if (survey == null ) | ||||
|                     return null; | ||||
|                 else return survey; | ||||
|             } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user