Created
July 26, 2013 12:23
-
-
Save wertlex/6088471 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pathPrefix("v1" / "users") { | |
path("") { | |
post { | |
entity(as[CreateUserRequest]) { createUserRequest => | |
log.info("Creating user for " + createUserRequest) | |
complete { | |
val res = userDao createUser createUserRequest | |
MailNotifier(res) | |
res | |
} | |
} | |
} ~ | |
get{ | |
parameters( | |
'text.as[String], | |
'offset.as[Int], | |
'limit.as[Int], | |
'creatdAtInterval.as[DateTimeInterval] ?, | |
'modifiedAtInterval.as[DateTimeInterval] ? | |
).as(UserSearchRequest) { userSearchRequest => | |
log.info("Search users by " + userSearchRequest) | |
complete { | |
userDao findUser userSearchRequest | |
} | |
} | |
} ~ | |
put { | |
entity(as[LoginRequest]) { loginRequest => | |
complete { | |
userDao getUser(loginRequest.login, loginRequest.password) match { | |
case Some(user) => user | |
case None => EmptyEntity | |
} | |
} | |
} | |
} | |
} ~ | |
path(Segment) { id => | |
val userId = UserId(id) | |
get { | |
complete { | |
log.info("Getting user " + userId) | |
userDao getUser userId match { | |
case Some(user) => user | |
case None => EmptyEntity | |
} | |
} | |
} ~ | |
put{ | |
entity(as[UpdateUserRequest]) { updateUserRequest => | |
complete { | |
log.info("Updating user " + userId + " with " + updateUserRequest) | |
var avatar: Option[Avatar] = None | |
if (!updateUserRequest.avatar.isEmpty) | |
avatar = Option(Avatar(updateUserRequest.avatar get,updateUserRequest.avatar get, updateUserRequest.avatar get, updateUserRequest.avatar get)) | |
log.info(avatar.toString) | |
userDao updateUser(userId, updateUserRequest, avatar) match { | |
case Some(user) => user | |
case None => EmptyEntity | |
} | |
} | |
} | |
} ~ | |
delete { | |
complete { | |
log.info("Deleting user " + userId) | |
userDao deleteUser userId | |
EmptyEntity | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment