Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
!**/.gitignore
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**
32 changes: 32 additions & 0 deletions .github/workflows/addressdata-backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build and deploy .NET application to container app addressdata-backend
on:
push:
branches:
- main
env:
CONTAINER_APP_CONTAINER_NAME: addressdatabackend
CONTAINER_APP_NAME: addressdata-backend
CONTAINER_APP_RESOURCE_GROUP_NAME: addressdata-rg
CONTAINER_REGISTRY_LOGIN_SERVER: containerplace.azurecr.io
DOCKER_FILE_PATH: src/AddressData.WebApi/Dockerfile
PROJECT_NAME_FOR_DOCKER: addressdatawebapi
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout to the branch
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to container registry
uses: docker/login-action@v3
with:
registry: ${{ env.CONTAINER_REGISTRY_LOGIN_SERVER }}
username: ${{ secrets.containerplace_USERNAME_BB72 }}
password: ${{ secrets.containerplace_PASSWORD_BB72 }}
- name: Build and push container image to registry
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ env.CONTAINER_REGISTRY_LOGIN_SERVER }}/${{ env.PROJECT_NAME_FOR_DOCKER }}:${{ github.sha }}
file: ${{ env.DOCKER_FILE_PATH }}
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
6 changes: 3 additions & 3 deletions src/AddressData.Core/AddressData.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
Expand All @@ -10,8 +10,8 @@


<ItemGroup>
<PackageReference Include="CsvHelper" Version="33.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.2" />
<PackageReference Include="CsvHelper" Version="33.1.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.9" />
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions src/AddressData.Core/Services/Interfaces/IDocumentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace AddressData.Core.Services.Interfaces;

public interface IDocumentService
{
Task<AddressDocumentDomainModel> InsertAsync(IEnumerable writeModel, LocationDomainModel location);
Task<AddressDocumentDomainModel?> GetAsync(LocationDomainModel location);
Task<IEnumerable<AddressDocumentDomainModel>> GetAllAsync();
public Task<AddressDocumentDomainModel> InsertAsync(IEnumerable writeModel, LocationDomainModel location);
public Task<AddressDocumentDomainModel?> GetAsync(LocationDomainModel location);
public Task<IEnumerable<AddressDocumentDomainModel>> GetAllAsync();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ namespace AddressData.Core.Services.Interfaces;

public interface IOverpassTurboService
{
Task<IEnumerable<CityInfoDomainModel>?> GetCities();
Task<CityInfoDomainModel?> GetCity(long areaId);
Task<LocationDomainModel?> GetLocation(long areaId);
Task<IEnumerable<AddressesDomainModel>?> GetAddresses(long areaId);
public Task<IEnumerable<CityInfoDomainModel>?> GetCities();
public Task<CityInfoDomainModel?> GetCity(long areaId);
public Task<LocationDomainModel?> GetLocation(long areaId);
public Task<IEnumerable<AddressesDomainModel>?> GetAddresses(long areaId);
}
4 changes: 2 additions & 2 deletions src/AddressData.Core/Services/Interfaces/ISeedingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace AddressData.Core.Services.Interfaces;

public interface ISeedingService
{
Task<IEnumerable<AddressDocumentDomainModel>> RunSeeding(long? limit);
Task<AddressDocumentDomainModel> AddCity(long areaId);
public Task<IEnumerable<AddressDocumentDomainModel>> RunSeeding(long? limit);
public Task<AddressDocumentDomainModel> AddCity(long areaId);
}
4 changes: 1 addition & 3 deletions src/AddressData.Core/Services/OverpassTurboService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@
using var streamReader = new StreamReader(stream);
using var csvReader = new CsvReader(streamReader, CultureInfo.InvariantCulture);

return csvReader
.GetRecords<T>()
.ToList();
return [.. csvReader.GetRecords<T>()];
}
catch (Exception ex)
{
Expand Down Expand Up @@ -128,8 +126,8 @@

private static StateCountryDomainModel? ParseJson(JsonDocument jsonDocument)
{
string countryName = null;

Check warning on line 129 in src/AddressData.Core/Services/OverpassTurboService.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
string stateName = null;

Check warning on line 130 in src/AddressData.Core/Services/OverpassTurboService.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.

// TODO: HACK: Manually parsing JSON here. There must be a better way...
var elements = jsonDocument.RootElement.GetProperty(Constants.OverpassTurboResponseElements);
Expand All @@ -144,22 +142,22 @@
{
if (tags.TryGetProperty(Constants.OverpassTurboResponseEnglishName, out var stateEnglish))
{
stateName = stateEnglish.GetString();

Check warning on line 145 in src/AddressData.Core/Services/OverpassTurboService.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
}
else if (tags.TryGetProperty(Constants.OverpassTurboResponseName, out var state))
{
stateName = state.GetString();

Check warning on line 149 in src/AddressData.Core/Services/OverpassTurboService.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
}
}
else if (adminLevel.GetString() == Constants.OverpassTurboResponseCountryAdministrationLevel)
{
if (tags.TryGetProperty(Constants.OverpassTurboResponseEnglishName, out var countryEnglish))
{
countryName = countryEnglish.GetString();

Check warning on line 156 in src/AddressData.Core/Services/OverpassTurboService.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
}
else if (tags.TryGetProperty(Constants.OverpassTurboResponseName, out var country))
{
countryName = country.GetString();

Check warning on line 160 in src/AddressData.Core/Services/OverpassTurboService.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
}
}
}
Expand Down
20 changes: 11 additions & 9 deletions src/AddressData.WebApi/AddressData.WebApi.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<UserSecretsId>fa62b18b-f3b6-4352-bd0c-b9289770d19d</UserSecretsId>
<DockerfileContext>..\..</DockerfileContext>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="9.0.2" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.2" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.11.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.11.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.11.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.11.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="9.0.9" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="9.0.0" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.12.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.12.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.12.0" />
</ItemGroup>


Expand Down
30 changes: 30 additions & 0 deletions src/AddressData.WebApi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["src/AddressData.WebApi/AddressData.WebApi.csproj", "src/AddressData.WebApi/"]
COPY ["src/AddressData.Core/AddressData.Core.csproj", "src/AddressData.Core/"]
RUN dotnet restore "./src/AddressData.WebApi/AddressData.WebApi.csproj"
COPY . .
WORKDIR "/src/src/AddressData.WebApi"
RUN dotnet build "./AddressData.WebApi.csproj" -c $BUILD_CONFIGURATION -o /app/build

# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./AddressData.WebApi.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "AddressData.WebApi.dll"]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>AddressData.FunctionalTests</RootNamespace>
Expand All @@ -13,13 +13,13 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.13" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.1" />
<PackageReference Include="Reqnroll.NUnit" Version="2.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.22.1" />
<PackageReference Include="Reqnroll.NUnit" Version="3.0.2" />
<PackageReference Include="RestSharp" Version="112.1.0" />
<PackageReference Include="nunit" Version="4.3.2" />
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
<PackageReference Include="nunit" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="5.1.0" />
</ItemGroup>


Expand Down
12 changes: 7 additions & 5 deletions tests/AddressData.UnitTests/AddressData.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
Expand All @@ -11,18 +11,20 @@

<ItemGroup>
<PackageReference Include="AutoFixture" Version="4.18.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit3TestAdapter" Version="5.0.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.6.0">
<PackageReference Include="NUnit" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="5.1.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.10.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
public void ErrorModelConstructedWithExceptionExceptionPropertiesMatchModelProperties(Type exceptionType, string message)
{
// Arrange
var comparedException = (Exception)Activator.CreateInstance(exceptionType, message);

Check warning on line 21 in tests/AddressData.UnitTests/Models/ErrorModelApiResponseTests.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.

// Act
var errorModel = new ErrorModelApiResponse(comparedException);
Assert.Multiple(() =>
using (Assert.EnterMultipleScope())
{

// Assert
Assert.That(errorModel.Type, Is.EqualTo(comparedException.GetType().Name));
Assert.That(errorModel.Message, Is.EqualTo(comparedException.Message));
Assert.That(errorModel.StackTrace, Is.EqualTo(comparedException.ToString()));
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public async Task GetAsyncReturnsZeroSizeWhenCsvHasOnlyHeader()

// Assert
Assert.That(doc, Is.Not.Null);
Assert.That(doc!.Size, Is.EqualTo(0));
Assert.That(doc!.Size, Is.Zero);
}

[Test]
Expand Down
Loading