Skip to content

Commit

Permalink
Initialize CMS. (#1)
Browse files Browse the repository at this point in the history
* Contracts.

* Aggregate

* Errors.

* Error

* Core layer.

* Infrastructure layer.

* Contracts.

* Core layer.

* Core & Infrastructure.

* EFCore.

* Contracts & Core.

* Handlers.

* Persistence.

* Web interface.

* Bootstrap.
  • Loading branch information
Utar94 authored Jul 10, 2024
1 parent b90d76c commit d3b50db
Show file tree
Hide file tree
Showing 99 changed files with 3,000 additions and 26 deletions.
24 changes: 12 additions & 12 deletions backend/Cms.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logitar.Cms.Contracts", "src\Logitar.Cms.Contracts\Logitar.Cms.Contracts.csproj", "{6A08D4DD-8E86-43AE-B391-BB10ABAEC4AD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logitar.Cms.Contracts", "src\Logitar.Cms.Contracts\Logitar.Cms.Contracts.csproj", "{6A08D4DD-8E86-43AE-B391-BB10ABAEC4AD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logitar.Cms.Core", "src\Logitar.Cms.Core\Logitar.Cms.Core.csproj", "{E98B3291-3F8F-4B80-8463-3873A51FDB22}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logitar.Cms.Infrastructure", "src\Logitar.Cms.Infrastructure\Logitar.Cms.Infrastructure.csproj", "{4784DFE3-5E0B-4628-A3F6-56A6ED11D185}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logitar.Cms.Infrastructure", "src\Logitar.Cms.Infrastructure\Logitar.Cms.Infrastructure.csproj", "{4784DFE3-5E0B-4628-A3F6-56A6ED11D185}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logitar.Cms.MongoDB", "src\Logitar.Cms.MongoDB\Logitar.Cms.MongoDB.csproj", "{FEF28D87-7237-4EC0-A957-DF7BC7FF7572}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logitar.Cms.MongoDB", "src\Logitar.Cms.MongoDB\Logitar.Cms.MongoDB.csproj", "{FEF28D87-7237-4EC0-A957-DF7BC7FF7572}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logitar.Cms.EntityFrameworkCore", "src\Logitar.Cms.EntityFrameworkCore\Logitar.Cms.EntityFrameworkCore.csproj", "{F14DA8F7-103B-4E37-8842-292F8B1954C2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logitar.Cms.EntityFrameworkCore", "src\Logitar.Cms.EntityFrameworkCore\Logitar.Cms.EntityFrameworkCore.csproj", "{F14DA8F7-103B-4E37-8842-292F8B1954C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logitar.Cms.EntityFrameworkCore.SqlSever", "src\Logitar.Cms.EntityFrameworkCore.SqlSever\Logitar.Cms.EntityFrameworkCore.SqlSever.csproj", "{8F7BE431-41ED-4E6C-A7B5-3B1A7B963F44}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logitar.Cms.EntityFrameworkCore.PostgreSQL", "src\Logitar.Cms.EntityFrameworkCore.PostgreSQL\Logitar.Cms.EntityFrameworkCore.PostgreSQL.csproj", "{79D2A438-4BD9-417E-89F2-28664B50533D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logitar.Cms.EntityFrameworkCore.PostgreSQL", "src\Logitar.Cms.EntityFrameworkCore.PostgreSQL\Logitar.Cms.EntityFrameworkCore.PostgreSQL.csproj", "{79D2A438-4BD9-417E-89F2-28664B50533D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logitar.Cms.Web", "src\Logitar.Cms.Web\Logitar.Cms.Web.csproj", "{4E2791D8-6D64-425C-A18B-0E70519D63FD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logitar.Cms.Web", "src\Logitar.Cms.Web\Logitar.Cms.Web.csproj", "{4E2791D8-6D64-425C-A18B-0E70519D63FD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Logitar.Cms", "src\Logitar.Cms\Logitar.Cms.csproj", "{8580B630-EECA-457F-B342-58B8B362CD98}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logitar.Cms", "src\Logitar.Cms\Logitar.Cms.csproj", "{8580B630-EECA-457F-B342-58B8B362CD98}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Logitar.Cms.EntityFrameworkCore.SqlServer", "src\Logitar.Cms.EntityFrameworkCore.SqlServer\Logitar.Cms.EntityFrameworkCore.SqlServer.csproj", "{01AE8019-93B4-4C51-ACEE-943F114B9ABF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -56,10 +56,6 @@ Global
{F14DA8F7-103B-4E37-8842-292F8B1954C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F14DA8F7-103B-4E37-8842-292F8B1954C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F14DA8F7-103B-4E37-8842-292F8B1954C2}.Release|Any CPU.Build.0 = Release|Any CPU
{8F7BE431-41ED-4E6C-A7B5-3B1A7B963F44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F7BE431-41ED-4E6C-A7B5-3B1A7B963F44}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F7BE431-41ED-4E6C-A7B5-3B1A7B963F44}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F7BE431-41ED-4E6C-A7B5-3B1A7B963F44}.Release|Any CPU.Build.0 = Release|Any CPU
{79D2A438-4BD9-417E-89F2-28664B50533D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{79D2A438-4BD9-417E-89F2-28664B50533D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{79D2A438-4BD9-417E-89F2-28664B50533D}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -72,6 +68,10 @@ Global
{8580B630-EECA-457F-B342-58B8B362CD98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8580B630-EECA-457F-B342-58B8B362CD98}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8580B630-EECA-457F-B342-58B8B362CD98}.Release|Any CPU.Build.0 = Release|Any CPU
{01AE8019-93B4-4C51-ACEE-943F114B9ABF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{01AE8019-93B4-4C51-ACEE-943F114B9ABF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{01AE8019-93B4-4C51-ACEE-943F114B9ABF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{01AE8019-93B4-4C51-ACEE-943F114B9ABF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
39 changes: 39 additions & 0 deletions backend/src/Logitar.Cms.Contracts/Actors/Actor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
namespace Logitar.Cms.Contracts.Actors;

public class Actor
{
public static Actor System => new(ActorType.System.ToString());

public Guid Id { get; set; }
public ActorType Type { get; set; }
public bool IsDeleted { get; set; }

public string DisplayName { get; set; }
public string? EmailAddress { get; set; }
public string? PictureUrl { get; set; }

public Actor() : this(string.Empty)
{
}

public Actor(string displayName)
{
DisplayName = displayName;
}

public override bool Equals(object obj) => obj is Actor actor && actor.Id == Id;
public override int GetHashCode() => Id.GetHashCode();
public override string ToString()
{
StringBuilder s = new();

s.Append(DisplayName);
if (EmailAddress != null)
{
s.Append(" <").Append(EmailAddress).Append('>');
}
s.Append(" (").Append(Type).Append(".Id=").Append(Id).Append(')');

return s.ToString();
}
}
8 changes: 8 additions & 0 deletions backend/src/Logitar.Cms.Contracts/Actors/ActorType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Logitar.Cms.Contracts.Actors;

public enum ActorType
{
System = 0,
User = 1,
ApiKey = 2
}
19 changes: 19 additions & 0 deletions backend/src/Logitar.Cms.Contracts/Aggregate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Logitar.Cms.Contracts.Actors;

namespace Logitar.Cms.Contracts;

public abstract class Aggregate
{
public Guid Id { get; set; }
public long Version { get; set; }

public Actor CreatedBy { get; set; } = new();
public DateTime CreatedOn { get; set; }

public Actor UpdatedBy { get; set; } = new();
public DateTime UpdatedOn { get; set; }

public override bool Equals(object obj) => obj is Aggregate aggregate && aggregate.GetType().Equals(GetType()) && aggregate.Id == Id;
public override int GetHashCode() => HashCode.Combine(GetType(), Id);
public override string ToString() => $"{GetType()} (Id={Id})";
}
26 changes: 26 additions & 0 deletions backend/src/Logitar.Cms.Contracts/Configurations/Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Logitar.Cms.Contracts.Configurations;

public class Configuration : Aggregate
{
public string Secret { get; set; }

public UniqueNameSettings UniqueNameSettings { get; set; }
public PasswordSettings PasswordSettings { get; set; }
public bool RequireUniqueName { get; set; }

public LoggingSettings LoggingSettings { get; set; }

public Configuration() : this(string.Empty)
{
}

public Configuration(string secret)
{
Secret = secret;

UniqueNameSettings = new();
PasswordSettings = new();

LoggingSettings = new();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Logitar.Cms.Contracts.Configurations;

public interface ILoggingSettings
{
LoggingExtent Extent { get; }
bool OnlyErrors { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Logitar.Cms.Contracts.Configurations;

public enum LoggingExtent
{
None = 0,
ActivityOnly = 1,
Full = 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Logitar.Cms.Contracts.Configurations;

public record LoggingSettings : ILoggingSettings
{
public LoggingExtent Extent { get; set; } = LoggingExtent.ActivityOnly;
public bool OnlyErrors { get; set; }

public LoggingSettings() : this(LoggingExtent.ActivityOnly, onlyErrors: false)
{
}

public LoggingSettings(ILoggingSettings logging) : this(logging.Extent, logging.OnlyErrors)
{
}

public LoggingSettings(LoggingExtent extent, bool onlyErrors)
{
Extent = extent;
OnlyErrors = onlyErrors;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Logitar.Identity.Contracts.Settings;

namespace Logitar.Cms.Contracts.Configurations;

public record PasswordSettings : IPasswordSettings
{
public int RequiredLength { get; set; }
public int RequiredUniqueChars { get; set; }
public bool RequireNonAlphanumeric { get; set; }
public bool RequireLowercase { get; set; }
public bool RequireUppercase { get; set; }
public bool RequireDigit { get; set; }
public string HashingStrategy { get; set; }

public PasswordSettings() : this(new PasswordSettings())
{
}

public PasswordSettings(IPasswordSettings password)
: this(password.RequiredLength, password.RequiredUniqueChars, password.RequireNonAlphanumeric, password.RequireLowercase, password.RequireUppercase, password.RequireDigit, password.HashingStrategy)
{
}

public PasswordSettings(
int requiredLength,
int requiredUniqueChars,
bool requireNonAlphanumeric,
bool requireLowercase,
bool requireUppercase,
bool requireDigit,
string hashingStrategy)
{
RequiredLength = requiredLength;
RequiredUniqueChars = requiredUniqueChars;
RequireNonAlphanumeric = requireNonAlphanumeric;
RequireLowercase = requireLowercase;
RequireUppercase = requireUppercase;
RequireDigit = requireDigit;
HashingStrategy = hashingStrategy;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Logitar.Identity.Contracts.Settings;

namespace Logitar.Cms.Contracts.Configurations;

public record UniqueNameSettings : IUniqueNameSettings
{
public string? AllowedCharacters { get; set; }

public UniqueNameSettings() : this(allowedCharacters: null)
{
}

public UniqueNameSettings(IUniqueNameSettings uniqueName) : this(uniqueName.AllowedCharacters)
{
}

public UniqueNameSettings(string? allowedCharacters)
{
AllowedCharacters = allowedCharacters;
}
}
21 changes: 21 additions & 0 deletions backend/src/Logitar.Cms.Contracts/Errors/Error.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Logitar.Cms.Contracts.Errors;

public record Error
{
public string Code { get; set; }
public string Message { get; set; }
public List<ErrorData> Data { get; set; }

public Error() : this(string.Empty, string.Empty)
{
}

public Error(string code, string message, IEnumerable<ErrorData>? data = null)
{
Code = code;
Message = message;
Data = data?.ToList() ?? [];
}

public void Add(ErrorData data) => Data.Add(data);
}
21 changes: 21 additions & 0 deletions backend/src/Logitar.Cms.Contracts/Errors/ErrorData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Logitar.Cms.Contracts.Errors;

public record ErrorData
{
public string Key { get; set; }
public string Value { get; set; }

public ErrorData() : this(string.Empty, string.Empty)
{
}

public ErrorData(KeyValuePair<string, string> data) : this(data.Key, data.Value)
{
}

public ErrorData(string key, string value)
{
Key = key;
Value = value;
}
}
18 changes: 18 additions & 0 deletions backend/src/Logitar.Cms.Contracts/Errors/PropertyError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Logitar.Cms.Contracts.Errors;

public record PropertyError : Error
{
public string? PropertyName { get; set; }
public object? AttemptedValue { get; set; }

public PropertyError() : this(string.Empty, string.Empty, null, null)
{
}

public PropertyError(string code, string message, string? propertyName, object? attemptedValue, IEnumerable<ErrorData>? data = null)
: base(code, message, data)
{
PropertyName = propertyName;
AttemptedValue = attemptedValue;
}
}
18 changes: 18 additions & 0 deletions backend/src/Logitar.Cms.Contracts/Errors/ValidationError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Logitar.Cms.Contracts.Errors;

public record ValidationError : Error
{
public List<PropertyError> Errors { get; set; }

public ValidationError() : this("Validation", "Validation failed.")
{
}

public ValidationError(string code, string message, IEnumerable<ErrorData>? data = null, IEnumerable<PropertyError>? errors = null)
: base(code, message, data)
{
Errors = errors?.ToList() ?? [];
}

public void Add(PropertyError error) => Errors.Add(error);
}
12 changes: 12 additions & 0 deletions backend/src/Logitar.Cms.Contracts/Logitar.Cms.Contracts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand All @@ -13,4 +14,15 @@
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Logitar.Identity.Contracts" Version="1.1.0" />
</ItemGroup>

<ItemGroup>
<Using Include="System" />
<Using Include="System.Collections.Generic" />
<Using Include="System.Linq" />
<Using Include="System.Text" />
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions backend/src/Logitar.Cms.Core/Caching/ICacheService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Logitar.Cms.Contracts.Actors;
using Logitar.Cms.Contracts.Configurations;
using Logitar.EventSourcing;

namespace Logitar.Cms.Core.Caching;

public interface ICacheService
{
Configuration? Configuration { get; set; }

Actor? GetActor(ActorId id);
void RemoveActor(ActorId id);
void SetActor(Actor actor);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using MediatR;

namespace Logitar.Cms.Core.Configurations.Commands;

public record InitializeConfigurationCommand(string DefaultLocale, string Username, string Password) : IRequest;
Loading

0 comments on commit d3b50db

Please sign in to comment.