On the second day at school, you and your classmates find yourselves diving into your first collaborative assignment. Though working together is stimulating, the challenge of managing responsibilities and progress for each team member becomes quickly apparent... 😩
During a lunch break, your group brainstorms solutions for a better system to organize the tasks and assignments.
One of your classmates proposes the idea of creating a homework diary on the famous Joogle Cloud, where each member can update tasks and monitor progress. The group quickly agrees and starts building the diary. As you observe the project taking shape, you notice a sly smile forming on the face of one student. 😼
The next day, you discover that this cunning student has exploited their access to the API keys, altering the diary to mark all their homework as completed. 🫢
Shocked and disappointment spread through the group, and you realize that the centralized solution has failed to provide the transparency and security you all craved for.
Determined to find a better way, the group gathers once more, and you share the idea of building the collaborative homework diary on the Internet Computer.
Your classmates' eyes light up as they understand the potential of a decentralized platform to foster transparency, unity, and trust among your classmates. 🫂
Your task is to create a collaborative homework diary, implement as a canister. The homework diary will allow students to create, edit, delete, and view their homework tasks.
- Import the type
Time
for theTime
library. - Define a record type
Homework
that represents a homework task. A Homework has a title field of typeText
, a description field of typeText
, a dueDate field of typeTime
, and a completed field of typeBool
. - Define a variable called
homeworkDiary
that will be used to store the homework tasks. Use a suitable data structure (such asBuffer
orArray
) for this variable. - Implement
addHomework
, which accepts a homework of typeHomework
, adds the homework to thehomeworkDiary
, and returns the id of the homework. The id should correspond to the index of the homework inhomeworkDiary
.
addHomework: shared (homework: Homework) -> async Nat;
- Implement
getHomework
, which accepts a homeworkId of typeNat
, and returns the corresponding homework wrapped in an Ok result. If the homeworkId is invalid, the function should return an error message wrapped in anErr
result.
getHomework: shared query (id: Nat) -> async Result.Result<Homework, Text>;
- Implement
updateHomework
, which accepts a homeworkId of typeNat
and a homework of typeHomework
, updates the corresponding homework inhomeworkDiary
, and returns a unit value wrapped in anOk
result. If the homeworkId is invalid, the function should return an error message wrapped in anErr
result.
updateHomework: shared (id: Nat, homework: Homework) -> async Result.Result<(), Text>;
- Implement
markAsComplete
, which accepts a homeworkId of typeNat
and updates the completed field of the corresponding homework totrue
, and returns a unit value wrapped in anOk
result. If thehomeworkId
is invalid, the function should return an error message wrapped in anErr
result.
markAsCompleted: shared (id: Nat) -> async Result.Result<(), Text>;
- Implement
deleteHomework
, which accepts ahomeworkId
of typeNat
, removes the corresponding homework from thehomeworkDiary
, and returns a unit value wrapped in anOk
result. If thehomeworkId
is invalid, the function should return an error message wrapped in anErr
result.
deleteHomework: shared (id: Nat) -> async Result.Result<(), Text>;
- Implement
getAllHomework
, which returns the list of all homework tasks inhomeworkDiary
.
getAllHomework: shared query () -> async [Homework];
- Implement
getPendingHomework
which returns the list of all uncompleted homework tasks inhomeworkDiary
.
getPendingHomework: shared query () -> async [Homework];
- Implement a
searchHomework
query function that accepts asearchTerm
of typeText
and returns a list of homework tasks that have the givensearchTerm
in their title or description.
searchHomework: shared query (searchTerm: Text) -> async [Homework];
- Deploy the howework diary on the Internet Computer.
At the end of the project, your canister should implement the following interface.
actor {
// Add a new homework task
addHomework: shared (homework: Homework) -> async Nat;
// Get a specific homework task by id
getHomework: shared query (id: Nat) -> async Result.Result<Homework, Text>;
// Update a homework task's title, description, and/or due date
updateHomework: shared (id: Nat, homework: Homework) -> async Result.Result<(), Text>;
// Mark a homework task as completed
markAsCompleted: shared (id: Nat) -> async Result.Result<(), Text>;
// Delete a homework task by id
deleteHomework: shared (id: Nat) -> async Result.Result<(), Text>;
// Get the list of all homework tasks
getAllHomework: shared query () -> async [Homework];
// Get the list of pending (not completed) homework tasks
getPendingHomework: shared query () -> async [Homework];
// Search for homework tasks based on a search terms
searchHomework: shared query (searchTerm: Text) -> async [Homework];
}