Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/implement usecases #9

Merged
merged 5 commits into from
Sep 10, 2024
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
5 changes: 3 additions & 2 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ name: Package

on:
push:
branches:
- main
tags:
- release/*
paths:
- 'FastCleanArchitecture.nuspec'

workflow_dispatch:

jobs:
publish:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The purpose of this template is to offer a simple and effective solution for building enterprise applications
by harnessing the capabilities of Clean Architecture and ASP.NET Core.
With this template, you can easily set up a Web API following Clean Architecture and Domain Drive Design principles.
Starting is quick and easyjust install the .NET template (detailed instructions provided below).
Starting is quick and easy-just install the .NET template (detailed instructions provided below).


## Getting Started
Expand Down
2 changes: 1 addition & 1 deletion src/API/Controllers/TodoListsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public async Task<IActionResult> CreateTodoList(CreateTodoListCommand request)

return NoContent();
}
}
}
32 changes: 30 additions & 2 deletions src/Domain/TodoLists/ITodoListRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,35 @@

public interface ITodoListRepository
{
/// <summary>
/// Get a todo list by title.
/// </summary>
/// <param name="title"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<TodoList?> GetByTitleAsync(string title, CancellationToken cancellationToken = default);

void Add(TodoList list);
}
/// <summary>
/// Add a todo list.
/// </summary>
/// <param name="todoList"><see cref="TodoList"/></param>
void Add(TodoList todoList);

/// <summary>
/// Remove a todo list.
/// </summary>
/// <param name="todoList"><see cref="TodoList"/></param>
void Remove(TodoList todoList);

/// <summary>
/// Remove a range of todo list.
/// </summary>
/// <param name="todoLists"><see cref="TodoList"/></param>
void RemoveRange(List<TodoList> todoLists);

/// <summary>
/// Update a todo list.
/// </summary>
/// <param name="todoList"><see cref="TodoList"/></param>
void Update(TodoList todoList);
}
17 changes: 11 additions & 6 deletions src/Domain/TodoLists/TodoList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@ namespace FastCleanArchitecture.Domain.TodoLists;

public sealed class TodoList : BaseAuditableEntity
{
private TodoList(Guid id, string? title) : base(id)
private TodoList(Guid id, string? title, Colour? colour, IList<TodoItem>? items) : base(id)
{
Title = title;
Colour = colour ?? Colour.Grey;
Items = items ?? [];
}

public string? Title { get; private set; }
public Colour Colour { get; private set; } = Colour.Grey;
public IList<TodoItem> Items { get; private set; } = new List<TodoItem>();
public Colour Colour { get; private set; }
public IList<TodoItem> Items { get; private set; }

public static TodoList Create(string? title)
public static TodoList Create(
string? title,
Colour? colour = null,
IList<TodoItem>? todoItems = null)
{
return new TodoList(Guid.NewGuid(), title);
return new TodoList(Guid.NewGuid(), title, colour, todoItems);
}
}
}
10 changes: 8 additions & 2 deletions src/Infrastructure/Data/Repositories/BaseRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ internal abstract class BaseRepository<T> where T : BaseEntity
public async Task<T?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default)
=> await Context.Set<T>().FirstOrDefaultAsync(x => x.Id == id, cancellationToken);

public void Add(T entity) => Context.Add(entity);
}
public void Add(T entity) => Context.Set<T>().Add(entity);

public void Remove(T entity) => Context.Set<T>().Remove(entity);

public void RemoveRange(List<T> entities) => Context.Set<T>().RemoveRange(entities);

public void Update(T entity) => Context.Set<T>().Update(entity);
}
8 changes: 4 additions & 4 deletions src/Infrastructure/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public static IServiceCollection AddInfrastructure(this IServiceCollection servi

services.AddDbContext<ApplicationDbContext>(options =>
{
//#if (UseOracle)
#if (UseOracle)
options.UseOracle(connectionString);
//#else
// options.UseSqlServer(connectionString);
//#endif
#else
options.UseSqlServer(connectionString);
#endif
});

services.AddScoped<ApplicationDbContextInitialiser>();
Expand Down
12 changes: 8 additions & 4 deletions src/Infrastructure/Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@
</PropertyGroup>

<ItemGroup>
<!--#if (UseLocalDB)-->
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.8" />
<!--#if (UseLocalDB)-->
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<!--#endif-->
<!--#if (UseOracle)-->
<PackageReference Include="Oracle.EntityFrameworkCore" Version="8.23.50" />
<!--#endif-->
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<!--#if (UseOracle)-->
<PackageReference Include="Oracle.EntityFrameworkCore" Version="8.23.50" />
<!--#endif-->
</ItemGroup>

<ItemGroup>
Expand Down
Loading