Skip to content
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,5 @@ ASALocalRun/
.localhistory/

# BeatPulse healthcheck temp database
healthchecksdb
healthchecksdb
Logs/logs.txt
22 changes: 22 additions & 0 deletions Application/Application.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.7.1" />
<PackageReference Include="MediatR" Version="12.1.1" />
</ItemGroup>





</Project>
19 changes: 19 additions & 0 deletions Application/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using FluentValidation;
using Microsoft.Extensions.DependencyInjection;

namespace Application;

public static class DependencyInjection
{
public static IServiceCollection AddApplication(this IServiceCollection services)
{
var assembly = typeof(DependencyInjection).Assembly;

services.AddMediatR(configuration =>
configuration.RegisterServicesFromAssembly(assembly));

services.AddValidatorsFromAssembly(assembly);

return services;
}
}
17 changes: 17 additions & 0 deletions Application/Exceptions/EntityNotFoundException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Net;

namespace Application.Exceptions;

public class EntityNotFoundException : Exception
{
public static HttpStatusCode StatusCode = HttpStatusCode.NotFound;

public EntityNotFoundException() : base()
{}

public EntityNotFoundException(string message) : base(message)
{}

public EntityNotFoundException(string message, Exception innerException) : base(message, innerException)
{}
}
15 changes: 15 additions & 0 deletions Application/Exceptions/ErrorDetails.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Text.Json;

namespace Application.Exceptions;

public class ErrorDetails
{
public int StatusCode { get; set; }

public string Message { get; set; }

public override string ToString()
{
return JsonSerializer.Serialize(this);
}
}
57 changes: 57 additions & 0 deletions Application/Interfaces/ITodoItemsRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Domain.Entities;

namespace Application.Interfaces;

public interface ITodoItemsRepository
{
/// <summary>
/// Gets every TodoItem
/// </summary>
/// <returns>Collection of TodoItems</returns>
Task<IEnumerable<TodoItem>> GetAll();

/// <summary>
/// Gets every TodoItem and separates them by pages
/// </summary>
/// <param name="page">Page</param>
/// <param name="pageSize">Items per page</param>
/// <returns>Collection of TodoItems</returns>
Task<IEnumerable<TodoItem>> GetAllPaginated(int page = 1, int pageSize = 10);

/// <summary>
/// Gets a specific TodoItem by its ID
/// </summary>
/// <param name="todoItemId">TodoItem ID</param>
/// <returns>TodoItem</returns>
Task<TodoItem> GetById(long todoItemId);

/// <summary>
/// Creates a new TodoItem
/// </summary>
/// <param name="todoItem">New TodoItem</param>
/// <returns>Created TodoItem</returns>
Task<TodoItem> CreateTodoItem(TodoItem todoItem);

/// <summary>
/// Updates an existing TodoItem
/// </summary>
/// <param name="todoItemId">TodoItem ID</param>
/// <param name="todoItem">Updated TodoItem data</param>
/// <returns>Updated TodoItem</returns>
Task<TodoItem> UpdateTodoItem(long todoItemId, TodoItem todoItem);

/// <summary>
/// Updates TodoItem's secret
/// </summary>
/// <param name="todoItemId">TodoItem ID</param>
/// <param name="secret">TodoItem Secret</param>
/// <returns>Updated TodoItem</returns>
Task<TodoItem> UpdateTodoItemSecret(long todoItemId, string secret);

/// <summary>
/// Deletes an existing TodoItem by ID
/// </summary>
/// <param name="todoItemId">TodoItem ID</param>
/// <returns></returns>
Task DeleteTodoItem(long todoItemId);
}
28 changes: 28 additions & 0 deletions Application/TodoItems/CommandHandlers/CreateTodoItemHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Application.Interfaces;
using Application.TodoItems.Commands;
using Domain.Entities;
using MediatR;

namespace Application.TodoItems.CommandHandlers;

public class CreateTodoItemHandler : IRequestHandler<CreateTodoItem, TodoItem>
{
private readonly ITodoItemsRepository _todoItemsRepository;

public CreateTodoItemHandler(ITodoItemsRepository todoItemsRepository)
{
_todoItemsRepository = todoItemsRepository;
}

public async Task<TodoItem> Handle(CreateTodoItem request, CancellationToken cancellationToken)
{
var newTodoItem = new TodoItem
{
Name = request.Name,
IsComplete = request.IsComplete,
Secret = request.Secret
};

return await _todoItemsRepository.CreateTodoItem(newTodoItem);
}
}
21 changes: 21 additions & 0 deletions Application/TodoItems/CommandHandlers/DeleteTodoItemHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Application.Interfaces;
using Application.TodoItems.Commands;
using Domain.Entities;
using MediatR;

namespace Application.TodoItems.CommandHandlers;

