Home > Article > Backend Development > How to rewrite the multi-condition and multi-filter display result list?
This is a list of orders displayed in the background. The basic requirement is that you can search based on the user's relevant information in the search box, such as user_id
, registered email
, or you can search and display based on the order-related information in the search box. , such as order_id
, order_type
, order creat_time
range, etc.
1. In order to quickly launch the business in the early stage, everything was thrown into the controller. Most of them used if..else
for search display. When the demand continued to increase, for example, user_phone
was added and order_state
was added. When order status (closed, in progress), etc., you have to write if...else
, which causes the function
of controller
to continue to grow.
2. Different query groups have different query permissions. For example, super administrators can query all users, and sellers can only query their own buyers’ users, so user
is different again. So this code is constantly copied and pasted in different controller
.
Now I want to refactor, want to make this search function independent into trait
or make controller
depend on service
? I don’t know how to handle these search parameters, and if they are separated, do you have any relevant articles? , or books and examples that have optimized similar functions
~~ Thank you!
This is a list of orders displayed in the background. The basic requirement is that you can search based on the user's relevant information in the search box, such as user_id
, registered email
, or you can search and display based on the order-related information in the search box. , such as order_id
, order_type
, order creat_time
range, etc.
1. In order to quickly launch the business in the early stage, everything was thrown into the controller. Most of them used if..else
for search display. When the demand continued to increase, for example, user_phone
was added and order_state
was added. When order status (closed, in progress), etc., you have to write if...else
, which causes the function
of controller
to continue to grow.
2. Different query groups have different query permissions. For example, super administrators can query all users, and sellers can only query their own buyers’ users, so user
is different again. So this code is constantly copied and pasted in different controller
.
Now I want to refactor, want to make this search function independent into trait
or make controller
depend on service
? I don’t know how to handle these search parameters, and if they are separated, do you have any related articles? , or books and examples that have optimized similar functions
~~ Thank you!