rest_rails 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e44dc67a7765b180d91f76fb2c06adce63351171b59f5e9e9d9fff357a3ea8ce
4
- data.tar.gz: cd7e5c02ad8e51b67cdf62a710ba7cc61c3f2c0d8e4d39f0a73932efe9d124fd
3
+ metadata.gz: df308706605d4fb456f3e21fa2d7ad69862cebf8c20eb53f3cf51900f688cc31
4
+ data.tar.gz: 73402c490bfe2043d04fc45db6d92815a08cea1fa73f5599a56b75147cb47e86
5
5
  SHA512:
6
- metadata.gz: 23b0e8395ce42d7046cdf727331e394a4025f64db4ad2471f8aa405f74fb136ff2bb89f6a55735f049ff50e375a0f4c5a1fbcf8f8a83020b084f62b066de900e
7
- data.tar.gz: db74177843f17a46787af716af6cfc5514ed743b1020fa6fafe2c58adbff6f82d957595b0c1fc85c22ca5662dfe56c12d194b266de0d004def625aa1812b9d1e
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 | GET | `/api/v1/articles/:id` | update an article
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 | GET | `/api/v1/comments/:id` | update an comment
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
- @objects = @model.all.in_groups_of(100) if p_hash.blank?
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
- if params[:page].blank? || (params[:page].to_i < 1)
17
- if @objects.empty?
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
@@ -1,3 +1,3 @@
1
1
  module RestRails
2
- VERSION = '1.0.5'
2
+ VERSION = '1.1.0'
3
3
  end
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.5
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: 2019-12-29 00:00:00.000000000 Z
11
+ date: 2020-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails