I'm currently building a consent management system consisting of 3 layers:
- Handlers/Controllers (Rest)
- Services (Logic)
- Repositories (Microsoft SQL)
This is the scenario:
I'm fetching the identifier (Id) from a model inside of the database. But before that, I have to check if a boolean of another model is set to true or false. I had a discussion with one of our engineers on how to implement his, and furthermore who is responsible for the checking: Business logic or repository layer by SQL queries.
Solution 1: Fetch the whole model/instance from the repository layer by two parameters and then explicitly check the state of the boolean. (true/false) Using the following query:
SELECT * FROM [ApplicationUserMapping] WHERE Uuid = @Uuid AND ApplicationUuid=@ApplicationUuid;
Code inside the business logic:
if !applicationUserMapping.HasConsent {
// User is NOT allowed to proceed -> Error messaging -> Logging -> etc.
}
// User is allowed to proceed -> Continue code block
Solution 2: Or write and execute a query that checks if the state of the boolean. (true/false) The repository is now responsible for checking the state. And return the values depending on the outcome of the query.
SELECT * FROM [ApplicationUserMapping] WHERE Uuid = @Uuid AND ApplicationUuid=@ApplicationUuid AND HasConsent = 1;
Solution 3: If you understand my scenario and have a better solution please provide it.