on master help sign in
Resolved #30.
0fd03c1iko
denis/src/Data/Schema.hs+4−2
@@ -23,7 +23,8 @@ type Schema =
23 '[
23 '[
24 "userId" ::: 'Def :=> 'NotNull 'PGint8,
24 "userId" ::: 'Def :=> 'NotNull 'PGint8,
25 "firstName" ::: 'NoDef :=> 'NotNull 'PGtext,
25 "firstName" ::: 'NoDef :=> 'NotNull 'PGtext,
26+ "middleName" ::: 'NoDef :=> 'NotNull 'PGtext,
26− "secondName" ::: 'NoDef :=> 'NotNull 'PGtext
27+ "lastName" ::: 'NoDef :=> 'NotNull 'PGtext
27 ]),
28 ]),
28 "posts" ::: 'Table ( '[
29 "posts" ::: 'Table ( '[
29 "pk_posts" ::: 'PrimaryKey '["postRowId"],
30 "pk_posts" ::: 'PrimaryKey '["postRowId"],
@@ -93,7 +94,8 @@ createTables :: Definition '[] Schema
93createTables = createTable #users (
94createTables = createTable #users (
94 serial8 `as` #userId :*
95 serial8 `as` #userId :*
95 notNullable text `as` #firstName :*
96 notNullable text `as` #firstName :*
96− notNullable text `as` #secondName
97+ notNullable text `as` #middleName :*
98+ notNullable text `as` #lastName
97 ) (
99 ) (
98 primaryKey #userId `as` #pk_users
100 primaryKey #userId `as` #pk_users
99 ) >>> createTable #posts (
101 ) >>> createTable #posts (
denis/src/Data/User.hs+6−4
@@ -22,7 +22,7 @@ import Servant.Docs (ToSample, toSamples, samples)
22-- MARK: Documentation
22-- MARK: Documentation
23
23
24instance ToSample User where
24instance ToSample User where
25− toSamples _ = samples [User 8 "Vasya" "Pupkin", User 69 "Seva" "Leonidov"]
25+ toSamples _ = samples [User 8 "Vasya" "Pupkinovuch" "Pupkin", User 69 "Seva" "Algebrovich" "Leonidov"]
26
26
27-- MARK: Implementation
27-- MARK: Implementation
28
28
@@ -31,7 +31,8 @@ type UserId = Int64
31data User = User {
31data User = User {
32 userId :: UserId,
32 userId :: UserId,
33 firstName :: Text,
33 firstName :: Text,
34− secondName :: Text
34+ middleName :: Text,
35+ lastName :: Text
35} deriving (GHC.Generic)
36} deriving (GHC.Generic)
36
37
37instance SOP.Generic User
38instance SOP.Generic User
@@ -39,8 +40,9 @@ instance SOP.Generic User
39instance SOP.HasDatatypeInfo User
40instance SOP.HasDatatypeInfo User
40
41
41instance ToJSON User where
42instance ToJSON User where
42− toJSON (User uId fName sName) = object [
43+ toJSON (User uId fName mName lName) = object [
43 "id" .= uId,
44 "id" .= uId,
44 "firstName" .= fName,
45 "firstName" .= fName,
45− "secondName" .= sName
46+ "middleName" .= mName,
47+ "lastName" .= lName
46 ]
48 ]