tramway-api 1.6.3.1 → 1.7.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc3d2db65fc5b4b06905703a83e8652a7794f46cf2c28147cf0c39d95bb81f4f
4
- data.tar.gz: 84d4b9f3f77bd968d75d2a512679647352c687193d26a2b30d909b58643cc3fa
3
+ metadata.gz: 56da4809e88d47a601a85acdeed9104c1ec4114c33a1c6cbc2c3a86b41a49003
4
+ data.tar.gz: 5c68a2cb731c77780b7ccdf399b66b792dd11626447eb9b676311ac5a839d840
5
5
  SHA512:
6
- metadata.gz: ee82990f80e8692e5a1428ad0685ee0d17ff9ffa3acd5474716b3385fae07570be6d1d2a21fa3590b9351992eab8f318b3c0fa3359fc76fef0d1aef96ab58c92
7
- data.tar.gz: 1fbe1b706291a8cfb0a04ea9e7ebeec5376032f2970d345424d18263d467d5d7da070dbb3f056482dd712e451d489e63bb314ed58ee0f1603f794d5c2fb32208
6
+ metadata.gz: a7eb92d306828573f93795a3fbbebd5df72a5a63af74144d19aed2658d1245fad3d9579582d9611765884357dca7d8c3804509e2e836d10a30cf9dab3e5a4553
7
+ data.tar.gz: e23a71a3d8a71b9ef5159ac2361912a186a0f7b522b83a8ca0951a84240485f9a31213f73f82fe30d207b168ffaf22786bb7fd46e3baa173a8b707c1474af6bc
data/README.md CHANGED
@@ -70,12 +70,22 @@ Then generate User (you use another name, it's just an example) model
70
70
  rails g model user email:text password_digest:text username:text state:text uid:text
71
71
  ```
72
72
 
73
- Add generating uid by default
73
+ Enable extension in your database:
74
74
 
75
- *db/migrate/create_users_*.rb
75
+ *db/migrate/enable_extension.rb*
76
+ ```
77
+ def change
78
+ enable_extension 'uuid-ossp'
79
+ end
80
+ ```
81
+
82
+
83
+ Add generating uuid by default to every model, that is accessible by API
84
+
85
+ *db/migrate/add_uuid_to_some_model.rb*
76
86
 
77
87
  ```ruby
78
- t.uuid :uid, default: 'uuid_generate_v4()'
88
+ t.uuid :uuid, default: 'uuid_generate_v4()'
79
89
  ```
80
90
 
81
91
  *app/models/user.rb*
@@ -85,7 +95,7 @@ class User < Tramway::Core::ApplicationRecord
85
95
  has_secure_password
86
96
 
87
97
  def self.from_token_payload(payload)
88
- find_by uid: payload['sub']
98
+ find_by uuid: payload['sub']
89
99
  end
90
100
  end
91
101
  ```
@@ -227,7 +237,7 @@ RSpec.describe 'Post generate token', type: :feature do
227
237
  post '/api/v1/user_token', params: { auth: { login: user.email, password: '123456789' } }
228
238
 
229
239
  expect(json_response[:auth_token].present?).to be_truthy
230
- expect(json_response[:user]).to include_json({ email: user.email, uid: user.uid })
240
+ expect(json_response[:user]).to include_json({ email: user.email, uuid: user.uuid })
231
241
  end
232
242
 
233
243
  end
@@ -29,7 +29,7 @@ module Tramway
29
29
  if entity.respond_to? :to_token_payload
30
30
  ::Knock::AuthToken.new payload: entity.to_token_payload
31
31
  else
32
- ::Knock::AuthToken.new payload: { sub: entity.uid }
32
+ ::Knock::AuthToken.new payload: { sub: entity.uuid }
33
33
  end
34
34
  end
35
35
 
@@ -18,6 +18,7 @@ module Tramway::Api::V1
18
18
  def create
19
19
  record_form = form_class.new model_class.new
20
20
  if record_form.submit snake_case params[:data][:attributes]
21
+ record_form.model.reload
21
22
  render json: record_form.model,
22
23
  serializer: serializer_class,
23
24
  include: '*',
@@ -28,7 +29,7 @@ module Tramway::Api::V1
28
29
  end
29
30
 
30
31
  def update
31
- record_form = form_class.new model_class.active.find params[:id]
32
+ record_form = form_class.new model_class.active.find_by uuid: params[:id]
32
33
  if record_form.submit snake_case params[:data][:attributes]
33
34
  render json: record_form.model,
34
35
  serializer: serializer_class,
@@ -40,7 +41,7 @@ module Tramway::Api::V1
40
41
  end
41
42
 
42
43
  def show
43
- record = model_class.active.find params[:id]
44
+ record = model_class.active.find_by uuid: params[:id]
44
45
  render json: record,
45
46
  serializer: serializer_class,
46
47
  include: '*',
@@ -48,7 +49,7 @@ module Tramway::Api::V1
48
49
  end
49
50
 
50
51
  def destroy
51
- record = model_class.active.find params[:id]
52
+ record = model_class.active.find_by uuid: params[:id]
52
53
  record.remove
53
54
  render json: record,
54
55
  serializer: serializer_class,
@@ -8,8 +8,7 @@ class Tramway::Api::V1::UserTokensController < ::Tramway::Api::V1::ApplicationCo
8
8
  auth_token: token,
9
9
  user: {
10
10
  email: @entity.email,
11
- uid: @entity.uid,
12
- id: @entity.id
11
+ uuid: @entity.uuid
13
12
  }
14
13
  }, status: :created
15
14
  else
@@ -10,13 +10,12 @@ class Tramway::Api::V1::UsersController < ::Tramway::Api::V1::ApplicationControl
10
10
  user_form = sign_up_form_class_name(user_based_model).new user_based_model.new
11
11
  # Implement JSON API spec here
12
12
  if user_form.submit snake_case params[:data][:attributes]
13
- token = ::Knock::AuthToken.new(payload: { sub: user_form.model.uid }).token
13
+ token = ::Knock::AuthToken.new(payload: { sub: user_form.model.uuid }).token
14
14
  # FIXME: refactor this bullshit
15
15
  serialized_user = OpenStruct.new(
16
16
  user_form.model.attributes.merge(
17
17
  authentication_token: token,
18
- uid: user_form.model.uid,
19
- id: user_form.model.id
18
+ uuid: user_form.model.uuid
20
19
  )
21
20
  )
22
21
  render json: serialized_user, status: :created
@@ -3,6 +3,12 @@
3
3
  class Tramway::Api::V1::ApplicationSerializer < ActiveModel::Serializer
4
4
  include ::Tramway::Core::Concerns::AttributesDecoratorHelper
5
5
 
6
+ attribute :id
7
+
8
+ def id
9
+ object.uuid
10
+ end
11
+
6
12
  def created_at
7
13
  object.created_at.iso8601
8
14
  end
@@ -18,12 +18,14 @@ module Tramway
18
18
  end
19
19
 
20
20
  def user_based_models
21
+ @@auth_config ||= []
21
22
  @@auth_config.map do |conf|
22
23
  conf[:user_model]
23
24
  end
24
25
  end
25
26
 
26
27
  def auth_attributes
28
+ @@auth_config ||= []
27
29
  @@auth_config.reduce({}) do |hash, conf|
28
30
  hash.merge! conf[:user_model] => conf[:auth_attributes]
29
31
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Api
5
- VERSION = '1.6.3.1'
5
+ VERSION = '1.7.0.4'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.3.1
4
+ version: 1.7.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-17 00:00:00.000000000 Z
11
+ date: 2020-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_model_serializers