Last active
August 13, 2024 12:35
-
-
Save ezzabuzaid/9c93eb3819e8d5b6338e28c89519a49c to your computer and use it in GitHub Desktop.
Todo API using Canon DSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default project( | |
feature('Todo', { | |
tables: { | |
tasks: table({ | |
fields: { | |
title: field({ type: 'short-text', validations: [mandatory()] }), | |
completed: field({ type: 'boolean' }), | |
}, | |
}), | |
}, | |
workflows: [ | |
workflow('AddTaskWorkflow', { | |
tag: 'tasks', | |
trigger: trigger.http({ | |
method: 'post', | |
path: '/', | |
}), | |
actions: { | |
addTask: action.database.insert({ | |
table: useTable('tasks'), | |
columns: [useField('title', trigger.body.title)], | |
}), | |
}, | |
}), | |
workflow('UpdateTaskWorkflow', { | |
tag: 'tasks', | |
trigger: trigger.http({ | |
method: 'patch', | |
path: '/:id', | |
}), | |
actions: { | |
updateTask: action.database.set({ | |
table: useTable('tasks'), | |
columns: [useField('title', true)], | |
query: query(where('id', 'equals', trigger.path.id)), | |
}), | |
}, | |
}), | |
workflow('ListTasksWorkflow', { | |
tag: 'tasks', | |
trigger: trigger.http({ | |
method: 'get', | |
path: '/', | |
}), | |
actions: { | |
listTasks: (trigger) => | |
action.database.list({ | |
table: useTable('tasks'), | |
pagination: 'deferred_joins', | |
limit: 20, | |
query: query(where('id', 'equals', trigger.path.id)), | |
}), | |
}, | |
}), | |
], | |
}) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment