Commit b371971d authored by Steve Smith's avatar Steve Smith

Renaming to Endpoints.

Added ListEndpoint
parent cf25c178
...@@ -2,8 +2,13 @@ ...@@ -2,8 +2,13 @@
namespace CleanArchitecture.Web.Endpoints namespace CleanArchitecture.Web.Endpoints
{ {
public abstract class BaseEndpoint<TRequest,TResponse> : ControllerBase public abstract class BaseEndpoint<TRequest, TResponse> : ControllerBase
{ {
public abstract ActionResult<TResponse> Handle(TRequest request); public abstract ActionResult<TResponse> Handle(TRequest request);
} }
public abstract class BaseEndpoint<TResponse> : ControllerBase
{
public abstract ActionResult<TResponse> Handle();
}
} }
...@@ -5,11 +5,11 @@ using System.ComponentModel.DataAnnotations; ...@@ -5,11 +5,11 @@ using System.ComponentModel.DataAnnotations;
namespace CleanArchitecture.Web.Endpoints.ToDoItems namespace CleanArchitecture.Web.Endpoints.ToDoItems
{ {
public class CreateHandler : BaseEndpoint<CreateCommand, CreatedResult> public class CreateEndpoint : BaseEndpoint<CreateCommand, CreatedResult>
{ {
private readonly IRepository _repository; private readonly IRepository _repository;
public CreateHandler(IRepository repository) public CreateEndpoint(IRepository repository)
{ {
_repository = repository; _repository = repository;
} }
......
using CleanArchitecture.Core.Entities;
using CleanArchitecture.SharedKernel.Interfaces;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace CleanArchitecture.Web.Endpoints.ToDoItems
{
public class ListEndpoint : BaseEndpoint<List<ToDoItemResult>>
{
private readonly IRepository _repository;
public ListEndpoint(IRepository repository)
{
_repository = repository;
}
[HttpGet("/endpoints/items")]
public override ActionResult<List<ToDoItemResult>> Handle()
{
var result = _repository.List<ToDoItem>()
.Select(i => new ToDoItemResult
{
Id = i.Id,
Title = i.Title,
Description = i.Description
});
return Ok(result);
}
}
// Imagine these are separate classes attached to the Handler/Endpoint with + expansion in VS
public class ToDoItemResult
{
public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment