Skip to content

Commit

Permalink
Hyperfocus coding session
Browse files Browse the repository at this point in the history
ditched the modular approach in favour of single clean arch sln
  • Loading branch information
alamb3142 committed Jun 13, 2023
1 parent 214b2e3 commit 575ba34
Show file tree
Hide file tree
Showing 39 changed files with 239 additions and 480 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions SmartHome.Service/Api/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello World!");

app.Run();


// TODO: give minimal APIs a go, ditch and go for controllers if it's too much effort
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:50973",
"sslPort": 44376
"applicationUrl": "http://localhost:29747",
"sslPort": 44381
}
},
"profiles": {
"SmartHome.Service.API": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7232;http://localhost:5232",
"applicationUrl": "http://localhost:5005",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7287;http://localhost:5005",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
9 changes: 9 additions & 0 deletions SmartHome.Service/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": "*"
}
5 changes: 5 additions & 0 deletions SmartHome.Service/Application/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Application;
public class Class1
{

}
3 changes: 3 additions & 0 deletions SmartHome.Service/Domain/Common/Interfaces/IAggregateRoot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Domain.Common;

public interface IAggregateRoot { }
6 changes: 6 additions & 0 deletions SmartHome.Service/Domain/Common/Interfaces/IDeviceFunction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Domain.Common;

public interface IDeviceFunction
{
public Guid DeviceId { get; }
}
6 changes: 6 additions & 0 deletions SmartHome.Service/Domain/Common/Interfaces/IRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Domain.Common;

public interface IRepository<T> where T : IAggregateRoot
{
// TODO: unit of work?
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace SmartHome.Service.BuildingBlocks;
namespace Domain.Common;

#nullable disable
// Courtesy of Microsoft:
public abstract class ValueObject
{
protected static bool EqualOperator(ValueObject left, ValueObject right)
Expand All @@ -8,7 +10,7 @@ protected static bool EqualOperator(ValueObject left, ValueObject right)
{
return false;
}
return ReferenceEquals(left, null) || left.Equals(right);
return ReferenceEquals(left, right) || left.Equals(right);
}

protected static bool NotEqualOperator(ValueObject left, ValueObject right)
Expand Down Expand Up @@ -37,8 +39,14 @@ public override int GetHashCode()
.Aggregate((x, y) => x ^ y);
}

public ValueObject GetCopy()
public static bool operator ==(ValueObject one, ValueObject two)
{
return this.MemberwiseClone() as ValueObject;
return EqualOperator(one, two);
}
}

public static bool operator !=(ValueObject one, ValueObject two)
{
return NotEqualOperator(one, two);
}
}
#nullable enable
28 changes: 28 additions & 0 deletions SmartHome.Service/Domain/Devices/Device.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Domain.Devices;

public class Device // todo: entity
{
public Guid Id { get; protected set; }
public string NodeId { get; protected set; } //? value object?
public bool On { get; protected set; }
public DeviceState State { get; protected set; }

protected Device(Guid id, string nodeId, bool on, DeviceState state)
{
Id = id;
NodeId = nodeId;
On = on;
State = state;
}

public static Device Create(string nodeId, bool on, DeviceState state)
{
var id = Guid.NewGuid();
return new Device(id, nodeId, on, state);
}

public void Switch(bool on)
{
On = on;
}
}
9 changes: 9 additions & 0 deletions SmartHome.Service/Domain/Devices/Enums/DeviceState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Domain.Devices;

public enum DeviceState
{
Connected,
LowBattery,
Disconnected,
Unkown
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
40 changes: 40 additions & 0 deletions SmartHome.Service/Domain/DoorLocks/DoorLock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Domain.Common;
using Domain.Devices;

namespace Domain.Doorlocks;

public class DoorLock : IAggregateRoot, IDeviceFunction
{
public Guid Id { get; protected set; }
public Guid DeviceId { get; protected set; }
public bool Locked { get; protected set; }

protected DoorLock(Guid id, Guid deviceId, bool locked)
{
Id = id;
DeviceId = deviceId;
Locked = locked;
}

public static DoorLock Create(Device device, bool locked)
{
if (device.State != DeviceState.Connected)
{
throw new Exception("Device must be available and charged");
}

var doorLockId = Guid.NewGuid();

return new DoorLock(doorLockId, device.Id, locked);
}

public void Lock()
{
Locked = true;
}

public void UnLock()
{
Locked = false;
}
}
5 changes: 5 additions & 0 deletions SmartHome.Service/Infrastructure/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Infrastructure;
public class Class1
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MediatR" Version="12.0.1" />
</ItemGroup>

</Project>

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 575ba34

Please sign in to comment.