Add public/private calendars, full iCal support, and iCal URL import
- Public/private: toggle is_public via PUT /calendars/{id}; generate/clear
public_token and return ical_url when public
- Public feed: GET /cal/{token}/feed.ics (no auth) for subscription in
Google/Apple/Outlook calendars
- Full iCal export: use golang-ical; VALARM, ATTENDEE, all-day (VALUE=DATE),
RRULE, DTSTAMP, CREATED, LAST-MODIFIED
- Full iCal import: parse TZID, VALUE=DATE, VALARM, ATTENDEE, RRULE
- Import from URL: POST /calendars/import-url with calendar_id + url
- Migration: unique index on public_token, calendar_subscriptions table
- Config: BASE_URL for ical_url; Calendar model + API: ical_url field
- Docs: OpenAPI, llms.txt, README, SKILL.md, about/overview
Made-with: Cursor
This commit is contained in:
@@ -91,6 +91,39 @@ func (q *Queries) GetCalendarByID(ctx context.Context, id pgtype.UUID) (GetCalen
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getCalendarByPublicToken = `-- name: GetCalendarByPublicToken :one
|
||||
SELECT id, owner_id, name, color, is_public, public_token, created_at, updated_at
|
||||
FROM calendars
|
||||
WHERE public_token = $1 AND is_public = true AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type GetCalendarByPublicTokenRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
Name string `json:"name"`
|
||||
Color string `json:"color"`
|
||||
IsPublic bool `json:"is_public"`
|
||||
PublicToken pgtype.Text `json:"public_token"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetCalendarByPublicToken(ctx context.Context, publicToken pgtype.Text) (GetCalendarByPublicTokenRow, error) {
|
||||
row := q.db.QueryRow(ctx, getCalendarByPublicToken, publicToken)
|
||||
var i GetCalendarByPublicTokenRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.Name,
|
||||
&i.Color,
|
||||
&i.IsPublic,
|
||||
&i.PublicToken,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listCalendarsByUser = `-- name: ListCalendarsByUser :many
|
||||
SELECT c.id, c.owner_id, c.name, c.color, c.is_public, c.created_at, c.updated_at, cm.role
|
||||
FROM calendars c
|
||||
@@ -139,6 +172,22 @@ func (q *Queries) ListCalendarsByUser(ctx context.Context, userID pgtype.UUID) (
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const setCalendarPublicToken = `-- name: SetCalendarPublicToken :exec
|
||||
UPDATE calendars
|
||||
SET public_token = $2, updated_at = now()
|
||||
WHERE id = $1 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type SetCalendarPublicTokenParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
PublicToken pgtype.Text `json:"public_token"`
|
||||
}
|
||||
|
||||
func (q *Queries) SetCalendarPublicToken(ctx context.Context, arg SetCalendarPublicTokenParams) error {
|
||||
_, err := q.db.Exec(ctx, setCalendarPublicToken, arg.ID, arg.PublicToken)
|
||||
return err
|
||||
}
|
||||
|
||||
const softDeleteCalendar = `-- name: SoftDeleteCalendar :exec
|
||||
UPDATE calendars SET deleted_at = now(), updated_at = now()
|
||||
WHERE id = $1 AND deleted_at IS NULL
|
||||
|
||||
@@ -58,6 +58,14 @@ type CalendarMember struct {
|
||||
Role string `json:"role"`
|
||||
}
|
||||
|
||||
type CalendarSubscription struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
SourceUrl string `json:"source_url"`
|
||||
LastSyncedAt pgtype.Timestamptz `json:"last_synced_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Contact struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
|
||||
55
internal/repository/subscriptions.sql.go
Normal file
55
internal/repository/subscriptions.sql.go
Normal file
@@ -0,0 +1,55 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: subscriptions.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createCalendarSubscription = `-- name: CreateCalendarSubscription :one
|
||||
INSERT INTO calendar_subscriptions (id, calendar_id, source_url)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING id, calendar_id, source_url, last_synced_at, created_at
|
||||
`
|
||||
|
||||
type CreateCalendarSubscriptionParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
SourceUrl string `json:"source_url"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateCalendarSubscription(ctx context.Context, arg CreateCalendarSubscriptionParams) (CalendarSubscription, error) {
|
||||
row := q.db.QueryRow(ctx, createCalendarSubscription, arg.ID, arg.CalendarID, arg.SourceUrl)
|
||||
var i CalendarSubscription
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CalendarID,
|
||||
&i.SourceUrl,
|
||||
&i.LastSyncedAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getSubscriptionByCalendar = `-- name: GetSubscriptionByCalendar :one
|
||||
SELECT id, calendar_id, source_url, last_synced_at, created_at FROM calendar_subscriptions
|
||||
WHERE calendar_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetSubscriptionByCalendar(ctx context.Context, calendarID pgtype.UUID) (CalendarSubscription, error) {
|
||||
row := q.db.QueryRow(ctx, getSubscriptionByCalendar, calendarID)
|
||||
var i CalendarSubscription
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CalendarID,
|
||||
&i.SourceUrl,
|
||||
&i.LastSyncedAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
Reference in New Issue
Block a user