public class DeleteTodoItemHandler : IRequestHandler<DeleteTodoItem>
{
private readonly ITodoItemsRepository _todoItemsRepository;

public DeleteTodoItemHandler(ITodoItemsRepository todoItemsRepository)
{
_todoItemsRepository = todoItemsRepository;
}

public async Task Handle(DeleteTodoItem request, CancellationToken cancellationToken)
{
await _todoItemsRepository.DeleteTodoItem(request.Id);
}
}
26 changes: 26 additions & 0 deletions Application/TodoItems/CommandHandlers/UpdateTodoItemHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Application.Interfaces;
using Application.TodoItems.Commands;
using Domain.Entities;
using MediatR;

namespace Application.TodoItems.CommandHandlers;

public class UpdateTodoItemHandler : IRequestHandler<UpdateTodoItem, TodoItem>
{
private readonly ITodoItemsRepository _todoItemsRepository;

public UpdateTodoItemHandler(ITodoItemsRepository todoItemsRepository)
{
_todoItemsRepository = todoItemsRepository;
}

public async Task<TodoItem> Handle(UpdateTodoItem request, CancellationToken cancellationToken)
{
var updatedTodoItem = new TodoItem
{
Name = request.Name,
IsComplete = request.IsComplete
};
return await _todoItemsRepository.UpdateTodoItem(request.Id, updatedTodoItem);
}
}
23 changes: 23 additions & 0 deletions Application/TodoItems/Commands/CreateTodoItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Application.TodoItems.Models;
using Domain.Entities;
using MediatR;

namespace Application.TodoItems.Commands;

public class CreateTodoItem : IRequest<TodoItem>
{
public string Name { get; set; }

public bool IsComplete { get; set; }

public string Secret { get; set; }

public CreateTodoItem()
{}

public CreateTodoItem(CreateTodoItemRequest request)
{
Name = request.Name;
IsComplete = request.IsComplete;
}
}
16 changes: 16 additions & 0 deletions Application/TodoItems/Commands/DeleteTodoItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using MediatR;

namespace Application.TodoItems.Commands;

public class DeleteTodoItem : IRequest
{
public long Id { get; set; }

public DeleteTodoItem()
{}

public DeleteTodoItem(long id)
{
Id = id;
}
}
24 changes: 24 additions & 0 deletions Application/TodoItems/Commands/UpdateTodoItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Application.TodoItems.Models;
using Domain.Entities;
using MediatR;

namespace Application.TodoItems.Commands;

public class UpdateTodoItem : IRequest<TodoItem>
{
public long Id { get; set; }

public string Name { get; set; }

public bool IsComplete { get; set; }

public UpdateTodoItem()
{}

public UpdateTodoItem(UpdateTodoItemRequest request)
{
Id = request.Id;
Name = request.Name;
IsComplete = request.IsComplete;
}
}
8 changes: 8 additions & 0 deletions Application/TodoItems/Models/CreateTodoItemRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Application.TodoItems.Models;

public class CreateTodoItemRequest
{
public string Name { get; set; }

public bool IsComplete { get; set; }
}
25 changes: 25 additions & 0 deletions Application/TodoItems/Models/TodoItemFullModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Domain.Entities;

namespace Application.TodoItems.Models;

public class TodoItemFullModel
{
public long Id { get; set; }

public string Name { get; set; }

public bool IsComplete { get; set; }

public string Secret { get; set; }

public TodoItemFullModel()
{}

public TodoItemFullModel(TodoItem todoItem)
{
Id = todoItem.Id;
Name = todoItem.Name;
IsComplete = todoItem.IsComplete;
Secret = todoItem.Secret;
}
}
22 changes: 22 additions & 0 deletions Application/TodoItems/Models/TodoItemShortModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Domain.Entities;

namespace Application.TodoItems.Models;

public class TodoItemShortModel
{
public long Id { get; set; }

public string Name { get; set; }

public bool IsComplete { get; set; }

public TodoItemShortModel()
{}

public TodoItemShortModel(TodoItem todoItem)
{
Id = todoItem.Id;
Name = todoItem.Name;
IsComplete = todoItem.IsComplete;
}
}
10 changes: 10 additions & 0 deletions Application/TodoItems/Models/UpdateTodoItemRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Application.TodoItems.Models;

public class UpdateTodoItemRequest
{
public long Id { get; set; }

public string Name { get; set; }

public bool IsComplete { get; set; }
}
9 changes: 9 additions & 0 deletions Application/TodoItems/Queries/GetAllTodoItems.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Domain.Entities;
using MediatR;

namespace Application.TodoItems.Queries;

public class GetAllTodoItems : IRequest<IEnumerable<TodoItem>>
{

}
17 changes: 17 additions & 0 deletions Application/TodoItems/Queries/GetTodoItemById.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Domain.Entities;
using MediatR;

namespace Application.TodoItems.Queries;

public class GetTodoItemById : IRequest<TodoItem>
{
public long Id { get; set; }

public GetTodoItemById()
{}

public GetTodoItemById(long id)
{
Id = id;
}
}
Loading