Skip to content

Commit

Permalink
Simplify backend project structure and namespaces (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-lerch authored May 22, 2024
1 parent f9caa72 commit 90ea3b4
Show file tree
Hide file tree
Showing 147 changed files with 438 additions and 464 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore NuGet packages
Expand All @@ -27,7 +27,7 @@ jobs:
# Launch and prepare MySQL server
sudo systemctl start mysql.service
dotnet run -c Release --no-build --project server/src/Korga.Server -- database create
dotnet run -c Release --no-build --project server/Korga -- database create
- name: Test
run: dotnet test -c Release --no-build --verbosity normal

Expand Down
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ FROM mcr.microsoft.com/dotnet/sdk:8.0 AS server
WORKDIR /app

# Copy csproj and restore as distinct layers
COPY server/src/Korga.Server/Korga.Server.csproj ./Korga.Server/
RUN dotnet restore Korga.Server
COPY server/Korga/Korga.csproj ./Korga/
RUN dotnet restore Korga

# Copy everything else and build
COPY server/src ./
RUN dotnet publish -c Release -o /app/out Korga.Server
COPY server ./
RUN dotnet publish -c Release -o /app/out Korga

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app

COPY --from=server /app/out .
COPY --from=webapp /app/dist wwwroot/
ENTRYPOINT ["dotnet", "Korga.Server.dll"]
ENTRYPOINT ["dotnet", "Korga.dll"]
22 changes: 10 additions & 12 deletions Korga.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,26 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.1.32210.238
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Korga.Server", "server\src\Korga.Server\Korga.Server.csproj", "{E1C5CDEB-C3D5-4BE1-B823-5FD650AB1D08}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Korga", "server\Korga\Korga.csproj", "{E1C5CDEB-C3D5-4BE1-B823-5FD650AB1D08}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "server-src", "server-src", "{565B1C55-E3A4-4B7E-9F8E-EF14AA917618}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "server", "server", "{565B1C55-E3A4-4B7E-9F8E-EF14AA917618}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_", "_", "{28945597-DB66-4C1C-A2DB-C5ACB5ED4DD4}"
ProjectSection(SolutionItems) = preProject
Dockerfile = Dockerfile
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "server-tests", "server-tests", "{86DB2784-54F6-43CC-8F86-94E059B7DE59}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Korga.Server.Tests", "server\tests\Korga.Server.Tests\Korga.Server.Tests.csproj", "{2A484A88-F6BD-4B36-92C8-0675ADDD8CDB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{2ED6D7FB-8B8A-4139-98C3-854E00A38490}"
ProjectSection(SolutionItems) = preProject
docs\docker-compose.yml = docs\docker-compose.yml
docs\email-processing-pipeline.md = docs\email-processing-pipeline.md
docs\frontend.md = docs\frontend.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Korga.Core", "server\src\Korga.Core\Korga.Core.csproj", "{D1CEB029-9AFB-4464-BF93-DBA6216B4128}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChurchTools", "server\ChurchTools\ChurchTools.csproj", "{D1CEB029-9AFB-4464-BF93-DBA6216B4128}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Korga.Tests", "server\Korga.Tests\Korga.Tests.csproj", "{EFA087E1-C034-44A2-B1C1-DEDCF996FEB1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -36,22 +34,22 @@ Global
{E1C5CDEB-C3D5-4BE1-B823-5FD650AB1D08}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1C5CDEB-C3D5-4BE1-B823-5FD650AB1D08}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1C5CDEB-C3D5-4BE1-B823-5FD650AB1D08}.Release|Any CPU.Build.0 = Release|Any CPU
{2A484A88-F6BD-4B36-92C8-0675ADDD8CDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A484A88-F6BD-4B36-92C8-0675ADDD8CDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A484A88-F6BD-4B36-92C8-0675ADDD8CDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A484A88-F6BD-4B36-92C8-0675ADDD8CDB}.Release|Any CPU.Build.0 = Release|Any CPU
{D1CEB029-9AFB-4464-BF93-DBA6216B4128}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D1CEB029-9AFB-4464-BF93-DBA6216B4128}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D1CEB029-9AFB-4464-BF93-DBA6216B4128}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D1CEB029-9AFB-4464-BF93-DBA6216B4128}.Release|Any CPU.Build.0 = Release|Any CPU
{EFA087E1-C034-44A2-B1C1-DEDCF996FEB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EFA087E1-C034-44A2-B1C1-DEDCF996FEB1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EFA087E1-C034-44A2-B1C1-DEDCF996FEB1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EFA087E1-C034-44A2-B1C1-DEDCF996FEB1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E1C5CDEB-C3D5-4BE1-B823-5FD650AB1D08} = {565B1C55-E3A4-4B7E-9F8E-EF14AA917618}
{2A484A88-F6BD-4B36-92C8-0675ADDD8CDB} = {86DB2784-54F6-43CC-8F86-94E059B7DE59}
{D1CEB029-9AFB-4464-BF93-DBA6216B4128} = {565B1C55-E3A4-4B7E-9F8E-EF14AA917618}
{EFA087E1-C034-44A2-B1C1-DEDCF996FEB1} = {565B1C55-E3A4-4B7E-9F8E-EF14AA917618}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {638049AA-35BE-4FFE-8370-373448555D24}
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Once configured, Korga automatically synchronizes people and groups from ChurchT
There is no Web UI available yet to manage distribution lists so you must stick to the CLI inside the Docker container:

