Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

http: add endpoint to fetch a detailed list of customer and account info #211

Closed
wants to merge 0 commits into from
Closed

http: add endpoint to fetch a detailed list of customer and account info #211

wants to merge 0 commits into from

Conversation

vxio
Copy link
Member

@vxio vxio commented Oct 1, 2020

Adds the endpoint /reports/accounts?accountIDs={...} that returns a list of objects that include customer and account information.

Fixes #196

@codecov-commenter
Copy link

codecov-commenter commented Oct 1, 2020

Codecov Report

Merging #211 into master will increase coverage by 0.40%.
The diff coverage is 71.42%.

@@            Coverage Diff             @@
##           master     #211      +/-   ##
==========================================
+ Coverage   58.72%   59.13%   +0.40%     
==========================================
  Files          49       51       +2     
  Lines        2629     2692      +63     
==========================================
+ Hits         1544     1592      +48     
- Misses        786      796      +10     
- Partials      299      304       +5     

Copy link

@jmbrown412 jmbrown412 left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -96,6 +97,7 @@ func main() {
disclaimerRepo := documents.NewDisclaimerRepo(logger, db)
documentRepo := documents.NewDocumentRepo(logger, db)
validationsRepo := validator.NewRepo(db)
aggregateRepo := reports.NewRepository(logger, db)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this make more sense as reportsRepo := ...?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah, aggregate was something I used before refactoring, thanks for the catch.

@@ -0,0 +1,80 @@
package reports
Copy link
Member

Choose a reason for hiding this comment

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

Nit: let's call it repository.go


func (r *sqlRepository) FindByAccountIDs(accountIDs []string) ([]*CustomerAccount, error) {
query := fmt.Sprintf(
`select
Copy link
Member

Choose a reason for hiding this comment

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

Why would we duplicate the logic for reading a Customer? That's pretty involved logic to duplicate.

Copy link
Member

Choose a reason for hiding this comment

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

We aren't reading out address, phone or metadata either.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, I was debating on whether to implement this. Based on the issue description, it seemed like we wanted to minimize the # of db queries we were making for fetching n # of customers/accounts. So it wasn't too much code to duplicate.

I could rip it out and call getCustomer * n. I also looked into using searchCustomers but underneath it still calls getCustomer n times.

And I assumed address, phone or metadata of the customer wasn't relevant to this endpoint.

Copy link
Member

Choose a reason for hiding this comment

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

I would always default to assuming we need to return the entire model. Otherwise the UI and folks could get confused.

It sounds like we need to reinvent the repository method for getting multiple customers then? I don't like this hack when we could have one method used in GET /customers/.... routes and this reporting endpoint.

Copy link
Member Author

@vxio vxio Oct 2, 2020

Choose a reason for hiding this comment

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

Good point.

I'll rework this, I'll use searchCustomers for now but will make sure to optimize it in another PR.

Related issue: #216

@@ -0,0 +1,49 @@
package reports
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Let's call this router.go.

Copy link
Member

@adamdecaf adamdecaf left a comment

Choose a reason for hiding this comment

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

This still looks like a WIP, right?


allCustomers := make(map[string]*client.Customer)
for _, acc := range allAccounts {
cust, err := customerRepo.GetCustomer(acc.CustomerID)
Copy link
Member Author

@vxio vxio Oct 5, 2020

Choose a reason for hiding this comment

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

In the future, need to update searchCustomers to accept a list of customerIDs to filter for.

New related issue: #220

@vxio vxio requested a review from adamdecaf October 5, 2020 19:07
api/admin.yaml Outdated
@@ -82,7 +82,7 @@ paths:
content:
application/json:
schema:
$ref: 'https://raw.githubusercontent.com/moov-io/api/master/openapi-common.yaml#/components/schemas/Error'
$ref: 'https://raw.githubusercontent.com/moov-io/base/master/api/common.yaml#/components/schemas/Error'
Copy link
Member

Choose a reason for hiding this comment

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

This should be fixed so we can remove this change.

#218

Copy link
Member Author

Choose a reason for hiding this comment

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

Sweet, will rebase and update.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New endpoint for batch searching for customers and accounts.
5 participants