Skip to content

Implement GET /opportunities (first draft)#49

Closed
bickelj wants to merge 1 commit into
mainfrom
31-get-opportunities
Closed

Implement GET /opportunities (first draft)#49
bickelj wants to merge 1 commit into
mainfrom
31-get-opportunities

Conversation

@bickelj

@bickelj bickelj commented Jul 18, 2022

Copy link
Copy Markdown
Contributor

A first draft of an implementation of HTTP GET on /opportunities. It
includes SQL for the schema, removal of cruft, SQL for the query, types,
and the boilerplate/glue code needed to wire it to the express server.
What it still lacks is tests, passing lint, and probably node-ish-ness.

Issue #31 Implement GET /opportunities endpoint

A first draft of an implementation of HTTP GET on /opportunities. It
includes SQL for the schema, removal of cruft, SQL for the query, types,
and the boilerplate/glue code needed to wire it to the express server.
What it still lacks is tests, passing lint, and probably node-ish-ness.

Issue #31 Implement GET /opportunities endpoint
@bickelj bickelj requested a review from slifty July 18, 2022 22:13
@bickelj

bickelj commented Jul 18, 2022

Copy link
Copy Markdown
Contributor Author

I know linting fails, but something in here is probably a simple misunderstanding due to my node/typescript noobness. Regardless, is this close to the shape of what you would expect for an implementation of this subset of the API?

@bickelj

bickelj commented Jul 18, 2022

Copy link
Copy Markdown
Contributor Author

I see the integration tests taking more than two minutes to run as well, canceling those.

@slifty slifty left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ALL RIGHT! Sorry it took so long to get you any feedback, I had a WIP branch that contains some of the patterns I wanted to propose which I wanted to get out there to be able to point to!

Some things I think are worth doing as part of our endpoint implementation are:

  1. fixture-based tests
  2. type checking of the database response (and 500 erroring with a useful error message if the type check fails)
  3. Defining defaults and type guards along side types (and trusting that we can use utility types to define subsets of interfaces where needed, rather than defining a bunch of versions of the same type)

I think we probably want to avoid bigints for the reasons you recognized in another thread; it'd be one thing if it was free but I think the added complexity isn't worth it for the moment.

title: string;
}

export interface Opportunity extends OpportunityMinimal {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In TypeScript the way to signal this is to define Opportunity and specify optional fields where appropriate using ?.

e.g.

export interface Opportunity {
  id?: number;
  title: string;
  createdAt?: Date;
}

For situations where we only need a smaller piece of an opportunity there are a series of utility types that let us specify a contextual modifications of a given interface.

For instance if we had an API endpoint that ONLY needed a smaller subset of Opportunity fields we could use Pick<Opportunity, 'title' | 'id'> and that would require both title and id for that particular parameter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the explanation here and in #55 (comment). It looks like I clicked the link you gave here but did not actually go through it and understand it until your other comment. I see the approach and it makes sense!

@bickelj bickelj changed the title Implement GET /opportunities Implement GET /opportunities (first draft) Aug 2, 2022
@bickelj

bickelj commented Aug 2, 2022

Copy link
Copy Markdown
Contributor Author

Closing without merge because this was before a good pattern (and the dependent endpoint implementation) was established by @slifty in #55. Second draft was in #63 which bit off too much and assumed too much.

@bickelj bickelj closed this Aug 2, 2022
@bickelj bickelj deleted the 31-get-opportunities branch August 2, 2022 17:39
@slifty slifty restored the 31-get-opportunities branch August 30, 2022 14:51
@slifty slifty deleted the 31-get-opportunities branch August 30, 2022 14:59
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.

2 participants