Added Agent Sales Seeder + Fix Sold Appliance page#568
Conversation
dmohns
left a comment
There was a problem hiding this comment.
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
processSaleFromFactorywe 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
processSaleFromFactoryandprocessSaleIfIsNotCreatedByFactorywhich 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
Requestcontext. 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
AgentSoldApplianceObserverin 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 |
dmohns
left a comment
There was a problem hiding this comment.
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_appliancetable. 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. |
|
Added sample endpoint (app) usage as bruno collections. |
4d4ce85 to
9276a4a
Compare
dmohns
left a comment
There was a problem hiding this comment.
Looks good 👍 Two more small comments
a167e28 to
12e1b49
Compare
12e1b49 to
aad302c
Compare
dmohns
left a comment
There was a problem hiding this comment.
Really good work 🤩 Thanks for the patience!

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.