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
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ root = true
# C# files
[*.cs]

# this should be causing namespace missmatch to fail the linting workflow and it does
# however, auto fix of formatting accoring to this rule is broken since 2022 :(
# thus, it is validated but needs manual fix as for now
# https://github.com/dotnet/format/issues/1623
dotnet_style_namespace_match_folder = true:warning
dotnet_diagnostic.IDE0130.severity = warning

#### Core EditorConfig Options ####

# Indentation and spacing
Expand Down
101 changes: 0 additions & 101 deletions Api/Controllers/ItemsController.cs

This file was deleted.

7 changes: 6 additions & 1 deletion Api/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Api.EnternalDeps.EmployeesApi;
using Api.ExternalDeps.EmployeesApi;
using Api.Features.Items.CreateItem;
using Api.Features.Items.GetAllItems;
using Application;
using Application.Commands;
using Application.Queries;
Expand Down Expand Up @@ -36,5 +38,8 @@ public static void AddApplication(this IServiceCollection services, IConfigurati
services.AddTransient<CreateItemCommand>();
services.AddTransient<AllItemsQuery>();
services.AddTransient<HardDeleteItemCommand>();

services.AddTransient<GetAllItemsHandler>();
services.AddTransient<CreateItemHandler>();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Api.EnternalDeps.EmployeesApi.Responses;
using Api.ExternalDeps.EmployeesApi.Responses;
using Microsoft.Extensions.Options;
using TourmalineCore.AspNetCore.JwtAuthentication.Core.Options;

namespace Api.EnternalDeps.EmployeesApi;
namespace Api.ExternalDeps.EmployeesApi;

public class EmployeesApi
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Api.EnternalDeps.EmployeesApi.Responses;
namespace Api.ExternalDeps.EmployeesApi.Responses;

public class EmployeesResponse
{
Expand Down
34 changes: 34 additions & 0 deletions Api/Features/Items/CreateItem/CreateItemHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Application.Commands;

namespace Api.Features.Items.CreateItem;

public class CreateItemHandler
{
private readonly CreateItemCommand _createItemCommand;

public CreateItemHandler(CreateItemCommand createItemCommand)
{
_createItemCommand = createItemCommand;
}

public async Task<CreateItemResponse> HandleAsync(CreateItemRequest createItemRequest)
{
var createItemCommandParams = new CreateItemCommandParams
{
Name = createItemRequest.Name,
SerialNumber = createItemRequest.SerialNumber,
ItemTypeId = createItemRequest.ItemTypeId,
Price = createItemRequest.Price,
Description = createItemRequest.Description,
PurchaseDate = createItemRequest.PurchaseDate,
HolderEmployeeId = createItemRequest.HolderEmployeeId
};

var newItemId = await _createItemCommand.ExecuteAsync(createItemCommandParams);

return new CreateItemResponse()
{
NewItemId = newItemId
};
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;

namespace Api.Requests;
namespace Api.Features.Items.CreateItem;

public class CreateItemRequest
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Api.Responses;
namespace Api.Features.Items.CreateItem;

public class CreateItemResponse
{
Expand Down
48 changes: 48 additions & 0 deletions Api/Features/Items/GetAllItems/GetAllItemsHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Api.ExternalDeps.EmployeesApi;
using Api.Responses;
using Application.Queries;

namespace Api.Features.Items.GetAllItems;

public class GetAllItemsHandler
{
private readonly AllItemsQuery _allItemsQuery;
private readonly EmployeesApi _employeesApi;

public GetAllItemsHandler(
AllItemsQuery allItemsQuery,
EmployeesApi employeesApi
)
{
_allItemsQuery = allItemsQuery;
_employeesApi = employeesApi;
}

public async Task<GetAllItemsResponse> HandleAsync()
{
var items = await _allItemsQuery.GetAsync();

var allEmployeesResponse = await _employeesApi.GetAllEmployeesAsync();

return new GetAllItemsResponse
{
Items = items
.Select(x => new ItemDto
{
Id = x.Id,
Name = x.Name,
SerialNumber = x.SerialNumber,
ItemType = new ItemTypeDto
{
Id = x.ItemType.Id,
Name = x.ItemType.Name
},
Price = x.Price,
Description = x.Description,
PurchaseDate = x.PurchaseDate,
HolderEmployee = HolderEmployeeMapper.MapToEmployeeDto(x.HolderEmployeeId, allEmployeesResponse)
})
.ToList()
};
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace Api.Responses;
using Api.Responses;

public class ItemsResponse
namespace Api.Features.Items.GetAllItems;

public class GetAllItemsResponse
{
public required List<ItemDto> Items { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Api.EnternalDeps.EmployeesApi.Responses;
using Api.Responses;
using Api.ExternalDeps.EmployeesApi.Responses;

namespace Api.Mappers;
namespace Api.Features.Items.GetAllItems;

public class HolderEmployeeMapper
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Api.EnternalDeps.EmployeesApi.Responses;
using Api.ExternalDeps.EmployeesApi.Responses;
using Xunit;

namespace Api.Mappers;
namespace Api.Features.Items.GetAllItems;

public class HolderEmployeeMapperTests
{
Expand Down
58 changes: 58 additions & 0 deletions Api/Features/Items/ItemsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.ComponentModel.DataAnnotations;
using Api.Features.Items.CreateItem;
using Api.Features.Items.GetAllItems;
using Application.Commands;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using TourmalineCore.AspNetCore.JwtAuthentication.Core.Filters;

namespace Api.Features.Items;

[Authorize]
[ApiController]
[Route("api/items")]
public class ItemsController : ControllerBase
{
/// <summary>
/// Get all items
/// </summary>
[RequiresPermission(UserClaimsProvider.CanViewItems)]
[HttpGet]
public Task<GetAllItemsResponse> GetAllItemsAsync(
[FromServices] GetAllItemsHandler getAllItemsHandler
)
{
return getAllItemsHandler.HandleAsync();
}

/// <summary>
/// Add an item
/// </summary>
/// <param name="createItemRequest"></param>
[RequiresPermission(UserClaimsProvider.CanManageItems)]
[HttpPost]
public Task<CreateItemResponse> CreateItemAsync(
[FromServices] CreateItemHandler createItemHandler,
[Required][FromBody] CreateItemRequest createItemRequest
)
{
return createItemHandler.HandleAsync(createItemRequest);
}

/// <summary>
/// Deletes specific item
/// </summary>
/// <param name="itemId"></param>
[RequiresPermission(UserClaimsProvider.AUTO_TESTS_ONLY_IsItemsHardDeleteAllowed)]
[HttpDelete("{itemId}/hard-delete")]
public async Task<object> HardDeleteItemAsync(
[FromServices] HardDeleteItemCommand hardDeleteItemCommand,
[Required][FromRoute] long itemId
)
{
return new
{
isDeleted = await hardDeleteItemCommand.ExecuteAsync(itemId)
};
}
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# inner-circle-items-api

<!-- auto-generated -->
[![coverage](https://img.shields.io/badge/e2e_coverage-81.90%25-olivedrab)](https://github.com/TourmalineCore/inner-circle-items-api/actions/workflows/calculate-tests-coverage-on-pull-request.yml)
[![coverage](https://img.shields.io/badge/units_coverage-17.65%25-crimson)](https://github.com/TourmalineCore/inner-circle-items-api/actions/workflows/calculate-tests-coverage-on-pull-request.yml)
[![coverage](https://img.shields.io/badge/full_coverage-89.78%25-olivedrab)](https://github.com/TourmalineCore/inner-circle-items-api/actions/workflows/calculate-tests-coverage-on-pull-request.yml)
[![coverage](https://img.shields.io/badge/e2e_coverage-82.22%25-olivedrab)](https://github.com/TourmalineCore/inner-circle-items-api/actions/workflows/calculate-tests-coverage-on-pull-request.yml)
[![coverage](https://img.shields.io/badge/units_coverage-17.34%25-crimson)](https://github.com/TourmalineCore/inner-circle-items-api/actions/workflows/calculate-tests-coverage-on-pull-request.yml)
[![coverage](https://img.shields.io/badge/full_coverage-89.96%25-olivedrab)](https://github.com/TourmalineCore/inner-circle-items-api/actions/workflows/calculate-tests-coverage-on-pull-request.yml)
<!-- auto-generated -->

This repo contains Inner Circle Items API.
Expand Down