Skip to content
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

Add Support for Creating Contacts with Optional Company Information #61

Merged
merged 7 commits into from
Dec 19, 2024

Conversation

CCirbo
Copy link
Collaborator

@CCirbo CCirbo commented Dec 19, 2024

Type of Change

  • feature ⛲
  • testing 🧪

Description

• Refactored ContactSerializer to include company information if a contact is created with a company.
• Added tests for the ContactController to validate logic for handling nested contact routes and companies.
• Implemented a create action for the nested contacts route.

Motivation and Context

These changes allow a contact to be created with a company.name/company_id or without a company, ensuring flexibility and maintaining a consistent user experience. The additional tests ensure 100% code coverage in SimpleCov for the Contact Controller's new logic.
closes #60
closes #3

Related Tickets

• Refactoring of the ContactsController has been moved to ticket #58.

Added Test?

  • Yes 🫡
    Request/Controller Specs?
  • No 🙅
  • All previous tests still pass 🥳

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Copy link
Collaborator

@Sgalvin36 Sgalvin36 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes made to the controllers looks great. I appreciate the checks for companies to make those connections while the contact is being made.
I asked for some more information to be provided in the README, I don't see anything in the code specifically that needs to be addressed before approval.


Authorization: Bearer Token - put in token for user

raw json body with all fields:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps adding some clarification on which of the fields are absolutely required. I saw in the tests you were using a minimal params when creating. So while it is very helpful to have the full JSON as an example, having some information on which fields will trigger the 404 error if not included can clear that up. For example, first and last name are required while email is an optional field.

Copy link
Collaborator

@reneemes reneemes Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing this out. Due to how the DB is currently set up only the first name, last name, and company ID id needed, depending on which URL being used. The Read Me currently states that unique first and last names are required, but does not specify that the new route needs a company ID. I can update that to make it more apparent.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Read Me has been updated.

render json: { company: CompanySerializer.new(company), contacts: ContactSerializer.new(contacts) }
def create
authorize Contact
if params[:company_id]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the company controller, this could potentially be refactored into the model. While not necessary for this specific PR, something to make note of, especially if there is any more logic added to the action at a later time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, definitely. There is a ticket up for that, #58 in backlog.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ope! I'm sorry I forgot that you mentioned that in the stand up.

Copy link
Collaborator

@jimmacur jimmacur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things are looking very good here. Ready to merge!

config/routes.rb Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you let me know why we need a contacts :create under both contacts and /companies/contacts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question! In Create a Contact, we need that companies/create to create a contact with a company. If we create a contact without a company, then it goes to the contacts/create route. It was the last piece needed for that page.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extremely thorough testing!

Copy link
Collaborator

@Sgalvin36 Sgalvin36 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding the clarification in the README

@Sgalvin36 Sgalvin36 merged commit 229f453 into main Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BE Fix Contact Serializer and Nested contact route for create action See all contacts FE
4 participants