Phase F follow-ups (ADR-16): - Calendars: events are now stored in calendar_events by a calendars.sync job (every 15 minutes per account, 90 days back and 400 ahead), so journals open at once and keep showing events while a source is down. Google accounts connect with OAuth (calendar.readonly) through DOCWELL_GOOGLE_CLIENT_ID/SECRET; reconnecting renews access. - OneNote: whole notebooks import through Microsoft Graph (Notes.Read, DOCWELL_MICROSOFT_CLIENT_ID/SECRET/TENANT) in the background, with section groups, sections, subpages, pictures and attached files. The Microsoft sign-in lives in memory for an hour and is never stored. - Readwise: an hourly sync with the person's sealed access token; new books get a page under "Readwise", new highlights are appended once. New readwise_syncs collection. - internal/oauth: signed states and one callback route per provider, routed by purpose. directory gains ImportConverted and CallerOf. - Phone app: "Today's journal" on the home screen and calendar events on journal pages. - Web clipper: `npm run package` builds Chrome/Edge, Firefox and source zips; store/ holds listing texts, permission notes and a privacy policy. - OpenAPI, generated clients, translations, compose and .env examples, and user docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
72 lines
2.7 KiB
Go
72 lines
2.7 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package httpapi
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"docwell/server/internal/access"
|
|
"docwell/server/internal/apperr"
|
|
"docwell/server/internal/calendar"
|
|
)
|
|
|
|
// CalendarService reads people's calendars for their journals (ADR-16).
|
|
type CalendarService interface {
|
|
List(ctx context.Context, c access.Caller) ([]calendar.Account, error)
|
|
Create(ctx context.Context, c access.Caller, in calendar.AccountInput) (calendar.Account, error)
|
|
Update(ctx context.Context, c access.Caller, id string, in calendar.AccountInput) (calendar.Account, error)
|
|
Delete(ctx context.Context, c access.Caller, id string) error
|
|
Refresh(ctx context.Context, c access.Caller, id string) (calendar.Account, error)
|
|
Events(ctx context.Context, c access.Caller, from, to, tz string) ([]calendar.Event, error)
|
|
GoogleEnabled() bool
|
|
GoogleConnectURL(ctx context.Context, c access.Caller) (string, error)
|
|
}
|
|
|
|
var errNoCalendars = apperr.NotFound("calendars are not available on this server")
|
|
|
|
func (a *api) withCalendars(next http.HandlerFunc) http.HandlerFunc {
|
|
return a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
if a.calendars == nil {
|
|
a.writeError(w, errNoCalendars)
|
|
return
|
|
}
|
|
next(w, r)
|
|
})
|
|
}
|
|
|
|
func (a *api) calendarRoutes(mux *routeMux) {
|
|
mux.HandleFunc("GET /api/v1/calendars", a.withCalendars(func(w http.ResponseWriter, r *http.Request) {
|
|
v, err := a.calendars.List(r.Context(), caller(r))
|
|
a.respond(w, v, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/calendars", a.withCalendars(func(w http.ResponseWriter, r *http.Request) {
|
|
var in calendar.AccountInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
v, err := a.calendars.Create(r.Context(), caller(r), in)
|
|
a.respondStatus(w, http.StatusCreated, v, err)
|
|
}))
|
|
mux.HandleFunc("PATCH /api/v1/calendars/{id}", a.withCalendars(func(w http.ResponseWriter, r *http.Request) {
|
|
var in calendar.AccountInput
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
v, err := a.calendars.Update(r.Context(), caller(r), r.PathValue("id"), in)
|
|
a.respond(w, v, err)
|
|
}))
|
|
mux.HandleFunc("DELETE /api/v1/calendars/{id}", a.withCalendars(func(w http.ResponseWriter, r *http.Request) {
|
|
a.respondNoContent(w, a.calendars.Delete(r.Context(), caller(r), r.PathValue("id")))
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/calendars/{id}/refresh", a.withCalendars(func(w http.ResponseWriter, r *http.Request) {
|
|
v, err := a.calendars.Refresh(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, v, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/calendar/events", a.withCalendars(func(w http.ResponseWriter, r *http.Request) {
|
|
q := r.URL.Query()
|
|
v, err := a.calendars.Events(r.Context(), caller(r), q.Get("from"), q.Get("to"), q.Get("tz"))
|
|
a.respond(w, v, err)
|
|
}))
|
|
}
|