-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98abe7f
commit 01b38b8
Showing
15 changed files
with
249 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace BuberDinner.Domain | ||
{ | ||
using CSharpFunctionalExtensions; | ||
|
||
public abstract class AggregateRoot<TId> : Entity<TId> | ||
where TId : notnull | ||
{ | ||
protected AggregateRoot(TId id) : base(id) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace BuberDinner.Domain.Menu.Entities; | ||
using BuberDinner.Domain.Menu.ValueObject; | ||
using CSharpFunctionalExtensions; | ||
using CSharpFunctionalExtensions.Errors; | ||
using FluentValidation; | ||
|
||
public class MenuItem : Entity<MenuItemId> | ||
{ | ||
public string Name { get; } | ||
public string Description { get; } | ||
|
||
public static Result<MenuItem, ErrorList> Create(string name, string description) | ||
{ | ||
MenuItem menuItem = new(MenuItemId.CreateUnique(), name, description); | ||
return s_validator.ValidateToResult(menuItem); | ||
} | ||
|
||
private MenuItem(MenuItemId menuItemId, string name, string description) | ||
{ | ||
Id = menuItemId; | ||
Name = name; | ||
Description = description; | ||
} | ||
|
||
static readonly InlineValidator<MenuItem> s_validator = new() | ||
{ | ||
v => v.RuleFor(x => x.Name).NotEmpty(), | ||
v => v.RuleFor(x => x.Description).NotEmpty(), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace BuberDinner.Domain.Menu.Entities; | ||
using BuberDinner.Domain.Menu.ValueObject; | ||
using CSharpFunctionalExtensions; | ||
using CSharpFunctionalExtensions.Errors; | ||
using FluentValidation; | ||
|
||
public class MenuSection : Entity<MenuSectionId> | ||
{ | ||
public string Name { get; } | ||
public string Description { get; } | ||
|
||
public IReadOnlyList<MenuItem> Items => _menuItems.AsReadOnly(); | ||
|
||
private readonly List<MenuItem> _menuItems = new(); | ||
|
||
public static Result<MenuSection, ErrorList> Create(string name, string description) | ||
{ | ||
MenuSection menuItem = new(MenuSectionId.CreateUnique(), name, description); | ||
return s_validator.ValidateToResult(menuItem); | ||
} | ||
|
||
private MenuSection(MenuSectionId menuItemId, string name, string description) | ||
{ | ||
Id = menuItemId; | ||
Name = name; | ||
Description = description; | ||
} | ||
|
||
static readonly InlineValidator<MenuSection> s_validator = new() | ||
{ | ||
v => v.RuleFor(x => x.Name).NotEmpty(), | ||
v => v.RuleFor(x => x.Description).NotEmpty(), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace BuberDinner.Domain.Menu | ||
{ | ||
using System.Collections.Generic; | ||
using BuberDinner.Domain.Menu.Entities; | ||
using BuberDinner.Domain.Menu.ValueObject; | ||
using CSharpFunctionalExtensions.Errors; | ||
using CSharpFunctionalExtensions; | ||
using FluentValidation; | ||
|
||
public class Menu : AggregateRoot<MenuId> | ||
{ | ||
public string Name { get; } | ||
public string Description { get; } | ||
public decimal AverageRating { get; } | ||
public IReadOnlyList<MenuSection> Section => _menuSections.AsReadOnly(); | ||
public HostId HostId { get; } | ||
public IReadOnlyList<DinnerId> DinnerIds => _dinnerIds.AsReadOnly(); | ||
|
||
private List<MenuSection> _menuSections = new(); | ||
private List<DinnerId> _dinnerIds = new(); | ||
|
||
public static Result<Menu, ErrorList> Create(string name, string description, HostId host) | ||
{ | ||
Menu menu = new(MenuId.CreateUnique(), name, description, host); | ||
return s_validator.ValidateToResult(menu); | ||
} | ||
|
||
private Menu(MenuId menuId, string name, string description, HostId hostId) : base(menuId) | ||
{ | ||
Name = name; | ||
Description = description; | ||
HostId = hostId; | ||
} | ||
|
||
static readonly InlineValidator<Menu> s_validator = new() | ||
{ | ||
v => v.RuleFor(x => x.Name).NotEmpty(), | ||
v => v.RuleFor(x => x.Description).NotEmpty(), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace BuberDinner.Domain.Menu.ValueObject | ||
{ | ||
using System; | ||
using CSharpFunctionalExtensions; | ||
using CSharpFunctionalExtensions.Errors; | ||
|
||
public class DinnerId : SimpleValueObject<Guid> | ||
{ | ||
private DinnerId(Guid value) : base(value) | ||
{ | ||
} | ||
|
||
public static Result<DinnerId, ErrorList> Create(Guid id) | ||
{ | ||
if (id == Guid.Empty) | ||
return Result.Failure<DinnerId, ErrorList>(Error.Validation(nameof(id), "Id cannot be empty")); | ||
|
||
return new DinnerId(id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace BuberDinner.Domain.Menu.ValueObject | ||
{ | ||
using System; | ||
using CSharpFunctionalExtensions; | ||
using CSharpFunctionalExtensions.Errors; | ||
|
||
public class HostId : SimpleValueObject<Guid> | ||
{ | ||
private HostId(Guid value) : base(value) | ||
{ | ||
} | ||
|
||
public static Result<HostId, ErrorList> Create(Guid id) | ||
{ | ||
if (id == Guid.Empty) | ||
return Result.Failure<HostId, ErrorList>(Error.Validation(nameof(id), "Id cannot be empty")); | ||
|
||
return new HostId(id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace BuberDinner.Domain.Menu.ValueObject | ||
{ | ||
using System; | ||
using CSharpFunctionalExtensions; | ||
using CSharpFunctionalExtensions.Errors; | ||
|
||
public class MenuId : SimpleValueObject<Guid> | ||
{ | ||
private MenuId(Guid value) : base(value) | ||
{ | ||
} | ||
|
||
public static Result<MenuId, ErrorList> Create(Guid id) | ||
{ | ||
if (id == Guid.Empty) | ||
return Result.Failure<MenuId, ErrorList>(Error.Validation(nameof(id), "Id cannot be empty")); | ||
|
||
return new MenuId(id); | ||
} | ||
|
||
internal static MenuId CreateUnique() => | ||
new MenuId(Guid.NewGuid()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace BuberDinner.Domain.Menu.ValueObject | ||
{ | ||
using System; | ||
using CSharpFunctionalExtensions; | ||
using CSharpFunctionalExtensions.Errors; | ||
|
||
public class MenuItemId : SimpleValueObject<Guid> | ||
{ | ||
private MenuItemId(Guid value) : base(value) | ||
{ | ||
} | ||
|
||
public static Result<MenuItemId, ErrorList> Create(Guid id) | ||
{ | ||
if (id == Guid.Empty) | ||
return Result.Failure<MenuItemId, ErrorList>(Error.Validation(nameof(id), "Id cannot be empty")); | ||
|
||
return new MenuItemId(id); | ||
} | ||
|
||
public static MenuItemId CreateUnique() => new(Guid.NewGuid()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace BuberDinner.Domain.Menu.ValueObject | ||
{ | ||
using System; | ||
using CSharpFunctionalExtensions; | ||
using CSharpFunctionalExtensions.Errors; | ||
|
||
public class MenuSectionId : SimpleValueObject<Guid> | ||
{ | ||
private MenuSectionId(Guid value) : base(value) | ||
{ | ||
} | ||
|
||
public static Result<MenuSectionId, ErrorList> Create(Guid id) | ||
{ | ||
if (id == Guid.Empty) | ||
return Result.Failure<MenuSectionId, ErrorList>(Error.Validation(nameof(id), "Id cannot be empty")); | ||
|
||
return new MenuSectionId(id); | ||
} | ||
|
||
internal static MenuSectionId CreateUnique() => | ||
new MenuSectionId(Guid.NewGuid()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,26 @@ | ||
# Buber Dinner | ||
|
||
## The idea | ||
|
||
Allows you to turn your home into a restaurant where... | ||
Just like people turning their homes into hotels via AirBNB. | ||
|
||
## Concepts & Tech used | ||
|
||
* .NET 7, EF Core | ||
* Clean Architecture & Domain-Driven Design principles | ||
* Common patterns such as CQRS, unit of work, repository, mediator | ||
* Open source libraries such as MediatR, FluentValidation, ErroOr, Throw, Mapster | ||
* Open source libraries such as Mediator, FluentValidation, CSharpFunctionalExtensions, Mapster | ||
* Authentication: JWT tokens | ||
|
||
### Clean Architecture | ||
 | ||
 | ||
 | ||
|
||
 | ||
 | ||
 | ||
|
||
* The **Domain** and **Application** layers are the focus and therefore the core of the system. | ||
* The Domain layer contains **enterprise logic** and **types**. The application layer contains **business logic** and **types**. | ||
* Infrastructure and Presentation depend on Core, but not on one another. | ||
* The **Domain** layer contains **business logic**, **AggregateRoot**, **Entities** and **ValueObjects**. | ||
* The **Application** layer contains **business logic** and glue to combine Infrastructure & Domain. | ||
* The **Infrastructure** layer contains glue code to connect the application to the outside world. It contains implementations of interfaces defined in the Application layer. | ||
* The **Presentation** layer is the entry point to the system. It is responsible for **translating HTTP requests** into commands and queries for the application layer to handle. |