on master help sign in
Resolved #30.
commit0fd03c14d8fd4042eaa5f3863568ba7acdc325a4 authoriko <ilyakooo0@gmail.com> dateFri 8 Mar 2019, 00:08 (8 years ago) parented66c43
2 files changed+10−6
denis/src/Data/Schema.hs+4−2 denis/src/Data/User.hs+6−4
denis/src/Data/Schema.hs+4−2
@@ -23,7 +23,8 @@ type Schema =
2323 '[
2424 "userId" ::: 'Def :=> 'NotNull 'PGint8,
2525 "firstName" ::: 'NoDef :=> 'NotNull 'PGtext,
26− "secondName" ::: 'NoDef :=> 'NotNull 'PGtext
26+ "middleName" ::: 'NoDef :=> 'NotNull 'PGtext,
27+ "lastName" ::: 'NoDef :=> 'NotNull 'PGtext
2728 ]),
2829 "posts" ::: 'Table ( '[
2930 "pk_posts" ::: 'PrimaryKey '["postRowId"],
@@ -93,7 +94,8 @@ createTables :: Definition '[] Schema
9394createTables = createTable #users (
9495 serial8 `as` #userId :*
9596 notNullable text `as` #firstName :*
96− notNullable text `as` #secondName
97+ notNullable text `as` #middleName :*
98+ notNullable text `as` #lastName
9799 ) (
98100 primaryKey #userId `as` #pk_users
99101 ) >>> createTable #posts (
denis/src/Data/User.hs+6−4
@@ -22,7 +22,7 @@ import Servant.Docs (ToSample, toSamples, samples)
2222-- MARK: Documentation
2323
2424instance 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"]
2626
2727-- MARK: Implementation
2828
@@ -31,7 +31,8 @@ type UserId = Int64
3131data User = User {
3232 userId :: UserId,
3333 firstName :: Text,
34− secondName :: Text
34+ middleName :: Text,
35+ lastName :: Text
3536} deriving (GHC.Generic)
3637
3738instance SOP.Generic User
@@ -39,8 +40,9 @@ instance SOP.Generic User
3940instance SOP.HasDatatypeInfo User
4041
4142instance ToJSON User where
42− toJSON (User uId fName sName) = object [
43+ toJSON (User uId fName mName lName) = object [
4344 "id" .= uId,
4445 "firstName" .= fName,
45− "secondName" .= sName
46+ "middleName" .= mName,
47+ "lastName" .= lName
4648 ]