-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathScrapeConfigService.cs
More file actions
59 lines (51 loc) · 2.51 KB
/
Copy pathScrapeConfigService.cs
File metadata and controls
59 lines (51 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using Microsoft.Extensions.Options;
using ProductScraper.Common.Naming;
using ProductScraper.Models.EntityModels;
using ProductScraper.Models.Extensions;
using ProductScraper.Models.ViewModels;
using ProductScraper.Services.Interfaces;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ProductScraper.Services.Implementations
{
public class ScrapeConfigService : IScrapeConfigService
{
private readonly IOptions<AppSettings> _settings;
private readonly IHttpHandlerService _httpHandlerService;
public ScrapeConfigService(IOptions<AppSettings> settings,
IHttpHandlerService httpHandlerService)
{
_settings = settings;
_httpHandlerService = httpHandlerService;
}
public async Task AddAsync(ScrapeConfig scrapeConfig)
{
scrapeConfig.Id = DateTime.Now.Ticks;
scrapeConfig.RowKey = scrapeConfig.Id.ToString();
scrapeConfig.PartitionKey = scrapeConfig.URL.ToCoreUrl();
string url = _settings.Value.AzureFunctionURL + FunctionName.AddScrapeConfig + "?code=" + _settings.Value.AzureFunctionCode;
await _httpHandlerService.HandlePostRequest(url, scrapeConfig);
}
public async Task DeleteAsync(string partitionKey, string rowKey)
{
string url = _settings.Value.AzureFunctionURL + FunctionName.DeleteScrapeConfig + $"/{partitionKey}/{rowKey}?code=" + _settings.Value.AzureFunctionCode;
await _httpHandlerService.HandlePostRequest(url, null);
}
public async Task<IList<ScrapeConfig>> GetAllAsync()
{
string url = _settings.Value.AzureFunctionURL + FunctionName.GetAllScrapeConfigs + "?code=" + _settings.Value.AzureFunctionCode;
return await _httpHandlerService.HandleGetRequest<IList<ScrapeConfig>>(url);
}
public async Task<ScrapeConfig> GetDetailsAsync(string partitionKey, string rowKey)
{
string url = _settings.Value.AzureFunctionURL + FunctionName.GetScrapeConfig + $"/{partitionKey}/{rowKey}?code=" + _settings.Value.AzureFunctionCode;
return await _httpHandlerService.HandleGetRequest<ScrapeConfig>(url);
}
public async Task UpdateAsync(ScrapeConfig scrapeConfig)
{
string url = _settings.Value.AzureFunctionURL + FunctionName.UpdateScrapeConfig + "?code=" + _settings.Value.AzureFunctionCode;
await _httpHandlerService.HandlePostRequest(url, scrapeConfig);
}
}
}