You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a route that essentially returns a single level BOM for a part. I want to validate that the user requesting the data has access to the top level part and that requires me to call a service function. Originally, I had the two service calls in the router function to validate that the user can see the part, then get the BOM data. I wanted to abstract it out so I can use the same logic on other parts. My first thought was to use a decorator:
This will throw an error if the user cannot see the part, and will not execute the function.
In my controller, the function its being used in looks like this:
My concern with this approach is that it might be an anti-pattern in the litestar framework. I have been trying to look at other approaches like a guard or the before request, but my understanding, which may be wrong, is the dependency resolution occurs after the guard and before requested are executed. Since the Service is resolved via the dependency injector, I have to execute the check after that occurs. Does anyone have any ideas on if there are other ways to achieve this? Is this the best approach? The only other way that I can think of is by using the dependencies and have it look like this:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a route that essentially returns a single level BOM for a part. I want to validate that the user requesting the data has access to the top level part and that requires me to call a service function. Originally, I had the two service calls in the router function to validate that the user can see the part, then get the BOM data. I wanted to abstract it out so I can use the same logic on other parts. My first thought was to use a decorator:
This will throw an error if the user cannot see the part, and will not execute the function.
In my controller, the function its being used in looks like this:
My concern with this approach is that it might be an anti-pattern in the litestar framework. I have been trying to look at other approaches like a guard or the before request, but my understanding, which may be wrong, is the dependency resolution occurs after the guard and before requested are executed. Since the Service is resolved via the dependency injector, I have to execute the check after that occurs. Does anyone have any ideas on if there are other ways to achieve this? Is this the best approach? The only other way that I can think of is by using the dependencies and have it look like this:
Any insights or thoughts on this would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions