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

External API GET threads and topics #9102

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open

Conversation

kurtisassad
Copy link
Contributor

@kurtisassad kurtisassad commented Sep 3, 2024

Link to Issue

Closes: #9015
Closes: #9103

Description of Changes

  • Adds GetThreads and GetTopics endpoints

Test Plan

  • Navigate to http://localhost:8080/api/v1/docs/ and test the corresponding API endpoints
  • Create a thread on dydx, ensure the topic dropdown works correctly (You can see multiple topics, and you can choose one).

@kurtisassad kurtisassad changed the title External API GET threads and toppics External API GET threads and topics Sep 3, 2024
# Conflicts:
#	packages/commonwealth/server/api/external-router.ts
}),
};

export const DEPRECATED_GetThreads = z.object({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These schemas conflict with our naming convention but are used for the old API. I have prefixed them with DEPRECATED for now since I am unsure how to handle it.

@kurtisassad kurtisassad marked this pull request as ready for review September 4, 2024 13:54
Copy link
Collaborator

@timolegros timolegros left a comment

Choose a reason for hiding this comment

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

Generally looks good.

I tested setting all include options to false and it still returned the Address and User.

Are these routes new external routes duplicates of existing legacy routes used on the client? If so we should quickly follow-up with transitioning the legacy route usage to the new routes to avoid having to maintain both routes.

include: includeArray,
...formatSequelizePagination(payload),
paranoid: false,
} as unknown as FindAndCountOptions<ThreadAttributes>);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can remove this type coercion from all future usage of formatSequelizePagination if we add a generic to the function which takes the attributes of the model and coerces order_by to one of the attributes instead of string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So it looks like the order_by is just typed as Order in sequelize, it does not depend on the key of the model. So I removed this as unknown typing, but just replaced it with the Order type without any generics

libs/model/src/topic/GetTopics.query.ts Outdated Show resolved Hide resolved
# Conflicts:
#	libs/model/src/thread/index.ts
#	packages/commonwealth/server/api/external-router.ts
#	packages/commonwealth/server/api/thread.ts
@kurtisassad
Copy link
Contributor Author

I tested setting all include options to false and it still returned the Address and User.

Fixed

@kurtisassad
Copy link
Contributor Author

If so we should quickly follow-up with transitioning the legacy route usage to the new routes to avoid having to maintain both routes.

Yes they are new routes with our consistent parameter convention. We discussed this during platform chat a while back, and the conclusion was, we will expect frontend to implement them when they have time :)

Then we will remove the old routes.

@timolegros
Copy link
Collaborator

If so we should quickly follow-up with transitioning the legacy route usage to the new routes to avoid having to maintain both routes.

Yes they are new routes with our consistent parameter convention. We discussed this during platform chat a while back, and the conclusion was, we will expect frontend to implement them when they have time :)

Then we will remove the old routes.

Do we have a ticket for using the new routes introduced here on the front-end? Having 2 routes that do the same thing is super risky - can easily make a change on one side without realizing there is another route that needs the same change so this shouldn't be something that Peng just eventually gets to 3 months down the line.

# Conflicts:
#	packages/commonwealth/server/api/internal-router.ts
# Conflicts:
#	libs/model/src/thread/index.ts
#	packages/commonwealth/server/api/external-router.ts
#	packages/commonwealth/server/routes/feed.ts
# Conflicts:
#	packages/commonwealth/client/scripts/models/Topic.ts
#	packages/commonwealth/client/scripts/views/pages/discussions/HeaderWithFilters/HeaderWithFilters.tsx
#	packages/commonwealth/server/api/external-router.ts
#	packages/commonwealth/server/api/thread.ts
# Conflicts:
#	packages/commonwealth/client/scripts/views/components/NewThreadForm/NewThreadForm.tsx
#	packages/commonwealth/server/api/external-router.ts
Copy link
Collaborator

@timolegros timolegros left a comment

Choose a reason for hiding this comment

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

Maybe fine for this PR but I would like a follow-up ticket for removing all the as unknown as Topic references on the client. From what I can see these are used because of the date <> string type mismatch issue.

We previously agreed that future instances of such errors would be resolved by stopping Sequelize from parsing ISO strings from the DB into JS date objects (make Sequelize leave them as strings). You can see examples of this in libs/model/src/models/community_alerts.ts.

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.

Add GetTopics to external API Add GetThreads to the external API
4 participants