dscf-credit 0.1.9 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a206be7d1f68e8a83476b508b3238c990eb67226243a5f242d3149828454891
4
- data.tar.gz: 2fb1cc62bf33eaf81c4dd52e8413ab9bb2bfa186287b4714b603cb95360fe522
3
+ metadata.gz: ab8778ae93f1e301f3f98e4715c341f177f6e12e47ab00a042355c098bdb4945
4
+ data.tar.gz: cfa7f52505d8cfae80563bb1d2790346dd9f115af2db68b5339b3a65af33e709
5
5
  SHA512:
6
- metadata.gz: cc931ad8d941a12b6d4680a761ea5210982ed5714e54bd2aec47a74444fea96e92a526250301d4391194da9bf389e92c4253818e6540fafdbf2d9d3d7728b0d7
7
- data.tar.gz: c24155a0a4ef04ebfa0366d523feeba334842be98dcff13708447af5b286a81b0a5118786f785748b0f65c1e76c263b98b6e44196cc55e2501381eceadaf2bf4
6
+ metadata.gz: a5385b0be9ebdce8e6e763a14f40476f707c2860d2fdb83d2134b5cfd944967a6eda0e590ada5fdabff8d931ef79dbc6d1544078641e5dc31d2ea588af4c2192
7
+ data.tar.gz: 6b4dcca19fd39513f9048c1e699be0838246e284c5a4e881cf6345e8127688fe305e74a58d042ddcf37ceb3623300f72c5718a1aa7a82e852183fbd3056b3b25
@@ -1,5 +1,5 @@
1
1
  module Dscf
2
2
  module Credit
3
- VERSION = "0.1.9"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dscf-credit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adoniyas
@@ -313,14 +313,6 @@ files:
313
313
  - MIT-LICENSE
314
314
  - README.md
315
315
  - Rakefile
316
- - app/controllers/concerns/dscf/core/authenticatable.rb
317
- - app/controllers/concerns/dscf/core/common.rb
318
- - app/controllers/concerns/dscf/core/copilot-instructions.md
319
- - app/controllers/concerns/dscf/core/filterable.rb
320
- - app/controllers/concerns/dscf/core/json_response.rb
321
- - app/controllers/concerns/dscf/core/pagination.rb
322
- - app/controllers/concerns/dscf/core/reviewable_controller.rb
323
- - app/controllers/concerns/dscf/core/token_authenticatable.rb
324
316
  - app/controllers/dscf/credit/application_controller.rb
325
317
  - app/controllers/dscf/credit/bank_branches_controller.rb
326
318
  - app/controllers/dscf/credit/bank_staffs_controller.rb
@@ -345,11 +337,9 @@ files:
345
337
  - app/controllers/dscf/credit/system_configs_controller.rb
346
338
  - app/controllers/dscf/credit/users_controller.rb
347
339
  - app/jobs/dscf/credit/application_job.rb
348
- - app/jobs/dscf/credit/generate_daily_accruals_job.rb
349
340
  - app/mailers/dscf/credit/application_mailer.rb
350
341
  - app/mailers/dscf/credit/bank_staff_welcome_mailer.rb
351
342
  - app/mailers/dscf/credit/facilitator_mailer.rb
352
- - app/models/concerns/core/reviewable_model.rb
353
343
  - app/models/dscf/credit/accounting_audit_request.rb
354
344
  - app/models/dscf/credit/accounting_entry.rb
355
345
  - app/models/dscf/credit/application_record.rb
