-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MusicalityLabs storage API was added for examples
- Loading branch information
1 parent
c542f0f
commit ba6327f
Showing
16 changed files
with
277 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Byndyusoft.ApiClient" Version="1.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Api.Contracts\Api.Contracts.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,22 @@ | ||
namespace MusicalityLabs.Storage.Api.Clients | ||
{ | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Byndyusoft.ApiClient; | ||
using Contracts.SoundSignatures; | ||
using Microsoft.Extensions.Options; | ||
|
||
public class SoundSignaturesApiClient : BaseClient, ISoundSignaturesApi | ||
{ | ||
private const string ApiRoutePrefix = "api/soundSignatures"; | ||
|
||
public SoundSignaturesApiClient(HttpClient client, IOptions<StorageApiSettings> apiSettings) | ||
: base(client, apiSettings) | ||
{ | ||
} | ||
|
||
public Task<SoundSignature> Save(SoundSignature soundSignature, CancellationToken cancellationToken) | ||
=> PostAsync<SoundSignature>(ApiRoutePrefix, soundSignature, cancellationToken); | ||
} | ||
} |
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,8 @@ | ||
namespace MusicalityLabs.Storage.Api.Clients | ||
{ | ||
using Byndyusoft.ApiClient; | ||
|
||
public class StorageApiSettings : ApiClientSettings | ||
{ | ||
} | ||
} |
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,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
10 changes: 10 additions & 0 deletions
10
examples/Api.Contracts/SoundSignatures/ISoundSignaturesApi.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,10 @@ | ||
namespace MusicalityLabs.Storage.Api.Contracts.SoundSignatures | ||
{ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
public interface ISoundSignaturesApi | ||
{ | ||
Task<SoundSignature> Save(SoundSignature soundSignature, CancellationToken cancellationToken); | ||
} | ||
} |
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,13 @@ | ||
namespace MusicalityLabs.Storage.Api.Contracts.SoundSignatures | ||
{ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
public class SoundSignature | ||
{ | ||
[Required] | ||
public int? Id { get; set; } | ||
|
||
[Required] | ||
public string Name { get; set; } | ||
Check warning on line 11 in examples/Api.Contracts/SoundSignatures/SoundSignature.cs GitHub Actions / push (ubuntu-latest)
Check warning on line 11 in examples/Api.Contracts/SoundSignatures/SoundSignature.cs GitHub Actions / push (windows-latest)
|
||
} | ||
} |
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,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Byndyusoft.Data.Relational" Version="0.8.0" /> | ||
<PackageReference Include="Npgsql" Version="4.1.14" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\DataAccess\DataAccess.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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 @@ | ||
namespace MusicalityLabs.Storage.Api | ||
{ | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
internal class Program | ||
{ | ||
public static void Main(string[] args) | ||
=> Host.CreateDefaultBuilder(args) | ||
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>()) | ||
.Build() | ||
.Run(); | ||
} | ||
} |
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 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/launchsettings.json", | ||
"profiles": { | ||
"Api": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": false, | ||
"applicationUrl": "http://localhost:5131", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
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,37 @@ | ||
namespace MusicalityLabs.Storage.Api | ||
{ | ||
using System; | ||
using DataAccess.SoundSignatures; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Npgsql; | ||
|
||
public class Startup | ||
{ | ||
private readonly IConfiguration _configuration; | ||
|
||
public Startup(IConfiguration configuration) | ||
{ | ||
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); | ||
} | ||
|
||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services | ||
.AddControllers(); | ||
|
||
services | ||
.AddRouting(o => o.LowercaseUrls = true); | ||
|
||
services | ||
.AddRelationalDb(NpgsqlFactory.Instance, _configuration.GetConnectionString("Main")) | ||
.AddSingleton<SoundSignaturesRepository>(); | ||
} | ||
|
||
public void Configure(IApplicationBuilder app) | ||
=> app | ||
.UseRouting() | ||
.UseEndpoints(endpoints => endpoints.MapControllers()); | ||
} | ||
} |
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,11 @@ | ||
{ | ||
"ConnectionStrings": { | ||
"Main": "Server=" | ||
}, | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
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,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Byndyusoft.Data.Relational.Abstractions" Version="0.8.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Api.Contracts\Api.Contracts.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
36 changes: 36 additions & 0 deletions
36
examples/DataAccess/SoundSignatures/SoundSignaturesRepository.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,36 @@ | ||
namespace MusicalityLabs.Storage.DataAccess.SoundSignatures | ||
{ | ||
using System.Data.Common; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Api.Contracts.SoundSignatures; | ||
using Byndyusoft.Data.Relational; | ||
|
||
public class SoundSignaturesRepository : DbSessionConsumer | ||
{ | ||
public SoundSignaturesRepository(IDbSessionAccessor sessionAccessor) : base(sessionAccessor) | ||
{ | ||
} | ||
|
||
public Task<SoundSignature> Save(SoundSignature soundSignature, CancellationToken cancellationToken) | ||
=> DbSession.QuerySingleAsync<SoundSignature>( | ||
@" | ||
insert into public.sound_signatures | ||
( | ||
id, | ||
name | ||
) | ||
values | ||
( | ||
@Id | ||
, @Name | ||
) | ||
on conflict (id) do update | ||
set name = excluded.name | ||
returning *; | ||
", | ||
soundSignature, | ||
cancellationToken: cancellationToken | ||
); | ||
} | ||
} |
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,12 @@ | ||
<Project> | ||
|
||
<PropertyGroup> | ||
<VersionPrefix>1.0.0</VersionPrefix> | ||
<AssemblyName>MusicalityLabs.Storage.$(MSBuildProjectName)</AssemblyName> | ||
<RootNamespace>MusicalityLabs.Storage.$(MSBuildProjectName)</RootNamespace> | ||
<LangVersion>9</LangVersion> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
</Project> |