@@ -8,15 +8,35 @@ class BooksController < ApplicationController
88
99 before_action :set_book , only : %i[ show update destroy ]
1010
11+ def_param_group :book do
12+ param :id , :number , desc : 'Id of book' , required : true
13+ param 'book[title]' , String , desc : 'Title of book' , required : true , only_in : :request
14+ param 'book[description]' , String , desc : 'Description of book' , only_in : :request
15+ property :title , String , desc : 'Title of book'
16+ property :descriprion , String , desc : 'Description of book'
17+ property :created_at , String , desc : 'Date of book creation'
18+ property :updated_at , String , desc : 'Date of book update'
19+ end
20+
21+ api :GET , '/books/' , 'Shows all books'
22+ returns array_of : :book , code : 200 , desc : 'All books'
1123 def index
1224 books = Book . all
1325 render json : books
1426 end
1527
28+ api :GET , '/books/:id' , 'Shows the requested book'
29+ param :id , :number , desc : 'Id of the book' , required : true
30+ returns :book , code : 200 , desc : 'Requested book'
31+ error code : 404 , desc : 'Not Found'
1632 def show
1733 render json : @book
1834 end
1935
36+ api :POST , '/books/' , 'Create a new book'
37+ returns :book , code : 200 , desc : 'Created book'
38+ param_group :book
39+
2040 def create
2141 book = Book . new ( book_params )
2242 if book . save
@@ -26,6 +46,10 @@ def create
2646 end
2747 end
2848
49+ api :PUT , '/books/:id' , 'Updates the requested book'
50+ param_group :book
51+ returns :book , code : 200 , desc : 'Updated book'
52+ error code : 404 , desc : 'Not Found'
2953 def update
3054 if @book . update ( book_params )
3155 render json : @book , status : :ok
@@ -34,6 +58,9 @@ def update
3458 end
3559 end
3660
61+ api :DELETE , '/books/:id' , 'Deletes the requested book'
62+ returns code : 200
63+ param :id , :number , desc : 'Id of the book' , required : true
3764 def destroy
3865 @book . destroy
3966 end
0 commit comments