Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CleanArchitecture
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CleanArchitecture
Commits
cf25c178
Commit
cf25c178
authored
Feb 08, 2020
by
Steve Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding working endpoint demo - run it from Swagger
parent
f0ff77b4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
0 deletions
+60
-0
BaseEndpoint.cs
src/CleanArchitecture.Web/Endpoints/BaseEndpoint.cs
+9
-0
CreateHandler.cs
...leanArchitecture.Web/Endpoints/ToDoItems/CreateHandler.cs
+51
-0
No files found.
src/CleanArchitecture.Web/Endpoints/BaseEndpoint.cs
0 → 100644
View file @
cf25c178
using
Microsoft.AspNetCore.Mvc
;
namespace
CleanArchitecture.Web.Endpoints
{
public
abstract
class
BaseEndpoint
<
TRequest
,
TResponse
>
:
ControllerBase
{
public
abstract
ActionResult
<
TResponse
>
Handle
(
TRequest
request
);
}
}
src/CleanArchitecture.Web/Endpoints/ToDoItems/CreateHandler.cs
0 → 100644
View file @
cf25c178
using
CleanArchitecture.Core.Entities
;
using
CleanArchitecture.SharedKernel.Interfaces
;
using
Microsoft.AspNetCore.Mvc
;
using
System.ComponentModel.DataAnnotations
;
namespace
CleanArchitecture.Web.Endpoints.ToDoItems
{
public
class
CreateHandler
:
BaseEndpoint
<
CreateCommand
,
CreatedResult
>
{
private
readonly
IRepository
_repository
;
public
CreateHandler
(
IRepository
repository
)
{
_repository
=
repository
;
}
[
HttpPost
(
"/endpoints/items"
)]
public
override
ActionResult
<
CreatedResult
>
Handle
([
FromBody
]
CreateCommand
request
)
{
var
todoItem
=
new
ToDoItem
()
{
Title
=
request
.
Title
,
Description
=
request
.
Description
};
_repository
.
Add
(
todoItem
);
var
result
=
new
CreatedResult
{
Id
=
todoItem
.
Id
,
Title
=
todoItem
.
Title
,
Description
=
todoItem
.
Description
};
return
Ok
(
result
);
}
}
// Imagine these are separate classes attached to the Handler/Endpoint with + expansion in VS
public
class
CreateCommand
{
[
Required
]
public
string
Title
{
get
;
set
;
}
[
Required
]
public
string
Description
{
get
;
set
;
}
}
public
class
CreatedResult
:
CreateCommand
{
public
int
Id
{
get
;
set
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment