Skip to content

mrigor87/PlaceForLunch

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notes

Users cannot change their roles through profile view because ProfileRestController works through UserTO, which is configured to prevent that. Admin controller, on the other hand, works with entities (User), so admins can change roles. Usernames cannot be changed through REST.

Example commands

Profile creating and editing

Get profile
$ curl -s -X GET --user estrella:estrellaPass http://placeforlunch.herokuapp.com/rest/v1/profile |json_pp
{
   "id" : 3,
   "name" : "Estrella Gosnell",
   "username" : "estrella"
}
Change password - too short
$ curl -s -X PUT -d '{"name": "Esfdsf", "username": "estrella", "password": "es"}' --user estrella:estrellaPass -H "Content-Type: application/json" placeforlunch.herokuapp.com/rest/v1/profile |json_pp
{
   "url" : "http://placeforlunch.herokuapp.com/rest/v1/profile",
   "cause" : "ValidationException",
   "details" : [
      "password must be between 5 and 64 characters"
   ]
}
Register new user
$ curl -sv -X POST -d '{"name": "John Smith", "username": "mrSmith", "password": "smithPass1"}' -H "Content-Type: application/json" placeforlunch.herokuapp.com/rest/v1/new-user |json_pp

link to profile is given in response header:

< Location: http://placeforlunch.herokuapp.com/rest/v1/profile

Profile data in body:

{
   "username" : "mrSmith",
   "name" : "John Smith"
}

user names are case-insensitive:

$ curl -s -X GET --user mrsmith:smithPass1 placeforlunch.herokuapp.com/rest/v1/profile |json_pp
{
   "username" : "mrSmith",
   "name" : "John Smith",
   "id" : 11
}

Delete profile:

$ curl -s -X DELETE --user mrSmith:smithPass1 placeforlunch.herokuapp.com/rest/v1/profile
Validation errors are shown as list
$ curl -s -X POST -d '{"name": "John Smith", "username": "mrSmith?@@", "password": "abc"}' -H "Content-Type: application/json" placeforlunch.herokuapp.com/rest/v1/new-user |json_pp
{
   "cause" : "ValidationException",
   "details" : [
      "username can have only letters, numbers and ._-",
      "password must be between 5 and 64 characters"
   ],
   "url" : "http://placeforlunch.herokuapp.com/rest/v1/new-user"
}

User administration

rest/v1/admin/users

Poll

rest/v1/poll/restaurants
rest/v1/poll/restaurants?showDishes=true
rest/v1/poll/restaurants/1/dishes

Voting

$ curl -s -X GET --user estrella:estrellaPass http://placeforlunch.herokuapp.com/rest/v1/profile/vote
curl -sv -X PUT --user estrella:estrellaPass -d '{"restaurantId": 1}' -H "Content-Type: application/json" http://placeforlunch.herokuapp.com/rest/v1/profile/vote |json_pp

Poll summary

$ curl -s -X GET --user estrella:estrellaPass http://placeforlunch.herokuapp.com/rest/v1/poll/vote-summary |json_pp
[
   {
      "votes" : 3,
      "id" : 1
   },
   {
      "votes" : 2,
      "id" : 2
   },
   {
      "votes" : 2,
      "id" : 4
   },
   {
      "votes" : 1,
      "id" : 3
   },
   {
      "votes" : 2
   }
]

About

Graduation task for topjava course

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Java 99.8%
  • Batchfile 0.2%