-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBookShop.hs
72 lines (51 loc) · 1.67 KB
/
BookShop.hs
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
module BookShop where
import qualified System.Random as SR
data Cat = Cat String deriving Show
data Address = Address String deriving Show
data Book =
Book { id :: String
, title :: String
, author :: String
} deriving Show
data Order =
Order { customer :: Cat
, shipping_address :: Address
, books :: [Book]
} deriving Show
data ValidationError
= InvalidIncomingData
| CatNotFound
| InvalidAddress
| BookNotFound
deriving Show
type JsonData = (String, String, [(String, String)])
test_data :: JsonData
test_data =
("Tihon", "Coolcat str 7/42 Minsk Belarus",
[ ("Scott Wlaschin", "Domain Modeling Made Functional")
, ("Стивен Строгац", "Удовольствие от Х")
, ("Mikito Takada", "Distributed systems for fun and profit")
])
test_data' :: JsonData
test_data' =
("Marfa", "Coolcat str 7/42 Minsk Belarus",
[ ("Scott Wlaschin", "Domain Modeling Made Functional")
, ("Mikito Takada", "Distributed systems for fun and profit")
])
validate_incoming_data :: JsonData -> Either ValidationError JsonData
validate_incoming_data json_data =
Right json_data
validate_cat :: String -> Either ValidationError Cat
validate_cat cat_name =
case cat_name of
"Tihon" -> Right $ Cat cat_name
_ -> Left CatNotFound
validate_address :: String -> Either ValidationError Address
validate_address addr_str =
Right $ Address addr_str
get_book :: String -> String -> Either ValidationError Book
get_book title author =
Right $ Book "ISBN 978-5-00057-917-6" title author
create_order :: Cat -> Address -> [Book] -> Order
create_order cat address books =
Order cat address books