drogonframework / drogonframework/drogon
Allow for creating composite filters
- Dominant language
- C++
- Stars
- 14.3k
- Forks
- 1.4k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 15
Description
**Is your feature request related to a problem? Please describe.**
Currently we can define singular filters and add them one by one to controllers, however, this gets frustrating when we have dozens of API endpoints that have a set of 3 or 4 filters repeated in each one. For example:
```c++
PATH_ADD(
"/api/something",
"LoggedIn",
"Verified",
"NotSuspicious",
HttpMethod::Post
)
```
Having these 3 filters repeated in multiple endpoints is error-prone in the case something is to be changed, for example we may want to add another filter on top of the 3 that does some other checks on the session, now we must go through each file and add that filter for all of them, and we may forget to add it for one of the API endpoints.
**Describe the solution you'd like**
Add Composite Filters, they are filters that have names just like normal filters, and they have a list of strings that contain the names of individual filters.
These composite filters can be added onto controllers like normal filters, and the composite filter will add its children into the controller automatically.
**Describe alternatives you've considered**
Macros, and they are quite ugly:
```c++
// A header file
#define API_LOGGED_IN_FILTERS \
"LoggedIn", \
"Verified", \
"NotSuspicious"
```
```c++
// API endpoint file
PATH_ADD(
"/api/something",
API_LOGGED_IN_FILTERS,
HttpMethod::Post
)
```
Contributor guide
Assessment
This issue has not been assessed yet.