Front end repository: https://github.com/natdjerf/js-cheese
All actions are implemented by the user. In order to add a cheese to a board, a POST request is made to the cheese addition table with the associated board and selected cheese id parameters.
Models:
class User < ActiveRecord::Base
include Authentication
has_many :boards
end
Boards table -required parameter: name
class Board < ActiveRecord::Base
belongs_to :user, inverse_of: :boards
has_many :cheese_additions
has_many :cheeses, through: :cheese_additions
end
Cheese table -loaded via csv
class Cheese < ActiveRecord::Base
has_many :cheese_additions
has_many :boards, through: :cheese_additions
end
Cheese Addition table -required parameters: board_id, cheese_id -join table of cheese and board
class CheeseAddition < ActiveRecord::Base
belongs_to :board, inverse_of: :cheese_additions
belongs_to :cheese, inverse_of: :cheese_additions
end
Verb | URI Pattern | Controller#Action |
---|---|---|
POST | /sign-up |
users#signup |
POST | /sign-in |
users#signin |
PATCH | /change-password/:id |
users#changepw |
DELETE | /sign-out/:id |
users#signout |
GET | /cheese_additions |
cheese_additions#index |
POST | /cheese_additions |
cheese_additions#create |
GET | /cheese_additions/:id |
cheese_additions#show |
PATCH | /cheese_additions/:id |
cheese_additions#update |
PUT | /cheese_additions/:id |
cheese_additions#update |
DELETE | /cheese_additions/:id |
cheese_additions#destroy |
GET | /cheeses |
cheeses#index |
POST | /cheeses |
cheeses#create |
GET | /cheeses/:id |
cheeses#show |
GET | /boards |
boards#index |
POST | /boards |
boards#create |
GET | /boards/:id |
boards#show |
PATCH | /boards/:id |
boards#update |
PUT | /boards/:id |
boards#update |
DELETE | /boards/:id |
boards#destroy |
Request:
curl --include --request POST http://localhost:3000/sign-up \
--header "Content-Type: application/json" \
--data '{
"credentials": {
"email": "an@example.email",
"password": "an example password",
"password_confirmation": "an example password"
}
}'
scripts/sign-up.sh
Response:
HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
{
"user": {
"id": 1,
"email": "an@example.email"
}
}
Request:
curl --include --request POST http://localhost:3000/sign-in \
--header "Content-Type: application/json" \
--data '{
"credentials": {
"email": "an@example.email",
"password": "an example password"
}
}'
scripts/sign-in.sh
Response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"user": {
"id": 1,
"email": "an@example.email",
"token": "33ad6372f795694b333ec5f329ebeaaa"
}
}
Request:
curl --include --request PATCH http://localhost:3000/change-password/$ID \
--header "Authorization: Token token=$TOKEN" \
--header "Content-Type: application/json" \
--data '{
"passwords": {
"old": "an example password",
"new": "super sekrit"
}
}'
ID=1 TOKEN=33ad6372f795694b333ec5f329ebeaaa scripts/change-password.sh
Response:
HTTP/1.1 204 No Content
Request:
curl --include --request DELETE http://localhost:3000/sign-out/$ID \
--header "Authorization: Token token=$TOKEN"
ID=1 TOKEN=33ad6372f795694b333ec5f329ebeaaa scripts/sign-out.sh
Response:
HTTP/1.1 204 No Content
Verb | URI Pattern | Controller#Action |
---|---|---|
GET | /users |
users#index |
GET | /users/1 |
users#show |
Request:
curl --include --request GET http://localhost:3000/users \
--header "Authorization: Token token=$TOKEN"
TOKEN=33ad6372f795694b333ec5f329ebeaaa scripts/users.sh
Response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"users": [
{
"id": 2,
"email": "another@example.email"
},
{
"id": 1,
"email": "an@example.email"
}
]
}
Request:
curl --include --request GET http://localhost:3000/users/$ID \
--header "Authorization: Token token=$TOKEN"
ID=2 TOKEN=33ad6372f795694b333ec5f329ebeaaa scripts/user.sh
Response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"user": {
"id": 2,
"email": "another@example.email"
}
}
Request:
curl "http://localhost:3000/boards/$ID" \
--include \
--request POST \
--header "Authorization: Token token=$TOKEN" \
--header "Content-Type: application/json" \
--data "{
\"board\" : {
\"name\" : \"$NAME\",
\"user_id\" : \"$USER_ID\"
}
}"
scripts/boards-create.sh
Request:
curl "http://localhost:3000/boards/$ID" \
--include \
--request PATCH \
--header "Authorization: Token token=$TOKEN" \
--data "{
\"board\" : {
\"name\" : \"$NAME\"
}
}"
scripts/board-update.sh
Request:
curl --include --request GET http://localhost:3000/boards/ \
--header "Authorization: Token token=$TOKEN"
scripts/boards-get.sh
Request:
curl --include --request GET http://localhost:3000/boards/$ID \
--header "Authorization: Token token=$TOKEN"
scripts/board-get.sh
curl --include --request DELETE http://localhost:3000/boards/$ID \
--header "Authorization: Token token=$TOKEN"
scripts/board-delete.sh
Request:
curl --include --request POST http://localhost:3000/cheese_additions \
--header "Authorization: Token token=$TOKEN" \
--header "Content-Type: application/json" \
--data '{
"cheese_addition": {
"board_id": "0",
"cheese_id": "0"
}
}'
scripts/cheese_additions-create.sh
Response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Request:
curl --include --request DELETE http://localhost:3000/cheese_additions/$ID \
--header "Authorization: Token token=$TOKEN"
Source code distributed under the MIT license. Text and other assets copyright General Assembly, Inc., all rights reserved.