rest_rails 1.0.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/app/controllers/rest_rails/data_controller.rb +6 -17
- data/lib/rest_rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df308706605d4fb456f3e21fa2d7ad69862cebf8c20eb53f3cf51900f688cc31
|
4
|
+
data.tar.gz: 73402c490bfe2043d04fc45db6d92815a08cea1fa73f5599a56b75147cb47e86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 749c06bab1acf04d5ddbb21da58320e96d53e2696bda5052c1d18156c35a20e1d23dd8f78bdd9bdc5d498c6f4cd239609d94e3bfa02a509d6827588dc11202e7
|
7
|
+
data.tar.gz: b7360138c4fb918bb45a93645e04b8b6629705d9a7fad92ae20ec4ce8a4fe2c60e9fd9d7a7879ea79c9628a0777fa8f07d9b47ea1177e3de8bf1a6b640b8e2b6
|
data/README.md
CHANGED
@@ -52,7 +52,7 @@ REST action | method | route | notes
|
|
52
52
|
index | GET | `/api/v1/articles` | index paginated by 100
|
53
53
|
show | GET | `/api/v1/articles/:id` | show for one article
|
54
54
|
create | POST | `/api/v1/articles` | create new article
|
55
|
-
update |
|
55
|
+
update | PATCH | `/api/v1/articles/:id` | update an article
|
56
56
|
destroy | DELETE | `/api/v1/articles/:id` | destroy an article
|
57
57
|
fetch_column | GET | `/api/v1/articles/:id/title` | fetch title of article
|
58
58
|
fetch_column | GET | `/api/v1/articles/:id/description` | fetch description of article
|
@@ -70,7 +70,7 @@ REST action | method | route | notes
|
|
70
70
|
index | GET | `/api/v1/comments` | index paginated by 100
|
71
71
|
show | GET | `/api/v1/comments/:id` | show for one comment
|
72
72
|
create | POST | `/api/v1/comments` | create new comment
|
73
|
-
update |
|
73
|
+
update | PATCH | `/api/v1/comments/:id` | update an comment
|
74
74
|
destroy | DELETE | `/api/v1/comments/:id` | destroy an comment
|
75
75
|
fetch_column | GET | `/api/v1/comments/:id/article_id` | fetch article_id of comment
|
76
76
|
fetch_column | GET | `/api/v1/comments/:id/content` | fetch content of comment
|
@@ -9,25 +9,14 @@ module RestRails
|
|
9
9
|
|
10
10
|
def index
|
11
11
|
p_hash = index_params.to_h
|
12
|
+
ppage = (params[:per_page] || 100).to_i
|
13
|
+
page = (params[:page] || 1).to_i
|
14
|
+
off = (page-1) * ppage
|
12
15
|
|
13
|
-
|
14
|
-
@objects = @model.where(p_hash).in_groups_of(100) if p_hash.present?
|
16
|
+
base_query = p_hash.blank? ? @model.all : @model.where(p_hash)
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
@objects = []
|
19
|
-
else
|
20
|
-
@objects = @objects[0].reject{|x|x.nil?}.map{|x| standardize_json(x) }
|
21
|
-
end
|
22
|
-
else
|
23
|
-
i = params[:page].to_i - 1
|
24
|
-
objs = @objects[i]
|
25
|
-
if objs.nil?
|
26
|
-
@objects = []
|
27
|
-
else
|
28
|
-
@objects = objs.reject{|x|x.nil?}.map{|x| standardize_json(x) }
|
29
|
-
end
|
30
|
-
end
|
18
|
+
@objects = base_query.order(:id).limit(ppage).offset(off)
|
19
|
+
@objects.map!{|x| standardize_json(x) }
|
31
20
|
|
32
21
|
render json: {code: 200, objects: @objects, count: @objects.count, total: @model.count}
|
33
22
|
end
|
data/lib/rest_rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergio Rivas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|