Skip to content

Commit

Permalink
MusicalityLabs storage API was added for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
litichevskiydv committed Jun 28, 2024
1 parent c542f0f commit ba6327f
Show file tree
Hide file tree
Showing 16 changed files with 277 additions and 1 deletion.
35 changes: 34 additions & 1 deletion Byndyusoft.ArchitectureTesting.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Abstractions", "src\Abstrac
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StructurizrParser", "src\StructurizrParser\StructurizrParser.csproj", "{DD449432-9A79-49A7-82CA-27FC3A8A356D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StructurizrParser.Tests", "tests\StructurizrParser.Tests\StructurizrParser.Tests.csproj", "{01B6A354-9B5A-4ACC-92E5-6DED1E88AFF7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StructurizrParser.Tests", "tests\StructurizrParser.Tests\StructurizrParser.Tests.csproj", "{01B6A354-9B5A-4ACC-92E5-6DED1E88AFF7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{3E802220-D845-4B0F-9F98-ACCE8861F90D}"
ProjectSection(SolutionItems) = preProject
examples\Directory.Build.props = examples\Directory.Build.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api.Contracts", "examples\Api.Contracts\Api.Contracts.csproj", "{BE19D907-9BE0-4CED-8460-820774DB30B2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api.Clients", "examples\Api.Clients\Api.Clients.csproj", "{3DC29ABF-B2A5-404C-BA7C-BCEDA02EC357}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataAccess", "examples\DataAccess\DataAccess.csproj", "{E3AFF259-C472-4841-BCE8-2C95042083E3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api", "examples\Api\Api.csproj", "{2C85FA76-AF62-4D6D-89BF-EE9B52AFDC72}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -40,6 +53,22 @@ Global
{01B6A354-9B5A-4ACC-92E5-6DED1E88AFF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01B6A354-9B5A-4ACC-92E5-6DED1E88AFF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01B6A354-9B5A-4ACC-92E5-6DED1E88AFF7}.Release|Any CPU.Build.0 = Release|Any CPU
{BE19D907-9BE0-4CED-8460-820774DB30B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE19D907-9BE0-4CED-8460-820774DB30B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE19D907-9BE0-4CED-8460-820774DB30B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE19D907-9BE0-4CED-8460-820774DB30B2}.Release|Any CPU.Build.0 = Release|Any CPU
{3DC29ABF-B2A5-404C-BA7C-BCEDA02EC357}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3DC29ABF-B2A5-404C-BA7C-BCEDA02EC357}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3DC29ABF-B2A5-404C-BA7C-BCEDA02EC357}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3DC29ABF-B2A5-404C-BA7C-BCEDA02EC357}.Release|Any CPU.Build.0 = Release|Any CPU
{E3AFF259-C472-4841-BCE8-2C95042083E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E3AFF259-C472-4841-BCE8-2C95042083E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E3AFF259-C472-4841-BCE8-2C95042083E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E3AFF259-C472-4841-BCE8-2C95042083E3}.Release|Any CPU.Build.0 = Release|Any CPU
{2C85FA76-AF62-4D6D-89BF-EE9B52AFDC72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C85FA76-AF62-4D6D-89BF-EE9B52AFDC72}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C85FA76-AF62-4D6D-89BF-EE9B52AFDC72}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C85FA76-AF62-4D6D-89BF-EE9B52AFDC72}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -48,6 +77,10 @@ Global
{0B01C1F0-B144-4772-872A-D056C3F03F9A} = {9D5D61C4-D494-4124-A184-59C12C2BB2BC}
{DD449432-9A79-49A7-82CA-27FC3A8A356D} = {9D5D61C4-D494-4124-A184-59C12C2BB2BC}
{01B6A354-9B5A-4ACC-92E5-6DED1E88AFF7} = {ECEA017E-7CB0-4E1C-8D29-9E38D39CD3C8}
{BE19D907-9BE0-4CED-8460-820774DB30B2} = {3E802220-D845-4B0F-9F98-ACCE8861F90D}
{3DC29ABF-B2A5-404C-BA7C-BCEDA02EC357} = {3E802220-D845-4B0F-9F98-ACCE8861F90D}
{E3AFF259-C472-4841-BCE8-2C95042083E3} = {3E802220-D845-4B0F-9F98-ACCE8861F90D}
{2C85FA76-AF62-4D6D-89BF-EE9B52AFDC72} = {3E802220-D845-4B0F-9F98-ACCE8861F90D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A79E4AD9-244B-42E6-BD30-255B9C3DEC46}
Expand Down
15 changes: 15 additions & 0 deletions examples/Api.Clients/Api.Clients.csproj
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>
22 changes: 22 additions & 0 deletions examples/Api.Clients/SoundSignaturesApiClient.cs
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);
}
}
8 changes: 8 additions & 0 deletions examples/Api.Clients/StorageApiSettings.cs
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
{
}
}
11 changes: 11 additions & 0 deletions examples/Api.Contracts/Api.Contracts.csproj
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 examples/Api.Contracts/SoundSignatures/ISoundSignaturesApi.cs
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);
}
}
13 changes: 13 additions & 0 deletions examples/Api.Contracts/SoundSignatures/SoundSignature.cs
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

View workflow job for this annotation

GitHub Actions / push (ubuntu-latest)

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 11 in examples/Api.Contracts/SoundSignatures/SoundSignature.cs

View workflow job for this annotation

GitHub Actions / push (windows-latest)

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 11 in examples/Api.Contracts/SoundSignatures/SoundSignature.cs

View workflow job for this annotation

GitHub Actions / push (macos-latest)

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}
}
16 changes: 16 additions & 0 deletions examples/Api/Api.csproj
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>
14 changes: 14 additions & 0 deletions examples/Api/Program.cs
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();
}
}
14 changes: 14 additions & 0 deletions examples/Api/Properties/launchSettings.json
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"
}
}
}
}
37 changes: 37 additions & 0 deletions examples/Api/Startup.cs
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());
}
}
11 changes: 11 additions & 0 deletions examples/Api/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ConnectionStrings": {
"Main": "Server="
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions examples/Api/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
15 changes: 15 additions & 0 deletions examples/DataAccess/DataAccess.csproj
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 examples/DataAccess/SoundSignatures/SoundSignaturesRepository.cs
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
);
}
}
12 changes: 12 additions & 0 deletions examples/Directory.Build.props
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>

0 comments on commit ba6327f

Please sign in to comment.