on master help sign in
Removed email from users
fc4e27diko
denis/src/Data/Query.hs+22−13
@@ -58,7 +58,8 @@ module Data.Query (
58 deactivateToken,
58 deactivateToken,
59 searchUsers,
59 searchUsers,
60 searchTags,
60 searchTags,
61− updateUser
61+ updateUser,
62+ UserUpdateRow(..)
62 ) where
63 ) where
63
64
64import Squeal.PostgreSQL
65import Squeal.PostgreSQL
@@ -287,7 +288,7 @@ getChannelForUserQ = selectStar $
287 from (table #channels) &
288 from (table #channels) &
288 where_ (#namedChannelFullOwner .== param @1 .&& #namedChannelFullId .== param @2)
289 where_ (#namedChannelFullOwner .== param @1 .&& #namedChannelFullId .== param @2)
289
290
290−updateUserQ :: Manipulation Schema (TuplePG (User FacultyUrl)) (RowPG (Only UserId))
291+updateUserQ :: Manipulation Schema (TuplePG (UserUpdateRow)) (RowPG (Only UserId))
291updateUserQ = update #users (
292updateUserQ = update #users (
292 Same `as` #userRowId :*
293 Same `as` #userRowId :*
293 Set (param @2) `as` #userRowFirstName :*
294 Set (param @2) `as` #userRowFirstName :*
@@ -296,7 +297,7 @@ updateUserQ = update #users (
296 Set (param @5) `as` #userRowFacultyUrl :*
297 Set (param @5) `as` #userRowFacultyUrl :*
297 Same `as` #userRowEmail :*
298 Same `as` #userRowEmail :*
298 Same `as` #userRowIsValidated)
299 Same `as` #userRowIsValidated)
299− (#userRowId .== param @1 .&& #userRowEmail .== param @6)
300+ (#userRowId .== param @1)
300 (Returning $ #userRowId `as` #fromOnly)
301 (Returning $ #userRowId `as` #fromOnly)
301
302
302getAllChannelsForUserQ :: Query Schema (TuplePG (Only UserId)) (RowPG NamedChannelFull)
303getAllChannelsForUserQ :: Query Schema (TuplePG (Only UserId)) (RowPG NamedChannelFull)
@@ -745,9 +746,18 @@ instance ToJSON UserCreation where
745 ]
746 ]
746
747
747instance FromJSON UserCreation where
748instance FromJSON UserCreation where
748− parseJSON = withObject "named channel" $ \e ->
749+ parseJSON = withObject "user creation" $ \e ->
749 UserCreation <$> e .: "firstName" <*> e .: "middleName" <*> e .: "lastName" <*> e .: "faculty" <*> e .: "email"
750 UserCreation <$> e .: "firstName" <*> e .: "middleName" <*> e .: "lastName" <*> e .: "faculty" <*> e .: "email"
750
751
752+data UserUpdateRow = UserUpdateRow {
753+ userUpdateRowId :: UserId,
754+ userUpdateRowFirstName :: Text,
755+ userUpdateRowMiddleName :: Text,
756+ userUpdateRowLastName :: Text,
757+ userUpdateRowUserFaculty :: FacultyUrl
758+} deriving (GHC.Generic, SOP.Generic, SOP.HasDatatypeInfo)
759+
760+
751data NamedChannelCreation = NamedChannelCreation {
761data NamedChannelCreation = NamedChannelCreation {
752 namedChannelCreationOwner :: UserId,
762 namedChannelCreationOwner :: UserId,
753 namedChannelCreationName :: Text,
763 namedChannelCreationName :: Text,
@@ -1055,19 +1065,18 @@ deactivateToken uId dData = fmap fromOnly <$> (manipulateParams deactivateTokenQ
1055getVerifiedToken :: UserId -> ByteString -> StaticPQ (Maybe Token)
1065getVerifiedToken :: UserId -> ByteString -> StaticPQ (Maybe Token)
1056getVerifiedToken uId tokenData = runQueryParams getVerifiedTokenQ (uId, hash tokenData) >>= firstRow
1066getVerifiedToken uId tokenData = runQueryParams getVerifiedTokenQ (uId, hash tokenData) >>= firstRow
1057
1067
1058−updateUser :: (User FacultyUrl) -> StaticPQ (Maybe UserId)
1068+updateUser :: (UserUpdateRow) -> StaticPQ (Maybe UserId)
1059updateUser user = fmap fromOnly <$> (manipulateParams updateUserQ (normalizeUser user) >>= firstRow)
1069updateUser user = fmap fromOnly <$> (manipulateParams updateUserQ (normalizeUser user) >>= firstRow)
1060
1070
1061-- MARK: Utils
1071-- MARK: Utils
1062
1072
1063−normalizeUser :: User FacultyUrl -> User FacultyUrl
1073+normalizeUser :: UserUpdateRow -> UserUpdateRow
1064−normalizeUser User{..} = User {
1074+normalizeUser UserUpdateRow{..} = UserUpdateRow {
1065− userId = userId,
1075+ userUpdateRowId = userUpdateRowId,
1066− firstName = T.strip $ firstName,
1076+ userUpdateRowFirstName = T.strip $ userUpdateRowFirstName,
1067− middleName = T.strip $ middleName,
1077+ userUpdateRowMiddleName = T.strip $ userUpdateRowMiddleName,
1068− lastName = T.strip $ lastName,
1078+ userUpdateRowLastName = T.strip $ userUpdateRowLastName,
1069− userFaculty = T.toLower . T.strip $ userFaculty,
1079+ userUpdateRowUserFaculty = T.toLower . T.strip $ userUpdateRowUserFaculty
1070− userEmail = T.toLower . T.strip $ userEmail
1071}
1080}
1072
1081
1073data UserRow = UserRow {
1082data UserRow = UserRow {
denis/src/Data/User.hs+26−1
@@ -11,7 +11,8 @@
11module Data.User (
11module Data.User (
12 User(..),
12 User(..),
13 UserId,
13 UserId,
14− UserEmail
14+ UserEmail,
15+ UserUpdate(..)
15) where
16) where
16
17
17import Data.Int (Int64)
18import Data.Int (Int64)
@@ -21,12 +22,16 @@ import Data.Text (Text)
21import Data.Aeson
22import Data.Aeson
22import Servant.Docs (ToSample, toSamples, samples)
23import Servant.Docs (ToSample, toSamples, samples)
23import Data.Proxy
24import Data.Proxy
25+import Data.Faculty
24
26
25-- MARK: Documentation
27-- MARK: Documentation
26
28
27instance (ToSample f) => ToSample (User f) where
29instance (ToSample f) => ToSample (User f) where
28 toSamples _ = samples $ [User 8 "Vasya" "Pupkinovuch" "Pupkin", User 69 "Seva" "Algebrovich" "Leonidov"] <*> (map snd $ toSamples Proxy) <*> ["foo@hse.ru"]
30 toSamples _ = samples $ [User 8 "Vasya" "Pupkinovuch" "Pupkin", User 69 "Seva" "Algebrovich" "Leonidov"] <*> (map snd $ toSamples Proxy) <*> ["foo@hse.ru"]
29
31
32+instance ToSample (UserUpdate) where
33+ toSamples _ = samples $ [UserUpdate "Vasya" "Pupkinovuch" "Pupkin", UserUpdate "Seva" "Algebrovich" "Leonidov"] <*> ["cs.hse.ru/dse/"]
34+
30-- MARK: Implementation
35-- MARK: Implementation
31
36
32type UserId = Int64
37type UserId = Int64
@@ -54,3 +59,23 @@ instance (ToJSON f) => ToJSON (User f) where
54instance (FromJSON f) => FromJSON (User f) where
59instance (FromJSON f) => FromJSON (User f) where
55 parseJSON = withObject "named channel" $ \e ->
60 parseJSON = withObject "named channel" $ \e ->
56 User <$> e .: "id" <*> e .: "firstName" <*> e .: "middleName" <*> e .: "lastName" <*> e .: "faculty" <*> e .: "email"
61 User <$> e .: "id" <*> e .: "firstName" <*> e .: "middleName" <*> e .: "lastName" <*> e .: "faculty" <*> e .: "email"
62+
63+data UserUpdate = UserUpdate {
64+ userUpdateFirstName :: Text,
65+ userUpdateMiddleName :: Text,
66+ userUpdateLastName :: Text,
67+ userUpdateUserFaculty :: FacultyUrl
68+} deriving (GHC.Generic, SOP.Generic, SOP.HasDatatypeInfo)
69+
70+instance ToJSON UserUpdate where
71+ toJSON (UserUpdate fName mName lName faculty) = object [
72+ "firstName" .= fName,
73+ "middleName" .= mName,
74+ "lastName" .= lName,
75+ "faculty" .= faculty
76+ ]
77+
78+instance FromJSON UserUpdate where
79+ parseJSON = withObject "user creation" $ \e ->
80+ UserUpdate <$> e .: "firstName" <*> e .: "middleName" <*> e .: "lastName" <*> e .: "faculty"
81+
denis/src/Server/API.hs+9−10
@@ -58,7 +58,7 @@ type API =
58 "users" :> ReqBody '[JSON] [UserId] :> Post '[JSON] [User Faculty] :<|>
58 "users" :> ReqBody '[JSON] [UserId] :> Post '[JSON] [User Faculty] :<|>
59 "users" :> "all" :> Post '[JSON] [User Faculty] :<|>
59 "users" :> "all" :> Post '[JSON] [User Faculty] :<|>
60 "users" :> "search" :> UserSearchDescription :> ReqBody '[JSON, PlainText] Text :> Post '[JSON] [User Faculty] :<|>
60 "users" :> "search" :> UserSearchDescription :> ReqBody '[JSON, PlainText] Text :> Post '[JSON] [User Faculty] :<|>
61− "users" :> "update" :> UpdateUserDescription :> ReqBody '[JSON] UserCreation :> PostNoContent '[JSON, PlainText] NoContent :<|>
61+ "users" :> "update" :> UpdateUserDescription :> ReqBody '[JSON] UserUpdate :> PostNoContent '[JSON, PlainText] NoContent :<|>
62 "posts" :> PostApi :<|>
62 "posts" :> PostApi :<|>
63 "channels" :> ChannelsApi :<|>
63 "channels" :> ChannelsApi :<|>
64 MessagesApi
64 MessagesApi
@@ -85,15 +85,14 @@ mkServerAPI l =
85 tagsServer :<|>
85 tagsServer :<|>
86 facultyServer
86 facultyServer
87
87
88−updateUserApi :: UserId -> UserCreation -> App NoContent
88+updateUserApi :: UserId -> UserUpdate -> App NoContent
89−updateUserApi uId UserCreation{..} = do
89+updateUserApi uId UserUpdate{..} = do
90− res <- runQerror $ updateUser User {
90+ res <- runQerror $ updateUser UserUpdateRow {
91− userId = uId,
91+ userUpdateRowId = uId,
92− firstName = userCreationFirstName,
92+ userUpdateRowFirstName = userUpdateFirstName,
93− middleName = userCreationMiddleName,
93+ userUpdateRowMiddleName = userUpdateMiddleName,
94− lastName = userCreationLastName,
94+ userUpdateRowLastName = userUpdateLastName,
95− userFaculty = userCreationUserFaculty,
95+ userUpdateRowUserFaculty = userUpdateUserFaculty
96− userEmail = userCreationUserEmail
97 }
96 }
98 if isJust res
97 if isJust res
99 then return NoContent
98 then return NoContent