33
33
module Lesli
34
34
module ResponderInterface
35
35
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
-
48
36
# 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
52
39
end
53
40
54
41
# Usage example
@@ -57,39 +44,38 @@ def respond_with_successful(payload = nil)
57
44
# .page(query[:pagination][:page])
58
45
# .per(query[:pagination][:perPage])
59
46
#
60
- # respond_with_successful_pagination (tasks)
47
+ # respond_with_pagination (tasks)
61
48
#
62
49
# IMPORTANT: It is strictly necessary to use the pagination methods
63
50
# 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
+ {
66
53
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
71
58
} ,
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 ) )
74
72
end
75
73
76
74
# JSON not found response
77
75
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
-
90
76
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
+ } )
93
79
end
94
80
95
81
# JSON not found response
0 commit comments