Skip to content

Instantly share code, notes, and snippets.

@ezzabuzaid
Last active August 13, 2024 12:35
Show Gist options
  • Save ezzabuzaid/9c93eb3819e8d5b6338e28c89519a49c to your computer and use it in GitHub Desktop.
Save ezzabuzaid/9c93eb3819e8d5b6338e28c89519a49c to your computer and use it in GitHub Desktop.
Todo API using Canon DSL
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