Skip to content

Commit fc6416b

Browse files
committed
feat: reorganize interfaces & services
1 parent 66d2ca3 commit fc6416b

File tree

6 files changed

+52
-284
lines changed

6 files changed

+52
-284
lines changed

app/controllers/lesli/application_lesli_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@
3333
module Lesli
3434
class ApplicationLesliController < ApplicationController
3535

36-
include Lesli::LoggerInterface
3736
include Lesli::ResponderInterface
3837
include Lesli::RequesterInterface
3938
include Lesli::CustomizationInterface
39+
include LesliAudit::LoggerInterface if defined?(LesliAudit)
4040
include LesliShield::AuthenticationInterface if defined?(LesliShield)
4141

4242
protect_from_forgery with: :exception
4343

4444
before_action :set_path
4545
before_action :set_locale
4646
before_action :authenticate_request if defined?(LesliShield)
47-
before_action :authorize_privilege if defined?(LesliSecurity)
47+
before_action :authorize_request if defined?(LesliSecurity)
4848
before_action :set_customizer
4949
before_action :set_requester
5050
after_action :log_requests if defined?(LesliAudit)

app/interfaces/lesli/authorization_interface.rb

-103
This file was deleted.

app/interfaces/lesli/logger_interface.rb

-132
This file was deleted.

app/interfaces/lesli/requester_interface.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ def set_locale
6565
# Set default query params for:
6666
def set_requester
6767
@query = {
68-
search: params[:search] || nil,
69-
pagination: {
70-
perPage: (params[:perPage] ? params[:perPage].to_i : 12),
71-
page: (params[:page] ? params[:page].to_i : 1)
68+
:search => params[:search] || nil,
69+
:pagination => {
70+
:perPage => (params[:perPage] ? params[:perPage].to_i : 12),
71+
:page => (params[:page] ? params[:page].to_i : 1)
7272
},
73-
order: {
74-
by: (params[:orderBy] || "id"),
75-
dir: (params[:order] || "desc")
73+
:order => {
74+
:by => (params[:orderBy] || "id"),
75+
:dir => (params[:order] || "desc")
7676
}
7777
}
7878
end

app/interfaces/lesli/responder_interface.rb

+24-38
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,9 @@
3333
module Lesli
3434
module ResponderInterface
3535

36-
def respond_with_pagination2(records, payload = nil)
37-
{
38-
pagination: {
39-
page: records.current_page,
40-
pages: records.total_pages,
41-
total: records.total_count,
42-
results: records.length
43-
},
44-
records: payload || records
45-
}
46-
end
47-
4836
# Return an standard http 200 respond
49-
def respond_with_successful(payload = nil)
50-
# Response for modern Lesli 3 apps
51-
respond_with_http(200, payload)
37+
def respond_as_successful(payload = nil)
38+
payload
5239
end
5340

5441
# Usage example
@@ -57,39 +44,38 @@ def respond_with_successful(payload = nil)
5744
# .page(query[:pagination][:page])
5845
# .per(query[:pagination][:perPage])
5946
#
60-
# respond_with_successful_pagination(tasks)
47+
# respond_with_pagination(tasks)
6148
#
6249
# IMPORTANT: It is strictly necessary to use the pagination methods
6350
# to make this work properly
64-
def respond_with_pagination(records, payload = nil)
65-
respond_with_http(200, {
51+
def respond_as_pagination(payload)
52+
{
6653
pagination: {
67-
page: records.current_page,
68-
pages: records.total_pages,
69-
total: records.total_count,
70-
results: records.length
54+
page: payload.current_page,
55+
pages: payload.total_pages,
56+
total: payload.total_count,
57+
results: payload.length
7158
},
72-
records: payload || records
73-
})
59+
records: payload
60+
}
61+
end
62+
63+
64+
65+
66+
def respond_with_successful(payload = nil)
67+
respond_with_http(200, respond_as_successful(payload))
68+
end
69+
70+
def respond_with_pagination(payload)
71+
respond_with_http(200, respond_as_pagination(payload))
7472
end
7573

7674
# JSON not found response
7775
def respond_with_not_found
78-
# Keep compatibility with Deutsche Leibrenten
79-
if defined? DeutscheLeibrenten
80-
response_body = {
81-
successful: false,
82-
error: {
83-
message: I18n.t("core.shared.messages_danger_not_found"),
84-
details: []
85-
}
86-
}
87-
return render(status: 404, json: response_body.to_json)
88-
end
89-
9076
respond_with_http(404, {
91-
message: I18n.t("core.shared.messages_danger_not_found")
92-
})
77+
message: I18n.t("core.shared.messages_danger_not_found")
78+
})
9379
end
9480

9581
# JSON not found response

0 commit comments

Comments
 (0)