liveBook · Manning

Habit status

As explained in Learn Go with Pocket-Sized Projects

Habit status is the recorded state of a habit, including information about its completion or progress.

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:

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

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Defines request and response fields, separates tick storage, and demonstrates endpoint and integration-test behavior.
Examples
Demonstrates grpcurl responses, current-week ticks, previous-week timestamps, and Go integration-test assertions.
What it assumes
Assumes familiarity with habits and weekly goals while teaching the status API, tick counting, timestamps, and layered implementation.
What you can do after
Operate and test weekly completion tracking through TickHabit and GetHabitStatus gRPC calls.
How it connects
Connects habits with weekly frequency, completion ticks, timestamps, gRPC, Protocol Buffers, repositories, and integration testing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.