site_blog 0.10.0 → 0.11.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: cab7ac4ecc8185d4c4767188b5ea55b94a80670e2e8b3b7a82eede29cf7e35c0
4
- data.tar.gz: 6978b193b7ec06015ce25b6eb1e830004bf5cc8afba4b3c89e4095e2f6d366c1
3
+ metadata.gz: 17887d197e4f068342e6b4b5488168131bf0322a10bd3ed5599db3c4133677e6
4
+ data.tar.gz: 6919603b9225bcdf09606af5faad5749f6864e83ce9996986e2cebd6b883ddf5
5
5
  SHA512:
6
- metadata.gz: a3aa2e2048e05a1ec032d540931686a824a971274c42353be6c2eaf67bc3bbae7394c069bcc3ae8b508d1031c1ea8c1fccf2c6c55694dfcbb0d5a460da7bddde
7
- data.tar.gz: 545a4d6b16c671674e1c8b4a808a4434f52fe10a84f325629b1294babb2a53cb5337c63fed6415dba94857056d03b664c5edb42d802c114e133a7750c6756934
6
+ metadata.gz: 6de7294cc0bc47e8d0b846abf65909a2d5d91f7f48c501d86ba9a691774e3370cbd2255b4538298dc2f5c57820dd738e795bfd437c8ee844943f2d05fc472ff1
7
+ data.tar.gz: 4ec3a1ef2ad9c2d8c5e951982e791eacd32580c5c27e3af300ad2abbdeb33f9ce6559019c8438712c19999d1cb9b09fe06ad8c9240fac53fa5f16919af88ded1
@@ -1,58 +1,31 @@
1
1
  module SiteBlog
2
2
  class ArticlesController < ApplicationController
3
- before_action :set_article, only: %i[ show update destroy ]
3
+ before_action :set_host, only: %i[ index show main ]
4
4
 
5
5
  # GET /articles
6
6
  def index
7
- render json: Article.filters(params)
7
+ @data = Article.filters(params)
8
+ render formats: :json
8
9
  end
9
10
 
11
+ # GET /articles/main
10
12
  def main
11
- render json: Article.main
13
+ @article = Article.main
14
+ render formats: :json
12
15
  end
13
16
 
14
- # GET /articles/1
17
+ # GET /articles/:slug
15
18
  def show
19
+ @article = Article.find_by(slug: params[:id])
16
20
  @article.increment!(:view_count)
17
- render json: @article
18
- end
19
-
20
- # POST /articles
21
- def create
22
- article = Article.new(article_params)
23
-
24
- if article.save
25
- render json: article, status: :created
26
- else
27
- render json: article.errors, status: :unprocessable_entity
28
- end
29
- end
30
-
31
- # PATCH/PUT /articles/1
32
- def update
33
- if @article.update(article_params)
34
- render json: @article
35
- else
36
- render json: @article.errors, status: :unprocessable_entity
37
- end
38
- end
39
-
40
- # DELETE /articles/1
41
- def destroy
42
- @article.destroy
43
- render json: { success: true }
21
+ render formats: :json
44
22
  end
45
23
 
46
24
  private
47
25
 
48
- # Use callbacks to share common setup or constraints between actions.
49
- def set_article
50
- @article = Article.find_by(params[:slug])
51
- end
26
+ def set_host
27
+ @host = !Rails.env.production? ? request.host : ''
28
+ end
52
29
 
53
- # Only allow a list of trusted parameters through.
54
- def article_params
55
- params.require(:article).permit(:title, :description, :image, :tag_id, :archived, :active)
56
- end
57
30
  end
58
31
  end
@@ -1,53 +1,16 @@
1
1
  module SiteBlog
2
2
  class TagsController < ApplicationController
3
- before_action :set_tag, only: %i[ show update destroy ]
4
3
 
5
4
  # GET /tags
6
5
  def index
7
- render json: Tag.archived(false)
6
+ render json: Tag.archived(false).as_json(except: [:archived])
8
7
  end
9
8
 
10
9
  # GET /tags/1
11
10
  def show
12
- render json: @tag
11
+ @tag = Tag.find(params[:id])
12
+ render json: @tag.as_json(except: [:archived])
13
13
  end
14
14
 
15
- # POST /tags
16
- def create
17
- @tag = Tag.new(tag_params)
18
-
19
- if @tag.save
20
- render json: @tag, status: :created
21
- else
22
- render json: @tag.errors, status: :unprocessable_entity
23
- end
24
- end
25
-
26
- # PATCH/PUT /tags/1
27
- def update
28
- if @tag.update(tag_params)
29
- render json: @tag
30
- else
31
- render json: @tag.errors, status: :unprocessable_entity
32
- end
33
- end
34
-
35
- # DELETE /tags/1
36
- def destroy
37
- @tag.destroy
38
- render json: { success: true }
39
- end
40
-
41
- private
42
-
43
- # Use callbacks to share common setup or constraints between actions.
44
- def set_tag
45
- @tag = Tag.find(params[:id])
46
- end
47
-
48
- # Only allow a list of trusted parameters through.
49
- def tag_params
50
- params.require(:tag).permit(:slug, :archived)
51
- end
52
15
  end
53
16
  end
@@ -33,14 +33,14 @@ module SiteBlog
33
33
  data = archived(false)
34
34
  data = data.joins(:tags).where(tags: { id: params[:tag_id] }) if params[:tag_id].present?
35
35
  data = data.search(params[:query]) if params[:query].present?
36
- count = data.length
36
+ count = data.count
37
37
  data = data.order('created_at DESC')
38
- data = data.limit(params[:limit]) if params[:limit]
39
38
  data = data.page(params[:page]).per(20)
39
+ data = data.limit(params[:limit]) if params[:limit]
40
40
 
41
41
  {
42
42
  total_count: count,
43
- data: data
43
+ articles: data
44
44
  }
45
45
  }
46
46
 
@@ -0,0 +1,15 @@
1
+ json.total_count @data[:total_count]
2
+ json.data do
3
+ json.array! @data[:articles] do |article|
4
+ json.id article.id
5
+ json.title article.title
6
+ json.slug article.slug
7
+ json.html_description article.html_description
8
+ json.view_count article.view_count
9
+ json.main article.main
10
+ json.orig_image_url @host + article.image.url
11
+ json.thumb_image_url @host + article.image.thumb.url
12
+ json.(article, :created_at, :updated_at)
13
+ end
14
+ end
15
+
@@ -0,0 +1,16 @@
1
+ json.id @article.id
2
+ json.title @article.title
3
+ json.slug @article.slug
4
+ json.html_description @article.html_description
5
+ json.view_count @article.view_count
6
+ json.main @article.main
7
+ json.orig_image_url @host + @article.image.url
8
+ json.thumb_image_url @host + @article.image.thumb.url
9
+ json.tags do
10
+ json.array! @article.tags do |tag|
11
+ json.id tag.id
12
+ json.slug tag.slug
13
+ end
14
+ end
15
+ json.(@article, :created_at, :updated_at)
16
+
@@ -0,0 +1,16 @@
1
+ json.id @article.id
2
+ json.title @article.title
3
+ json.slug @article.slug
4
+ json.html_description @article.html_description
5
+ json.view_count @article.view_count
6
+ json.main @article.main
7
+ json.orig_image_url @host + @article.image.url
8
+ json.thumb_image_url @host + @article.image.thumb.url
9
+ json.tags do
10
+ json.array! @article.tags do |tag|
11
+ json.id tag.id
12
+ json.slug tag.slug
13
+ end
14
+ end
15
+ json.(@article, :created_at, :updated_at)
16
+
@@ -1,3 +1,3 @@
1
1
  module SiteBlog
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: site_blog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eldar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-28 00:00:00.000000000 Z
11
+ date: 2023-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: jbuilder
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Description of AppComponent
98
112
  email:
99
113
  - eldarweb@mail.ru
@@ -118,6 +132,9 @@ files:
118
132
  - app/models/site_blog/tagging.rb
119
133
  - app/uploaders/site_blog/image_uploader.rb
120
134
  - app/views/layouts/blog/application.html.erb
135
+ - app/views/site_blog/articles/index.json.jbuilder
136
+ - app/views/site_blog/articles/main.json.jbuilder
137
+ - app/views/site_blog/articles/show.json.jbuilder
121
138
  - config/routes.rb
122
139
  - db/migrate/20230201140930_add_article_and_tag.rb
123
140
  - lib/site_blog.rb