Skip to content

Commit 5d16db7

Browse files
author
Brian Jones
committedMay 15, 2020
Add/fix some documentation
1 parent 2d4a38f commit 5d16db7

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed
 

‎backend/src/DataAccess/Todo.hs

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ toTodoR t =
2222
(M.TodoDesc $ todoDesc t)
2323
(toEnum $ todoStatus t)
2424

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+
2532
class Monad m => TodoDAM m where
2633
getTodos :: HasCallStack => m [M.TodoR]
2734
getTodo :: HasCallStack => M.TodoId -> m (Maybe M.TodoR)

‎backend/src/Errors.hs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import Servant
99
import Types
1010
--------------------------------------------------------------------------------
1111

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.
1215
handleError :: AppContext -> IO (Either AppError a) -> Handler a
1316
handleError ctx f = Handler . ExceptT $ convert ctx f
1417

‎backend/src/Routes.hs

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Models.Todo
1212
-- In order to get proper route type safety and avoid spelling mistakes like
1313
-- "user" vs "uesr" in urls we create type synonyms which end up as a Symbol
1414
type ApiTerm = "api"
15-
type Version1Term = "v2"
15+
type Version1Term = "v1"
1616

1717
-- The top level composition of all of our routes appended together
1818
type Routes =
@@ -36,21 +36,24 @@ type RoutesTodo =
3636
type TodoListTerm = "todos"
3737
type TodoTerm = "todo"
3838

39+
-- GET /api/v1/todos
3940
type GetTodos =
4041
TodoListTerm :>
4142
Get '[JSON] [TodoR]
4243

43-
-- GET /api/v2/todo/{id}
44+
-- GET /api/v1/todo/{id}
4445
type GetTodo =
4546
TodoTerm :>
4647
Capture "todo_id" TodoId :>
4748
Get '[JSON] TodoR
4849

50+
-- POST /api/v1/todo
4951
type CreateTodo =
5052
TodoTerm :>
5153
ReqBody '[JSON] TodoC :>
5254
Post '[JSON] TodoR
5355

56+
-- PUT /api/v1/todo
5457
type UpdateTodo =
5558
TodoTerm :>
5659
ReqBody '[JSON] TodoU :>

0 commit comments

Comments
 (0)
Please sign in to comment.