-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Agent Sales Seeder + Fix Sold Appliance page #568
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @beesaferoot
Thanks for the PR. I was not expecting this topic to be so big 🙈
There is a couple of things that I don't like
- In the newly created
processSaleFromFactory
we are essentially "seeding" some data with things like'tenure' => rand(6, 24),
. I know it's minor, but still. I'd love to have all seeding code in seeders. - There is a lot of redundancy between
processSaleFromFactory
andprocessSaleIfIsNotCreatedByFactory
which will lead to hard-to-maintain code.
Both of the above aren't really flaws of your solution. But I think there is a bigger underlying problem in the code base here:
The AgentSoldApplianceObserver
seems to heavily rely on request()->input()
. This feels wrong on so many levels.
- Currently the Observer implements a lot of business logic like creating model objects from requests and setting relation ships between them. By understanding is that Observer should react to CRUD operations rather than performing them.
- Observer cannot be used outside of
Request
context. This is exactly the problem you are facing, which leads to a lot of code duplication.
What do you think about the following suggestion:
- Let's merge your changes the way they are, so we can benefit from the additional Seeding data generation.
- Let's create a follow-up ticket to refactor
AgentSoldApplianceObserver
in a way that it doesn't require `request()->input().
Number 2. will be quite big, as it will require shuffling a lot of code around from the Observer into corresponding Services and Controllers. But I think it would be a valuable addition and improvement to the code base.
WDYT?
PS: @alaincodes24 I would also like to hear your opinion here |
Thanks for the review @dmohns, I agree it does need some refactoring and cleanup. Although one of the reasons I opted to use an entirely different function for seeding purposes was because it wasn't clear why the |
@dmohns I agree that the observer shouldn't be tied to |
@alaincodes24 Do you mind clarifying a bit more on this? Perhaps you can point to an example where the seed code is used outside a seeder. I think I now understand what you are referring to. The problem is that to refactor this I need to refactor the Observer method |
e4e315b
to
6ea5040
Compare
Updated, kindly review @dmohns @alaincodes24 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Two follow up questions:
- When as we are changing the
request()->input()
logic I would want to be able to test that AgentSoldAppliance API endpoints still work as expected. Could you add an example HTTP collection with some dummy data, so we can test before and after the change? - I'm a bit confused as to why we need to add columns to
agent_sold_appliance
table. Where is this data stored right now?
I will be including a collection for this endpoint as noted. For 2) so from my investigation, fields like I considered two approaches: After discusing a bit with Alain about a more idiomatic approach, I decided 1.) works well and is more laravel like. |
…and update agent seeder for test email
Added sample endpoint (app) usage as bruno collections. |
Brief summary of the change made
These changes allows us to generate data from agent to customer relationships, by which we can then query upon these interactions.
The PR also includes minor big fixes on the UI related to appliance page.
Are there any other side effects of this change that we should be aware of?
Describe how you tested your changes?
Pull Request checklist
Please confirm you have completed any of the necessary steps below.