-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo.pact
37 lines (30 loc) · 966 Bytes
/
todo.pact
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(module todo-app CAP
(defcap CAP() true)
(defschema todo-schema
id:string
desc:string
complete:bool)
(deftable todo-table:{todo-schema})
(defun create-todo(id:string desc:string)
@doc "Create a todo in the database"
; @model [(property desc (enforce (> (length desc) 3) "the description should be longer than 3"))]
(enforce (> (length desc) 3) "the description should be longer than 3")
(insert todo-table id {
"id": id,
"desc": desc,
"complete":false
})
)
(defun read-todo(id:string)
(read todo-table id)
)
(defun update-todo(id:string desc:string)
(with-read todo-table id {'id:=id}
(update todo-table id { "desc": desc }))
)
(defun complete-todo(id:string)
(with-read todo-table id {'id:=id}
(update todo-table id {"complete": true}))
)
)
(create-table todo-table)