```
./Korga.Server distribution-list create --group 137 kids
./Korga distribution-list create --group 137 kids
```

This command creates a distribution list _[email protected]_ which forwards emails to every member of group #137.
Expand All @@ -32,7 +32,7 @@ Korga has multiple modules that must be enabled via configuration to use them:

Configuration can set as enviroment variables or by creating a custom config file.
I recommend to use environment variables and will explain them in the following sections.
However, if you prefer a config file, copy the default [appsettings.json](server/src/Korga.Server/appsettings.json), edit it as required, and mount it at `/app/appsettings.json`.
However, if you prefer a config file, copy the default [appsettings.json](server/src/Korga/appsettings.json), edit it as required, and mount it at `/app/appsettings.json`.

### OpenID Connect authentication

Expand Down
9 changes: 9 additions & 0 deletions server/ChurchTools/ChurchTools.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>ChurchTools</RootNamespace>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Korga.ChurchTools.Api;
using ChurchTools.Model;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -10,7 +10,7 @@
using System.Threading;
using System.Threading.Tasks;

namespace Korga.ChurchTools;
namespace ChurchTools;

public class ChurchToolsApi : IChurchToolsApi, IDisposable
{
Expand Down Expand Up @@ -164,7 +164,7 @@ private async ValueTask<T> InternalGetNonPaged<T>(string path, CancellationToken

private async ValueTask<List<T>> InternalGetAllPages<T>(string path, string? query, CancellationToken cancellationToken)
{
List<T> items = new();
List<T> items = [];
PaginatedResponse<T[]>? response;
int page = 0;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Korga.ChurchTools.Api;
using ChurchTools.Model;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Korga.ChurchTools;
namespace ChurchTools;

public interface IChurchToolsApi : IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;

namespace Korga.ChurchTools.Api;
namespace ChurchTools.Model;

public class Event
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Korga.ChurchTools.Api;
namespace ChurchTools.Model;

public class GlobalPermissions
{
Expand Down
23 changes: 23 additions & 0 deletions server/ChurchTools/Model/Group.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Text.Json;

namespace ChurchTools.Model;

public class Group : IIdentifiable<int>
{
public Group(int id, Guid guid, string name, Dictionary<string, JsonElement> information)
{
Id = id;
Guid = guid;
Name = name;
Information = information;
}

public int Id { get; set; }
public Guid Guid { get; set; }
public string Name { get; set; }
public Dictionary<string, JsonElement> Information { get; set; }
public int GroupTypeId => Information["groupTypeId"].GetInt32();
public int GroupStatusId => Information["groupStatusId"].GetInt32();
}
19 changes: 19 additions & 0 deletions server/ChurchTools/Model/GroupMember.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace ChurchTools.Model;

public class GroupMember : IIdentifiable<long>
{
public GroupMember(int personId, int groupId, int groupTypeRoleId, string groupMemberStatus)
{
PersonId = personId;
GroupId = groupId;
GroupTypeRoleId = groupTypeRoleId;
GroupMemberStatus = groupMemberStatus;
}

public int PersonId { get; set; }
public int GroupId { get; set; }
public int GroupTypeRoleId { get; set; }
public string GroupMemberStatus { get; set; }

long IIdentifiable<long>.Id => (long)PersonId << 32 | (long)GroupId;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Korga.ChurchTools;
namespace ChurchTools.Model;

public enum GroupMemberStatus
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;

namespace Korga;
namespace ChurchTools.Model;

public interface IIdentifiable<TKey> where TKey : IComparable<TKey>
{
TKey Id { get; }
TKey Id { get; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Korga.ChurchTools.Api;
namespace ChurchTools.Model;

public class Login
{
Expand Down
35 changes: 35 additions & 0 deletions server/ChurchTools/Model/PaginatedResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace ChurchTools.Model;

public class PaginatedResponse<T>
{
public PaginatedResponse(T data, PaginatedResponse<T>.ListInformation meta)
{
Data = data;
Meta = meta;
}

public T Data { get; set; }
public ListInformation Meta { get; set; }

public class ListInformation
{
public ListInformation(int count, int all, PaginatedResponse<T>.Pagination pagination)
{
Count = count;
All = all;
Pagination = pagination;
}

public int Count { get; set; }
public int All { get; set; }
public Pagination Pagination { get; set; }
}

public class Pagination
{
public int Total { get; set; }
public int Limit { get; set; }
public int Current { get; set; }
public int LastPage { get; set; }
}
}
23 changes: 23 additions & 0 deletions server/ChurchTools/Model/Person.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Generic;

namespace ChurchTools.Model;

public class Person : IIdentifiable<int>
{
public Person(int id, int statusId, List<int> departmentIds, string firstName, string lastName, string email)
{
Id = id;
StatusId = statusId;
DepartmentIds = departmentIds;
FirstName = firstName;
LastName = lastName;
Email = email;
}

public int Id { get; set; }
public int StatusId { get; set; }
public List<int> DepartmentIds { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Korga.ChurchTools.Api;
namespace ChurchTools.Model;

public class PersonMasterdata
{
public PersonMasterdata()
{
Roles = Array.Empty<Role>();
GroupTypes = Array.Empty<GroupType>();
GroupStatuses = Array.Empty<GroupStatus>();
Departments = Array.Empty<Department>();
Statuses = Array.Empty<Status>();
Roles = [];
GroupTypes = [];
GroupStatuses = [];
Departments = [];
Statuses = [];
}

[JsonConstructor]
Expand All @@ -26,14 +26,14 @@ public PersonMasterdata(IReadOnlyList<Role> roles, IReadOnlyList<GroupType> grou
}

public IReadOnlyList<Role> Roles { get; set; }
public IReadOnlyList<GroupType> GroupTypes { get; set; }
public IReadOnlyList<GroupType> GroupTypes { get; set; }
public IReadOnlyList<GroupStatus> GroupStatuses { get; set; }
public IReadOnlyList<Department> Departments { get; set; }
public IReadOnlyList<Status> Statuses { get; set; }
public IReadOnlyList<Department> Departments { get; set; }
public IReadOnlyList<Status> Statuses { get; set; }

public record Role(int Id, int GroupTypeId, string Name, int SortKey) : IIdentifiable<int>;
public record GroupType(int Id, string Name, int SortKey) : IIdentifiable<int>;
public record Role(int Id, int GroupTypeId, string Name, int SortKey) : IIdentifiable<int>;
public record GroupType(int Id, string Name, int SortKey) : IIdentifiable<int>;
public record GroupStatus(int Id, string Name, int SortKey) : IIdentifiable<int>;
public record Department(int Id, string Name, int SortKey) : IIdentifiable<int>;
public record Status(int Id, string Name, int SortKey) : IIdentifiable<int>;
public record Department(int Id, string Name, int SortKey) : IIdentifiable<int>;
public record Status(int Id, string Name, int SortKey) : IIdentifiable<int>;
}
11 changes: 11 additions & 0 deletions server/ChurchTools/Model/Response.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace ChurchTools.Model;

public class Response<T>
{
public Response(T data)
{
Data = data;
}

public T Data { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Korga.ChurchTools.Api;
namespace ChurchTools.Model;

public class Service
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Korga.ChurchTools.Api;
namespace ChurchTools.Model;

public class ServiceGroup
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Korga.ChurchTools;
using ChurchTools;
using System.Threading.Tasks;
using Xunit;

namespace Korga.Server.Tests;
namespace Korga.Tests;

public class ChurchToolsApiTests
{
Expand Down
Loading

0 comments on commit 90ea3b4

Please sign in to comment.