@@ -1,81 +0,0 @@
1
- module Dscf
2
- module Core
3
- module Authenticatable
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- before_action :authenticate_user, if: :authentication_required?
8
- rescue_from AuthenticationError, with: :handle_authentication_error
9
- end
10
-
11
- def current_user
12
- @current_user ||= authenticate_from_token
13
- end
14
-
15
- def authenticate_user!
16
- raise AuthenticationError, "Authentication required" unless current_user
17
- end
18
-
19
- def authenticate_user
20
- authenticate_user! if authentication_required?
21
- end
22
-
23
- def sign_in(user, request)
24
- tokens = user.generate_auth_tokens(request)
25
- @current_user = user
26
- tokens
27
- end
28
-
29
- def sign_out
30
- # Revoke the current refresh token if available
31
- refresh_token_value = extract_refresh_token_from_params
32
- AuthService.revoke_refresh_token(refresh_token_value) if refresh_token_value
33
- @current_user = nil
34
- end
35
-
36
- def refresh_token
37
- refresh_token_value = extract_refresh_token_from_params
38
- return nil unless refresh_token_value
39
-
40
- begin
41
- AuthService.refresh_access_token(refresh_token_value, request)
42
- rescue AuthenticationError
43
- nil
44
- end
45
- end
46
-
47
- private
48
-
49
- def authenticate_from_token
50
- access_token = extract_access_token_from_header
51
- return nil unless access_token
52
-
53
- payload = TokenService.decode(access_token)
54
- return nil unless payload && payload["type"] == "access"
55
-
56
- User.find_by(id: payload["user_id"])
57
- rescue AuthenticationError
58
- nil
59
- end
60
-
61
- def extract_access_token_from_header
62
- auth_header = request.headers["Authorization"]
63
- return nil unless auth_header&.start_with?("Bearer ")
64
-
65
- auth_header.split(" ").last
66
- end
67
-
68
- def extract_refresh_token_from_params
69
- params[:refresh_token]
70
- end
71
-
72
- def authentication_required?
73
- true # Override in specific controllers if needed
74
- end
75
-
76
- def handle_authentication_error(error)
77
- render json: error.to_hash, status: error.status_code
78
- end
79
- end
80
- end
81
- end
@@ -1,200 +0,0 @@
1
- module Dscf
2
- module Core
3
- module Common
4
- extend ActiveSupport::Concern
5
- include Dscf::Core::Pagination
6
- include Dscf::Core::JsonResponse
7
- include Dscf::Core::Filterable
8
-
9
- included do
10
- before_action :set_clazz
11
- before_action :set_object, only: %i[show update]
12
- end
13
-
14
- def index
15
- data = nil
16
- options = {}
17
- if block_given?
18
- incoming = yield
19
- if incoming.instance_of?(Array)
20
- data, options = incoming
21
- elsif incoming.instance_of?(Hash)
22
- options = incoming
23
- else
24
- data = incoming
25
- end
26
- else
27
- data = @clazz.all
28
- end
29
-
30
- # Apply eager loading if defined
31
- data = data.includes(eager_loaded_associations) if eager_loaded_associations.present?
32
-
33
- # Apply Ransack filtering
34
- data = filter_records(data)
35
-
36
- # Get total count before pagination
37
- total_count = data.count if params[:page]
38
-
39
- data = data.then(&paginate) if params[:page]
40
-
41
- # Add action specific serializer includes
42
- includes = serializer_includes_for_action(:index)
43
- options[:include] = includes if includes.present?
44
-
45
- # Add pagination metadata if paginated
46
- if params[:page]
47
- total_pages = (total_count.to_f / per_page).ceil
48
- count = data.is_a?(Array) ? data.length : data.count
49
-
50
- options[:pagination] = {
51
- current_page: page_no,
52
- per_page: per_page,
53
- count: count,
54
- total_count: total_count,
55
- total_pages: total_pages,
56
- links: pagination_links(total_pages)
57
- }
58
- end
59
-
60
- render_success(data: data, serializer_options: options)
61
- end
62
-
63
- def show
64
- data = nil
65
- options = {}
66
- if block_given?
67
- incoming = yield
68
- if incoming.instance_of?(Array)
69
- data, options = incoming
70
- elsif incoming.instance_of?(Hash)
71
- data = @obj
72
- options = incoming
73
- else
74
- data = incoming
75
- end
76
- else
77
- data = @obj
78
- end
79
-
80
- data = @clazz.includes(eager_loaded_associations).find(params[:id]) if data.is_a?(@clazz) && eager_loaded_associations.present?
81
-
82
- includes = serializer_includes_for_action(:show)
83
- options[:include] = includes if includes.present?
84
-
85
- render_success(data: data, serializer_options: options)
86
- end
87
-
88
- def create
89
- obj = nil
90
- options = {}
91
- if block_given?
92
- incoming = yield
93
- if incoming.instance_of?(Array)
94
- obj, options = incoming
95
- elsif incoming.instance_of?(Hash)
96
- obj = @clazz.new(model_params)
97
- options = incoming
98
- else
99
- obj = incoming
100
- end
101
- else
102
- obj = @clazz.new(model_params)
103
- end
104
-
105
- if obj.save
106
- obj = @clazz.includes(eager_loaded_associations).find(obj.id) if eager_loaded_associations.present?
107
-
108
- includes = serializer_includes_for_action(:create)
109
- options[:include] = includes if includes.present?
110
-
111
- render_success(data: obj, serializer_options: options, status: :created)
112
- else
113
- render_error(errors: obj.errors.full_messages[0], status: :unprocessable_entity)
114
- end
115
- rescue StandardError => e
116
- render_error(error: e.message)
117
- end
118
-
119
- def update
120
- obj = nil
121
- options = {}
122
- if block_given?
123
- incoming = yield
124
- if incoming.instance_of?(Array)
125
- obj, options = incoming
126
- elsif incoming.instance_of?(Hash)
127
- obj = set_object
128
- options = incoming
129
- else
130
- obj = incoming
131
- end
132
- else
133
- obj = set_object
134
- end
135
-
136
- if obj.update(model_params)
137
- obj = @clazz.includes(eager_loaded_associations).find(obj.id) if eager_loaded_associations.present?
138
-
139
- includes = serializer_includes_for_action(:update)
140
- options[:include] = includes if includes.present?
141
-
142
- render_success(data: obj, serializer_options: options)
143
- else
144
- render_error(errors: obj.errors.full_messages[0], status: :unprocessable_entity)
145
- end
146
- rescue StandardError => e
147
- render_error(error: e.message)
148
- end
149
-
150
- private
151
-
152
- def set_clazz
153
- model_name = controller_name.classify
154
-
155
- controller_namespace = self.class.name.deconstantize
156
- engine_namespace = controller_namespace.split("::")[0..1].join("::")
157
-
158
- @clazz = "#{engine_namespace}::#{model_name}".constantize
159
- rescue NameError
160
- @clazz = "Dscf::Core::#{model_name}".constantize
161
- end
162
-
163
- def set_object
164
- @obj = if eager_loaded_associations.present?
165
- @clazz.includes(eager_loaded_associations).find(params[:id])
166
- else
167
- @clazz.find(params[:id])
168
- end
169
- end
170
-
171
- # Override in controllers to define what to eager load
172
- def eager_loaded_associations
173
- []
174
- end
175
-
176
- # Override in controllers to define allowed order columns for pagination
177
- def allowed_order_columns
178
- %w[id created_at updated_at]
179
- end
180
-
181
- # Override in controllers to define serializer includes
182
- def default_serializer_includes
183
- {}
184
- end
185
-
186
- def serializer_includes_for_action(action)
187
- includes = default_serializer_includes
188
-
189
- if includes.is_a?(Hash)
190
- includes[action] || includes[:default] || []
191
- else
192
- includes.present? ? includes : []
193
- end
194
- end
195
-
196
- # This method should be overridden by respective child controllers
197
- def model_params; end
198
- end
199
- end
200
- end