Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Johannes Loher
d-webservice-example
Commits
940aae65
Commit
940aae65
authored
Jun 05, 2019
by
Johannes Loher
Browse files
Use optional package
parent
f9f4bbf1
Pipeline
#153
passed with stages
Changes
8
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
dub.sdl
View file @
940aae65
...
...
@@ -4,8 +4,9 @@ authors "Johannes Loher"
copyright "Copyright © 2018, Johannes Loher"
license "MIT"
dependency "aedi" version="~>1.0.0"
dependency "fluent-asserts" version="~>0.12.3"
dependency "vibe-d" version="~>0.8.4"
dependency "fluent-asserts" version="~>0.12.4"
dependency "vibe-d" version="~>0.8.5"
dependency "optional" version="~>0.15.0"
configuration "executable" {
targetType "executable"
...
...
dub.selections.json
View file @
940aae65
...
...
@@ -2,21 +2,24 @@
"fileVersion"
:
1
,
"versions"
:
{
"aedi"
:
"1.0.0"
,
"bolts"
:
"0.11.1"
,
"botan"
:
"1.12.10"
,
"botan-math"
:
"1.0.3"
,
"ddmp"
:
"0.0.1-0.dev.3"
,
"diet-ng"
:
"1.5.0"
,
"eventcore"
:
"0.8.4
0
"
,
"fluent-asserts"
:
"0.12.
3
"
,
"libasync"
:
"0.8.
3
"
,
"eventcore"
:
"0.8.4
3
"
,
"fluent-asserts"
:
"0.12.
4
"
,
"libasync"
:
"0.8.
4
"
,
"libdparse"
:
"0.8.8"
,
"libevent"
:
"2.0.2+2.0.16"
,
"memutils"
:
"0.4.13"
,
"mir-linux-kernel"
:
"1.0.1"
,
"openssl"
:
"1.1.6+1.0.1g"
,
"optional"
:
"0.15.0"
,
"silly"
:
"0.8.2"
,
"stdx-allocator"
:
"2.77.5"
,
"taggedalgebraic"
:
"0.1
0.12
"
,
"vibe-core"
:
"1.
4.6
"
,
"vibe-d"
:
"0.8.
4
"
"taggedalgebraic"
:
"0.1
1.4
"
,
"vibe-core"
:
"1.
6.2
"
,
"vibe-d"
:
"0.8.
5
"
}
}
source/d_webservice_example/business/todo_service.d
View file @
940aae65
...
...
@@ -36,10 +36,13 @@ public:
{
import
std
.
exception
:
enforce
;
import
vibe
.
http
.
common
:
HTTPStatus
,
HTTPStatusException
;
import
optional
.
optional
:
orElse
;
immutable
maybeTodo
=
todoRepository
.
findByUuid
(
uuid
);
enforce
(!
maybeTodo
.
isNull
,
new
HTTPStatusException
(
HTTPStatus
.
NotFound
));
return
maybeTodo
.
get
;
immutable
todo
=
todoRepository
.
findByUuid
(
uuid
).
orElse
!(
function
Todo
()
{
throw
new
HTTPStatusException
(
HTTPStatus
.
NotFound
);
});
return
todo
;
}
Todo
updateTodo
(
UUID
uuid
,
const
TodoUpdateDO
todoUpdate
)
@safe
...
...
@@ -66,10 +69,10 @@ public:
interface
TodoRepository
{
import
std
.
typecons
:
Nullable
;
import
optional
.
optional
:
Optional
;
Todo
save
(
Todo
todo
)
@safe
;
bool
remove
(
Todo
todo
)
@safe
;
Nullable
!
Todo
findByUuid
(
UUID
uuid
)
@safe
;
Optional
!
Todo
findByUuid
(
UUID
uuid
)
@safe
;
Todo
[]
findAll
()
@safe
;
}
source/d_webservice_example/controller/todo_controller.d
View file @
940aae65
...
...
@@ -5,22 +5,22 @@ import std.typecons : Nullable;
import
std
.
uuid
:
UUID
;
import
vibe
.
web
.
rest
:
path
;
@path
(
"/api/v1/
todos
"
)
@path
(
"/api/v1/"
)
interface
TodoApi
{
@path
(
"
/
"
)
@path
(
"
todos
"
)
TodoTO
addTodo
(
string
title
,
string
content
)
@safe
;
@path
(
"
/
"
)
@path
(
"
todos
"
)
TodoTO
[]
getTodos
()
@safe
;
@path
(
"/:uuid"
)
@path
(
"
todos
/:uuid"
)
TodoTO
getTodo
(
UUID
_uuid
)
@safe
;
@path
(
"/:uuid"
)
@path
(
"
todos
/:uuid"
)
TodoTO
updateTodo
(
UUID
_uuid
,
Nullable
!
string
title
,
Nullable
!
string
content
)
@safe
;
@path
(
"/:uuid"
)
@path
(
"
todos
/:uuid"
)
void
deleteTodo
(
UUID
_uuid
)
@safe
;
}
...
...
source/d_webservice_example/dataaccess/in_memory_todo_repository.d
View file @
940aae65
...
...
@@ -10,7 +10,7 @@ version (unittest)
class
InMemoryTodoRepository
:
TodoRepository
{
import
d_webservice_example
.
model
.
todo
:
Todo
;
import
std
.
typecons
:
Nullable
,
nullable
;
import
optional
.
optional
:
Optional
;
import
std
.
uuid
:
randomUUID
,
UUID
;
private
:
...
...
@@ -71,15 +71,11 @@ public:
return
todos
.
byValue
.
array
;
}
override
Nullable
!
Todo
findByUuid
(
UUID
uuid
)
override
Optional
!
Todo
findByUuid
(
UUID
uuid
)
{
import
std
.
algorithm
.
searching
:
find
;
import
d_webservice_example
.
util
.
algorithm
:
find
First
;
auto
foundTodos
=
todos
.
byValue
.
find
!(
todo
=>
todo
.
uuid
==
uuid
);
if
(
foundTodos
.
empty
)
return
Nullable
!
Todo
.
init
;
else
return
nullable
(
foundTodos
.
front
);
return
todos
.
byValue
.
findFirst
!(
todo
=>
todo
.
uuid
==
uuid
);
}
override
bool
remove
(
Todo
todo
)
...
...
source/d_webservice_example/transport/todo_to.d
View file @
940aae65
...
...
@@ -2,7 +2,6 @@ module d_webservice_example.transport.todo_to;
struct
TodoTO
{
import
std
.
typecons
:
Nullable
;
import
std
.
uuid
:
UUID
;
UUID
uuid
;
...
...
source/d_webservice_example/util/algorithm.d
0 → 100644
View file @
940aae65
module
d_webservice_example
.
util
.
algorithm
;
import
d_webservice_example
.
util
.
meta
:
from
;
auto
findFirst
(
alias
pred
,
InputRange
)(
InputRange
haystack
)
if
(
from
!
"std.range"
.
isInputRange
!
InputRange
)
{
import
optional
.
optional
:
toOptional
;
import
std
.
algorithm
.
searching
:
find
;
import
std
.
range
:
take
;
return
haystack
.
find
!(
pred
).
take
(
1
).
toOptional
();
}
source/d_webservice_example/util/meta.d
0 → 100644
View file @
940aae65
module
d_webservice_example
.
util
.
meta
;
template
from
(
string
moduleName
)
{
mixin
(
"import from = "
~
moduleName
~
";"
);
}
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