File tree 3 files changed +15
-2
lines changed
3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,13 @@ toTodoR t =
22
22
(M. TodoDesc $ todoDesc t)
23
23
(toEnum $ todoStatus t)
24
24
25
+ -- While not "lawful" typeclasses, we take advantage of the abstraction
26
+ -- so that we can write an intermediate layer between our Domain and
27
+ -- actual datasource (in this particular case a Database layer).
28
+ --
29
+ -- This then allows us to test the Domain logic using the same typeclass
30
+ -- but in some alternative Monad, like Identity or State.
31
+
25
32
class Monad m => TodoDAM m where
26
33
getTodos :: HasCallStack => m [M. TodoR ]
27
34
getTodo :: HasCallStack => M. TodoId -> m (Maybe M. TodoR )
Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ import Servant
9
9
import Types
10
10
--------------------------------------------------------------------------------
11
11
12
+ -- Our top level handler captures any errors that get generated and properly
13
+ -- converts them into an ErrorJSON, logs somewhere, and returns the right
14
+ -- HTTP error code.
12
15
handleError :: AppContext -> IO (Either AppError a ) -> Handler a
13
16
handleError ctx f = Handler . ExceptT $ convert ctx f
14
17
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import Models.Todo
12
12
-- In order to get proper route type safety and avoid spelling mistakes like
13
13
-- "user" vs "uesr" in urls we create type synonyms which end up as a Symbol
14
14
type ApiTerm = " api"
15
- type Version1Term = " v2 "
15
+ type Version1Term = " v1 "
16
16
17
17
-- The top level composition of all of our routes appended together
18
18
type Routes =
@@ -36,21 +36,24 @@ type RoutesTodo =
36
36
type TodoListTerm = " todos"
37
37
type TodoTerm = " todo"
38
38
39
+ -- GET /api/v1/todos
39
40
type GetTodos =
40
41
TodoListTerm :>
41
42
Get '[JSON ] [TodoR ]
42
43
43
- -- GET /api/v2 /todo/{id}
44
+ -- GET /api/v1 /todo/{id}
44
45
type GetTodo =
45
46
TodoTerm :>
46
47
Capture " todo_id" TodoId :>
47
48
Get '[JSON ] TodoR
48
49
50
+ -- POST /api/v1/todo
49
51
type CreateTodo =
50
52
TodoTerm :>
51
53
ReqBody '[JSON ] TodoC :>
52
54
Post '[JSON ] TodoR
53
55
56
+ -- PUT /api/v1/todo
54
57
type UpdateTodo =
55
58
TodoTerm :>
56
59
ReqBody '[JSON ] TodoU :>
You can’t perform that action at this time.
0 commit comments