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 represents a journal entry returned from the Lunatask API.
14// Note: name and content are E2EE and not returned by 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 represents the request to create a journal entry.
23type CreateJournalEntryRequest struct {
24	// DateOn is the date for the journal entry (required).
25	DateOn Date `json:"date_on"`
26	// Name is the title for the entry (optional, defaults to weekday name like "Tuesday, July 1st").
27	Name *string `json:"name,omitempty"`
28	// Content is the Markdown content of the entry (optional).
29	Content *string `json:"content,omitempty"`
30}
31
32// journalEntryResponse represents a single journal entry response from the API.
33type journalEntryResponse struct {
34	JournalEntry JournalEntry `json:"journal_entry"`
35}
36
37// CreateJournalEntry creates a new journal entry for a given date.
38func (c *Client) CreateJournalEntry(ctx context.Context, entry *CreateJournalEntryRequest) (*JournalEntry, error) {
39	resp, _, err := doJSON[journalEntryResponse](c, ctx, http.MethodPost, "/journal_entries", entry)
40	if err != nil {
41		return nil, err
42	}
43
44	return &resp.JournalEntry, nil
45}