~sirn/fanboi2

ref: a68873a108d20a6a49a1b6caf374bfb2cf6a94fe fanboi2/fanboi2/services/__init__.py -rw-r--r-- 9.2 KiB
a68873a1Kridsada Thanabulpong Coding style cleanups and setup pre-commit hooks (#42) 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
from ..interfaces import (
    IBoardCreateService,
    IBoardQueryService,
    IBoardUpdateService,
    IFilterService,
    IIdentityService,
    IPageCreateService,
    IPageDeleteService,
    IPageQueryService,
    IPageUpdateService,
    IPostCreateService,
    IPostDeleteService,
    IPostQueryService,
    IRateLimiterService,
    IRuleBanCreateService,
    IRuleBanQueryService,
    IRuleBanUpdateService,
    ISettingQueryService,
    ISettingUpdateService,
    ITaskQueryService,
    ITopicCreateService,
    ITopicDeleteService,
    ITopicQueryService,
    ITopicUpdateService,
    IUserCreateService,
    IUserLoginService,
    IUserQueryService,
    IUserSessionQueryService,
)

from .board import BoardCreateService, BoardQueryService, BoardUpdateService
from .filter_ import FilterService
from .identity import IdentityService
from .page import (
    PageCreateService,
    PageDeleteService,
    PageQueryService,
    PageUpdateService,
)
from .post import PostCreateService, PostDeleteService, PostQueryService
from .rate_limiter import RateLimiterService
from .rule import RuleBanCreateService, RuleBanQueryService, RuleBanUpdateService
from .setting import SettingQueryService, SettingUpdateService
from .task import TaskQueryService
from .topic import (
    TopicCreateService,
    TopicDeleteService,
    TopicQueryService,
    TopicUpdateService,
)
from .user import (
    UserCreateService,
    UserLoginService,
    UserQueryService,
    UserSessionQueryService,
)


def includeme(config):  # pragma: no cover  # noqa: C901

    # Board Create

    def board_create_factory(context, request):
        dbsession = request.find_service(name="db")
        return BoardCreateService(dbsession)

    config.register_service_factory(board_create_factory, IBoardCreateService)

    # Board Query

    def board_query_factory(context, request):
        dbsession = request.find_service(name="db")
        return BoardQueryService(dbsession)

    config.register_service_factory(board_query_factory, IBoardQueryService)

    # Board Update

    def board_update_factory(context, request):
        dbsession = request.find_service(name="db")
        return BoardUpdateService(dbsession)

    config.register_service_factory(board_update_factory, IBoardUpdateService)

    # Filter

    def filter_factory(context, request):
        filters = request.registry["filters"]

        def service_query_fn(*a, **k):
            return request.find_service(*a, **k)

        return FilterService(filters, service_query_fn)

    config.register_service_factory(filter_factory, IFilterService)

    # Identity

    def identity_factory(context, request):
        redis_conn = request.find_service(name="redis")
        setting_query_svc = request.find_service(ISettingQueryService)
        ident_size = setting_query_svc.value_from_key("app.ident_size")
        return IdentityService(redis_conn, ident_size)

    config.register_service_factory(identity_factory, IIdentityService)

    # Page Create

    def page_create_factory(context, request):
        dbsession = request.find_service(name="db")
        cache_region = request.find_service(name="cache")
        return PageCreateService(dbsession, cache_region)

    config.register_service_factory(page_create_factory, IPageCreateService)

    # Page Delete

    def page_delete_factory(context, request):
        dbsession = request.find_service(name="db")
        cache_region = request.find_service(name="cache")
        return PageDeleteService(dbsession, cache_region)

    config.register_service_factory(page_delete_factory, IPageDeleteService)

    # Page Query

    def page_query_factory(context, request):
        dbsession = request.find_service(name="db")
        cache_region = request.find_service(name="cache")
        return PageQueryService(dbsession, cache_region)

    config.register_service_factory(page_query_factory, IPageQueryService)

    # Page Update

    def page_update_factory(context, request):
        dbsession = request.find_service(name="db")
        cache_region = request.find_service(name="cache")
        return PageUpdateService(dbsession, cache_region)

    config.register_service_factory(page_update_factory, IPageUpdateService)

    # Post Create

    def post_create_factory(context, request):
        dbsession = request.find_service(name="db")
        identity_svc = request.find_service(IIdentityService)
        setting_query_svc = request.find_service(ISettingQueryService)
        user_query_svc = request.find_service(IUserQueryService)
        return PostCreateService(
            dbsession, identity_svc, setting_query_svc, user_query_svc
        )

    config.register_service_factory(post_create_factory, IPostCreateService)

    # Post Delete

    def post_delete_factory(context, request):
        dbsession = request.find_service(name="db")
        return PostDeleteService(dbsession)

    config.register_service_factory(post_delete_factory, IPostDeleteService)

    # Post Query

    def post_query_factory(context, request):
        dbsession = request.find_service(name="db")
        return PostQueryService(dbsession)

    config.register_service_factory(post_query_factory, IPostQueryService)

    # Rate Limiter

    def rate_limiter_factory(context, request):
        redis_conn = request.find_service(name="redis")
        return RateLimiterService(redis_conn)

    config.register_service_factory(rate_limiter_factory, IRateLimiterService)

    # RuleBan create

    def rule_ban_create_factory(context, request):
        dbsession = request.find_service(name="db")
        return RuleBanCreateService(dbsession)

    config.register_service_factory(rule_ban_create_factory, IRuleBanCreateService)

    # RuleBan query

    def rule_ban_query_factory(context, request):
        dbsession = request.find_service(name="db")
        return RuleBanQueryService(dbsession)

    config.register_service_factory(rule_ban_query_factory, IRuleBanQueryService)

    # RuleBan update

    def rule_ban_update_factory(context, request):
        dbsession = request.find_service(name="db")
        return RuleBanUpdateService(dbsession)

    config.register_service_factory(rule_ban_update_factory, IRuleBanUpdateService)

    # Setting Query

    def setting_query_factory(context, request):
        dbsession = request.find_service(name="db")
        cache_region = request.find_service(name="cache")
        return SettingQueryService(dbsession, cache_region)

    config.register_service_factory(setting_query_factory, ISettingQueryService)

    # Setting Update

    def setting_update_factory(context, request):
        dbsession = request.find_service(name="db")
        cache_region = request.find_service(name="cache")
        return SettingUpdateService(dbsession, cache_region)

    config.register_service_factory(setting_update_factory, ISettingUpdateService)

    # Task Query

    def task_query_factory(context, request):
        return TaskQueryService()

    config.register_service_factory(task_query_factory, ITaskQueryService)

    # Topic Create

    def topic_create_factory(context, request):
        dbsession = request.find_service(name="db")
        identity_svc = request.find_service(IIdentityService)
        setting_query_svc = request.find_service(ISettingQueryService)
        user_query_svc = request.find_service(IUserQueryService)
        return TopicCreateService(
            dbsession, identity_svc, setting_query_svc, user_query_svc
        )

    config.register_service_factory(topic_create_factory, ITopicCreateService)

    # Topic Delete

    def topic_delete_factory(context, request):
        dbsession = request.find_service(name="db")
        return TopicDeleteService(dbsession)

    config.register_service_factory(topic_delete_factory, ITopicDeleteService)

    # Topic Query

    def topic_query_factory(context, request):
        dbsession = request.find_service(name="db")
        return TopicQueryService(dbsession)

    config.register_service_factory(topic_query_factory, ITopicQueryService)

    # Topic Update

    def topic_update_factory(context, request):
        dbsession = request.find_service(name="db")
        return TopicUpdateService(dbsession)

    config.register_service_factory(topic_update_factory, ITopicUpdateService)

    # User create

    def user_create_factory(context, request):
        dbsession = request.find_service(name="db")
        identity_svc = request.find_service(IIdentityService)
        return UserCreateService(dbsession, identity_svc)

    config.register_service_factory(user_create_factory, IUserCreateService)

    # User Login

    def user_login_factory(context, request):
        dbsession = request.find_service(name="db")
        return UserLoginService(dbsession)

    config.register_service_factory(user_login_factory, IUserLoginService)

    # User Query

    def user_query_factory(context, request):
        dbsession = request.find_service(name="db")
        return UserQueryService(dbsession)

    config.register_service_factory(user_query_factory, IUserQueryService)

    # User Query

    def user_session_query_factory(context, request):
        dbsession = request.find_service(name="db")
        return UserSessionQueryService(dbsession)

    config.register_service_factory(
        user_session_query_factory, IUserSessionQueryService
    )