-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #184 from OpenBracketsCH/development
Add v2 to backend to support geojson and access with multiple options
- Loading branch information
Showing
18 changed files
with
588 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Azure.Storage.Blobs; | ||
using DefikarteBackend.Model; | ||
using Newtonsoft.Json; | ||
using System; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Linq; | ||
|
||
namespace DefikarteBackend.Cache | ||
{ | ||
public class BlobStorageCacheRepositoryV2 : IBlobStorageCacheRepository, IGeoJsonCacheRepository | ||
{ | ||
private readonly BlobContainerClient _containerClient; | ||
private readonly string _blobName; | ||
|
||
public BlobStorageCacheRepositoryV2(BlobContainerClient containerClient, string blobName) | ||
{ | ||
_containerClient = containerClient; | ||
_blobName = blobName; | ||
} | ||
|
||
public async Task CreateAsync(string jsonData, string blobName) | ||
{ | ||
BlobClient blobClient = _containerClient.GetBlobClient(blobName); | ||
await blobClient.UploadAsync(BinaryData.FromString(jsonData)); | ||
} | ||
|
||
public async Task<string> ReadAsync(string blobName) | ||
{ | ||
BlobClient blobClient = _containerClient.GetBlobClient(blobName); | ||
var response = await blobClient.DownloadContentAsync(); | ||
var content = response.Value.Content; | ||
return Encoding.UTF8.GetString(content); | ||
} | ||
|
||
public async Task UpdateAsync(string jsonData, string blobName) | ||
{ | ||
BlobClient blobClient = _containerClient.GetBlobClient(blobName); | ||
await blobClient.UploadAsync(BinaryData.FromString(jsonData), overwrite: true); | ||
} | ||
|
||
public async Task DeleteAsync(string blobName) | ||
{ | ||
BlobClient blobClient = _containerClient.GetBlobClient(blobName); | ||
await blobClient.DeleteIfExistsAsync(); | ||
} | ||
|
||
public async Task<FeatureCollection> GetAsync() | ||
{ | ||
var content = await ReadAsync(_blobName); | ||
return JsonConvert.DeserializeObject<FeatureCollection>(content); | ||
} | ||
|
||
public async Task<Feature> GetByIdAsync(string id) | ||
{ | ||
return (await GetAsync()).Features.FirstOrDefault(x => x.Id == id); | ||
} | ||
|
||
public async Task<bool> TryUpdateCacheAsync(FeatureCollection values) | ||
{ | ||
var success = false; | ||
try | ||
{ | ||
await UpdateAsync(JsonConvert.SerializeObject(values), _blobName); | ||
success = true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex); | ||
} | ||
|
||
return success; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace DefikarteBackend.Cache | ||
{ | ||
public interface IBlobStorageCacheRepository | ||
{ | ||
Task CreateAsync(string jsonData, string blobName); | ||
|
||
Task<string> ReadAsync(string blobName); | ||
|
||
Task UpdateAsync(string jsonData, string blobName); | ||
|
||
Task DeleteAsync(string blobName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using DefikarteBackend.Model; | ||
using System.Threading.Tasks; | ||
|
||
namespace DefikarteBackend.Cache | ||
{ | ||
public interface IGeoJsonCacheRepository | ||
{ | ||
Task<FeatureCollection> GetAsync(); | ||
|
||
Task<Feature> GetByIdAsync(string id); | ||
|
||
Task<bool> TryUpdateCacheAsync(FeatureCollection values); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
backend/Configuration/CustomOpenApiConfigurationOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations; | ||
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums; | ||
using Microsoft.OpenApi.Models; | ||
using System; | ||
|
||
namespace DefikarteBackend.Configuration | ||
{ | ||
public class CustomOpenApiConfigurationOptions : DefaultOpenApiConfigurationOptions | ||
{ | ||
public override OpenApiInfo Info { get; set; } = new OpenApiInfo() | ||
{ | ||
Version = "1.0.0", | ||
Title = "OpenAPI Document for Defikarte.ch-API", | ||
Description = "HTTP APIs used for the Defikarte.ch", | ||
TermsOfService = new Uri("https://defikarte.ch/impressum.html"), | ||
Contact = new OpenApiContact() | ||
{ | ||
Name = "Defikarte.ch-API", | ||
Email = "[email protected]", | ||
Url = new Uri("https://github.com/OpenBracketsCH/defikarte.ch-app/issues"), | ||
}, | ||
}; | ||
|
||
public override OpenApiVersionType OpenApiVersion { get; set; } = OpenApiVersionType.V3; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.