Habit status records a habit’s details together with how many times it has been completed during a specified week. It answers whether the weekly goal is complete and helps plan the remaining time. section 10.0 section 10.7
A status request uses:
- A habit identifier to select the habit. section 10.7.4
- An optional timestamp to select the week being inspected. section 10.7.4
- A response containing the habit and its tick count for that week. section 10.7.4
The status is calculated from separate habit and tick data. Ticking a habit records completion; retrieving status counts the relevant ticks without requiring the client to manage that storage directly. section 10.7.1 section 10.7.4
Reading a weekly status
A habit with weeklyFrequency 3 and ticksCount 2 has been completed twice in the selected week. The remaining target is one completion.
Listing 10.37 api/proto/service.go: GetHabitStatus definition
// GetHabitStatus is the endpoint to retrieve the status of
//ticks of a habit.
rpc GetHabitStatus(
GetHabitStatusRequest
) returns (GetHabitStatusResponse);
// GetHabitStatusRequest is the request to GetHabitStatus endpoint.
message GetHabitStatusRequest {
// The identifier of the habit we want to retrieve.
string habit_id = 1;
// The time for which we want to retrieve the status of a habit.
optional google.protobuf.Timestamp timestamp = 2;
}
// GetHabitStatusResponse is the response to retrieving the status of a
// habit.
message GetHabitStatusResponse {
// All the information of a habit.
Habit habit = 1;
// The number of times the habit has been ticked for a given week.
int32 ticks_count = 2;
}
Inspect the Protocol Buffers contract for GetHabitStatus, including the habit ID, optional timestamp, returned habit, and weekly tick count. section 10.7.4
Integration tests can tick habits, retrieve their generated IDs, and verify returned habit data and tick counts. Timestamped calls also verify statuses for previous weeks. section 10.7.6
