journal.go

 1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
 2//
 3// SPDX-License-Identifier: AGPL-3.0-or-later
 4
 5package lunatask
 6
 7import (
 8	"context"
 9	"net/http"
10	"time"
11)
12
13// JournalEntry is a daily journal entry. Name and Content are encrypted
14// client-side and will be null when read back from the API.
15type JournalEntry struct {
16	ID        string    `json:"id"`
17	DateOn    Date      `json:"date_on"`
18	CreatedAt time.Time `json:"created_at"`
19	UpdatedAt time.Time `json:"updated_at"`
20}
21
22// CreateJournalEntryRequest defines a new journal entry.
23// Use [JournalEntryBuilder] for a fluent construction API.
24type CreateJournalEntryRequest struct {
25	// DateOn is the date for the journal entry (required).
26	DateOn Date `json:"date_on"`
27	// Name is the title for the entry (optional, defaults to weekday name like "Tuesday, July 1st").
28	Name *string `json:"name,omitempty"`
29	// Content is the Markdown content of the entry (optional).
30	Content *string `json:"content,omitempty"`
31}
32
33// journalEntryResponse wraps a single journal entry from the API.
34type journalEntryResponse struct {
35	JournalEntry JournalEntry `json:"journal_entry"`
36}
37
38// CreateJournalEntry adds a journal entry. Returns the created entry's metadata;
39// Name and Content won't round-trip due to E2EE.
40func (c *Client) CreateJournalEntry(ctx context.Context, entry *CreateJournalEntryRequest) (*JournalEntry, error) {
41	resp, _, err := doJSON[journalEntryResponse](ctx, c, http.MethodPost, "/journal_entries", entry)
42	if err != nil {
43		return nil, err
44	}
45
46	return &resp.JournalEntry, nil
47}