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 contexts api #500

Closed
wants to merge 3 commits into from
Closed

Conversation

tomcorey26
Copy link

@tomcorey26 tomcorey26 commented Oct 17, 2020

Question Answer
Bug fix
New feature
Breaking change
Deprecations
Documentation
Tests added

Closes #497

Copy link
Collaborator

@enudler enudler left a comment

Choose a reason for hiding this comment

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

Hi @tomcorey26
Thanks for this great PR!

Left some small comments to make it compatible with all other APIs behavior

}

if (!deleteResult) {
res.status(204).json({ message: 'Context not found' });
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi!, we usually return 404 when context not found, and 204 if it's found and deleted

id: dataValues.id,
name: dataValues.name
}));
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's multiple get, so it's ok to return empty array instead 404

try {
await database.saveContext(id, contextName);
} catch (err) {
const error = new Error(err.message);
Copy link
Collaborator

Choose a reason for hiding this comment

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

we don't expect any 400 here, the open API validator needs to verify the correctness of the input data, so no need for try-catch

async function deleteContext(contextId) {
let deleteResult;
try {
deleteResult = await database.deleteContext(contextId);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above (no need try-catch)

Copy link
Collaborator

Choose a reason for hiding this comment

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

if context not found, better to throw here a 404 exception (then no need to catch it specifically in the controller)


const duplicate = await contextClient.findOne({ where: { name: contextName } });
if (duplicate) {
throw Error('Duplicate context');
Copy link
Collaborator

@enudler enudler Oct 18, 2020

Choose a reason for hiding this comment

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

need to throw here an error with 409 status code.
also need to verify that context_id doesn't exist.

Copy link
Member

@NivLipetz NivLipetz Oct 18, 2020

Choose a reason for hiding this comment

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

you defined name as unique: true in the sequelize data spec, so this if might be unnecessary and sequelize would throw an error in the contextClient.create() function if it were a duplicated name.

The error thrown should be there with status code 409

async function getContexts() {
const contextClient = client.model('context');
const options = {
attributes: { exclude: ['updated_at', 'created_at'] }
Copy link
Collaborator

Choose a reason for hiding this comment

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

created_at and updated_at not exists in this table
maybe it's a good idea to add create_at to this table

@@ -68,6 +69,7 @@ module.exports = async () => {
app.use('/v1/processors', processorsRouter);
app.use('/v1/files', filesRouter);
app.use('/v1/webhooks', webhooksRouter);
app.use('/v1/contexts', contextsRouter);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add this api spec to

  1. predator/docs/devguide/docs/swagger-docs.yaml
  2. predator/docs/openapi3.yaml

@@ -0,0 +1,57 @@

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there is a need to add unit tests as well to pass coverage threshold

@enudler
Copy link
Collaborator

enudler commented Oct 30, 2020

hi @tomcorey26
Are you able to finish this PR?

@tomcorey26 tomcorey26 closed this May 19, 2022
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 Contexts API
3 participants