Add OpenAPI docs, frontend, migrations, and API updates
- OpenAPI: add missing endpoints (add-from-url, subscriptions, public availability) - OpenAPI: CalendarSubscription schema, Subscriptions tag - Frontend app - Migrations: count_for_availability, subscriptions_sync, user_preferences, calendar_settings - Config, rate limit, auth, calendar, booking, ICS, availability, user service updates Made-with: Cursor
This commit is contained in:
@@ -14,7 +14,7 @@ import (
|
||||
const createCalendar = `-- name: CreateCalendar :one
|
||||
INSERT INTO calendars (id, owner_id, name, color, is_public)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id, owner_id, name, color, is_public, public_token, created_at, updated_at
|
||||
RETURNING id, owner_id, name, color, is_public, public_token, count_for_availability, default_reminder_minutes, sort_order, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateCalendarParams struct {
|
||||
@@ -26,14 +26,17 @@ type CreateCalendarParams struct {
|
||||
}
|
||||
|
||||
type CreateCalendarRow 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"`
|
||||
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"`
|
||||
CountForAvailability bool `json:"count_for_availability"`
|
||||
DefaultReminderMinutes pgtype.Int4 `json:"default_reminder_minutes"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateCalendar(ctx context.Context, arg CreateCalendarParams) (CreateCalendarRow, error) {
|
||||
@@ -52,6 +55,9 @@ func (q *Queries) CreateCalendar(ctx context.Context, arg CreateCalendarParams)
|
||||
&i.Color,
|
||||
&i.IsPublic,
|
||||
&i.PublicToken,
|
||||
&i.CountForAvailability,
|
||||
&i.DefaultReminderMinutes,
|
||||
&i.SortOrder,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
@@ -59,20 +65,23 @@ func (q *Queries) CreateCalendar(ctx context.Context, arg CreateCalendarParams)
|
||||
}
|
||||
|
||||
const getCalendarByID = `-- name: GetCalendarByID :one
|
||||
SELECT id, owner_id, name, color, is_public, public_token, created_at, updated_at
|
||||
SELECT id, owner_id, name, color, is_public, public_token, count_for_availability, default_reminder_minutes, sort_order, created_at, updated_at
|
||||
FROM calendars
|
||||
WHERE id = $1 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type GetCalendarByIDRow 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"`
|
||||
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"`
|
||||
CountForAvailability bool `json:"count_for_availability"`
|
||||
DefaultReminderMinutes pgtype.Int4 `json:"default_reminder_minutes"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetCalendarByID(ctx context.Context, id pgtype.UUID) (GetCalendarByIDRow, error) {
|
||||
@@ -85,32 +94,38 @@ func (q *Queries) GetCalendarByID(ctx context.Context, id pgtype.UUID) (GetCalen
|
||||
&i.Color,
|
||||
&i.IsPublic,
|
||||
&i.PublicToken,
|
||||
&i.CountForAvailability,
|
||||
&i.DefaultReminderMinutes,
|
||||
&i.SortOrder,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getCalendarByPublicToken = `-- name: GetCalendarByPublicToken :one
|
||||
SELECT id, owner_id, name, color, is_public, public_token, created_at, updated_at
|
||||
const getCalendarByToken = `-- name: GetCalendarByToken :one
|
||||
SELECT id, owner_id, name, color, is_public, public_token, count_for_availability, default_reminder_minutes, sort_order, created_at, updated_at
|
||||
FROM calendars
|
||||
WHERE public_token = $1 AND is_public = true AND deleted_at IS NULL
|
||||
WHERE public_token = $1 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"`
|
||||
type GetCalendarByTokenRow 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"`
|
||||
CountForAvailability bool `json:"count_for_availability"`
|
||||
DefaultReminderMinutes pgtype.Int4 `json:"default_reminder_minutes"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
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
|
||||
func (q *Queries) GetCalendarByToken(ctx context.Context, publicToken pgtype.Text) (GetCalendarByTokenRow, error) {
|
||||
row := q.db.QueryRow(ctx, getCalendarByToken, publicToken)
|
||||
var i GetCalendarByTokenRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
@@ -118,14 +133,69 @@ func (q *Queries) GetCalendarByPublicToken(ctx context.Context, publicToken pgty
|
||||
&i.Color,
|
||||
&i.IsPublic,
|
||||
&i.PublicToken,
|
||||
&i.CountForAvailability,
|
||||
&i.DefaultReminderMinutes,
|
||||
&i.SortOrder,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listCalendarsByOwnerForAvailability = `-- name: ListCalendarsByOwnerForAvailability :many
|
||||
SELECT id, owner_id, name, color, is_public, public_token, count_for_availability, default_reminder_minutes, sort_order, created_at, updated_at
|
||||
FROM calendars
|
||||
WHERE owner_id = $1 AND deleted_at IS NULL AND count_for_availability = true
|
||||
`
|
||||
|
||||
type ListCalendarsByOwnerForAvailabilityRow 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"`
|
||||
CountForAvailability bool `json:"count_for_availability"`
|
||||
DefaultReminderMinutes pgtype.Int4 `json:"default_reminder_minutes"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListCalendarsByOwnerForAvailability(ctx context.Context, ownerID pgtype.UUID) ([]ListCalendarsByOwnerForAvailabilityRow, error) {
|
||||
rows, err := q.db.Query(ctx, listCalendarsByOwnerForAvailability, ownerID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListCalendarsByOwnerForAvailabilityRow{}
|
||||
for rows.Next() {
|
||||
var i ListCalendarsByOwnerForAvailabilityRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.Name,
|
||||
&i.Color,
|
||||
&i.IsPublic,
|
||||
&i.PublicToken,
|
||||
&i.CountForAvailability,
|
||||
&i.DefaultReminderMinutes,
|
||||
&i.SortOrder,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
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
|
||||
SELECT c.id, c.owner_id, c.name, c.color, c.is_public, c.count_for_availability, c.default_reminder_minutes, c.sort_order, c.created_at, c.updated_at, cm.role
|
||||
FROM calendars c
|
||||
JOIN calendar_members cm ON cm.calendar_id = c.id
|
||||
WHERE cm.user_id = $1 AND c.deleted_at IS NULL
|
||||
@@ -133,14 +203,17 @@ ORDER BY c.created_at ASC
|
||||
`
|
||||
|
||||
type ListCalendarsByUserRow 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"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
Role string `json:"role"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
Name string `json:"name"`
|
||||
Color string `json:"color"`
|
||||
IsPublic bool `json:"is_public"`
|
||||
CountForAvailability bool `json:"count_for_availability"`
|
||||
DefaultReminderMinutes pgtype.Int4 `json:"default_reminder_minutes"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListCalendarsByUser(ctx context.Context, userID pgtype.UUID) ([]ListCalendarsByUserRow, error) {
|
||||
@@ -158,6 +231,9 @@ func (q *Queries) ListCalendarsByUser(ctx context.Context, userID pgtype.UUID) (
|
||||
&i.Name,
|
||||
&i.Color,
|
||||
&i.IsPublic,
|
||||
&i.CountForAvailability,
|
||||
&i.DefaultReminderMinutes,
|
||||
&i.SortOrder,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Role,
|
||||
@@ -213,27 +289,36 @@ UPDATE calendars
|
||||
SET name = COALESCE($1::TEXT, name),
|
||||
color = COALESCE($2::TEXT, color),
|
||||
is_public = COALESCE($3::BOOLEAN, is_public),
|
||||
count_for_availability = COALESCE($4::BOOLEAN, count_for_availability),
|
||||
default_reminder_minutes = COALESCE($5::INTEGER, default_reminder_minutes),
|
||||
sort_order = COALESCE($6::INTEGER, sort_order),
|
||||
updated_at = now()
|
||||
WHERE id = $4 AND deleted_at IS NULL
|
||||
RETURNING id, owner_id, name, color, is_public, public_token, created_at, updated_at
|
||||
WHERE id = $7 AND deleted_at IS NULL
|
||||
RETURNING id, owner_id, name, color, is_public, public_token, count_for_availability, default_reminder_minutes, sort_order, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateCalendarParams struct {
|
||||
Name pgtype.Text `json:"name"`
|
||||
Color pgtype.Text `json:"color"`
|
||||
IsPublic pgtype.Bool `json:"is_public"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Name pgtype.Text `json:"name"`
|
||||
Color pgtype.Text `json:"color"`
|
||||
IsPublic pgtype.Bool `json:"is_public"`
|
||||
CountForAvailability pgtype.Bool `json:"count_for_availability"`
|
||||
DefaultReminderMinutes pgtype.Int4 `json:"default_reminder_minutes"`
|
||||
SortOrder pgtype.Int4 `json:"sort_order"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
}
|
||||
|
||||
type UpdateCalendarRow 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"`
|
||||
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"`
|
||||
CountForAvailability bool `json:"count_for_availability"`
|
||||
DefaultReminderMinutes pgtype.Int4 `json:"default_reminder_minutes"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateCalendar(ctx context.Context, arg UpdateCalendarParams) (UpdateCalendarRow, error) {
|
||||
@@ -241,6 +326,9 @@ func (q *Queries) UpdateCalendar(ctx context.Context, arg UpdateCalendarParams)
|
||||
arg.Name,
|
||||
arg.Color,
|
||||
arg.IsPublic,
|
||||
arg.CountForAvailability,
|
||||
arg.DefaultReminderMinutes,
|
||||
arg.SortOrder,
|
||||
arg.ID,
|
||||
)
|
||||
var i UpdateCalendarRow
|
||||
@@ -251,6 +339,9 @@ func (q *Queries) UpdateCalendar(ctx context.Context, arg UpdateCalendarParams)
|
||||
&i.Color,
|
||||
&i.IsPublic,
|
||||
&i.PublicToken,
|
||||
&i.CountForAvailability,
|
||||
&i.DefaultReminderMinutes,
|
||||
&i.SortOrder,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
|
||||
@@ -41,15 +41,18 @@ type BookingLink struct {
|
||||
}
|
||||
|
||||
type Calendar 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"`
|
||||
DeletedAt pgtype.Timestamptz `json:"deleted_at"`
|
||||
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"`
|
||||
CountForAvailability bool `json:"count_for_availability"`
|
||||
DefaultReminderMinutes pgtype.Int4 `json:"default_reminder_minutes"`
|
||||
SortOrder int32 `json:"sort_order"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
DeletedAt pgtype.Timestamptz `json:"deleted_at"`
|
||||
}
|
||||
|
||||
type CalendarMember struct {
|
||||
@@ -59,11 +62,12 @@ type CalendarMember struct {
|
||||
}
|
||||
|
||||
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"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
SourceUrl string `json:"source_url"`
|
||||
LastSyncedAt pgtype.Timestamptz `json:"last_synced_at"`
|
||||
SyncIntervalMinutes pgtype.Int4 `json:"sync_interval_minutes"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type Contact struct {
|
||||
@@ -136,12 +140,21 @@ type RefreshToken struct {
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
PasswordHash string `json:"password_hash"`
|
||||
Timezone string `json:"timezone"`
|
||||
IsActive bool `json:"is_active"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
DeletedAt pgtype.Timestamptz `json:"deleted_at"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
PasswordHash string `json:"password_hash"`
|
||||
Timezone string `json:"timezone"`
|
||||
IsActive bool `json:"is_active"`
|
||||
WeekStartDay int16 `json:"week_start_day"`
|
||||
DateFormat string `json:"date_format"`
|
||||
TimeFormat string `json:"time_format"`
|
||||
DefaultEventDurationMinutes int32 `json:"default_event_duration_minutes"`
|
||||
DefaultReminderMinutes int32 `json:"default_reminder_minutes"`
|
||||
ShowWeekends bool `json:"show_weekends"`
|
||||
WorkingHoursStart string `json:"working_hours_start"`
|
||||
WorkingHoursEnd string `json:"working_hours_end"`
|
||||
NotificationsEmail bool `json:"notifications_email"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
DeletedAt pgtype.Timestamptz `json:"deleted_at"`
|
||||
}
|
||||
|
||||
@@ -12,44 +12,143 @@ import (
|
||||
)
|
||||
|
||||
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
|
||||
INSERT INTO calendar_subscriptions (id, calendar_id, source_url, sync_interval_minutes)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, calendar_id, source_url, last_synced_at, sync_interval_minutes, created_at
|
||||
`
|
||||
|
||||
type CreateCalendarSubscriptionParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
SourceUrl string `json:"source_url"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
SourceUrl string `json:"source_url"`
|
||||
SyncIntervalMinutes pgtype.Int4 `json:"sync_interval_minutes"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateCalendarSubscription(ctx context.Context, arg CreateCalendarSubscriptionParams) (CalendarSubscription, error) {
|
||||
row := q.db.QueryRow(ctx, createCalendarSubscription, arg.ID, arg.CalendarID, arg.SourceUrl)
|
||||
row := q.db.QueryRow(ctx, createCalendarSubscription,
|
||||
arg.ID,
|
||||
arg.CalendarID,
|
||||
arg.SourceUrl,
|
||||
arg.SyncIntervalMinutes,
|
||||
)
|
||||
var i CalendarSubscription
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CalendarID,
|
||||
&i.SourceUrl,
|
||||
&i.LastSyncedAt,
|
||||
&i.SyncIntervalMinutes,
|
||||
&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
|
||||
const deleteSubscription = `-- name: DeleteSubscription :exec
|
||||
DELETE FROM calendar_subscriptions
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetSubscriptionByCalendar(ctx context.Context, calendarID pgtype.UUID) (CalendarSubscription, error) {
|
||||
row := q.db.QueryRow(ctx, getSubscriptionByCalendar, calendarID)
|
||||
func (q *Queries) DeleteSubscription(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteSubscription, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getSubscriptionByID = `-- name: GetSubscriptionByID :one
|
||||
SELECT id, calendar_id, source_url, last_synced_at, sync_interval_minutes, created_at FROM calendar_subscriptions
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetSubscriptionByID(ctx context.Context, id pgtype.UUID) (CalendarSubscription, error) {
|
||||
row := q.db.QueryRow(ctx, getSubscriptionByID, id)
|
||||
var i CalendarSubscription
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CalendarID,
|
||||
&i.SourceUrl,
|
||||
&i.LastSyncedAt,
|
||||
&i.SyncIntervalMinutes,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listSubscriptionsByCalendar = `-- name: ListSubscriptionsByCalendar :many
|
||||
SELECT id, calendar_id, source_url, last_synced_at, sync_interval_minutes, created_at FROM calendar_subscriptions
|
||||
WHERE calendar_id = $1
|
||||
ORDER BY created_at ASC
|
||||
`
|
||||
|
||||
func (q *Queries) ListSubscriptionsByCalendar(ctx context.Context, calendarID pgtype.UUID) ([]CalendarSubscription, error) {
|
||||
rows, err := q.db.Query(ctx, listSubscriptionsByCalendar, calendarID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []CalendarSubscription{}
|
||||
for rows.Next() {
|
||||
var i CalendarSubscription
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.CalendarID,
|
||||
&i.SourceUrl,
|
||||
&i.LastSyncedAt,
|
||||
&i.SyncIntervalMinutes,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateSubscriptionLastSynced = `-- name: UpdateSubscriptionLastSynced :exec
|
||||
UPDATE calendar_subscriptions
|
||||
SET last_synced_at = now()
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) UpdateSubscriptionLastSynced(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, updateSubscriptionLastSynced, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const listSubscriptionsDueForSync = `-- name: ListSubscriptionsDueForSync :many
|
||||
SELECT s.id, s.calendar_id, s.source_url, c.owner_id
|
||||
FROM calendar_subscriptions s
|
||||
JOIN calendars c ON c.id = s.calendar_id AND c.deleted_at IS NULL
|
||||
WHERE s.sync_interval_minutes IS NOT NULL
|
||||
AND s.sync_interval_minutes > 0
|
||||
AND (s.last_synced_at IS NULL
|
||||
OR s.last_synced_at + make_interval(mins => s.sync_interval_minutes::numeric) <= now())
|
||||
`
|
||||
|
||||
type ListSubscriptionsDueForSyncRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
SourceUrl string `json:"source_url"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListSubscriptionsDueForSync(ctx context.Context) ([]ListSubscriptionsDueForSyncRow, error) {
|
||||
rows, err := q.db.Query(ctx, listSubscriptionsDueForSync)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListSubscriptionsDueForSyncRow
|
||||
for rows.Next() {
|
||||
var i ListSubscriptionsDueForSyncRow
|
||||
if err := rows.Scan(&i.ID, &i.CalendarID, &i.SourceUrl, &i.OwnerID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
@@ -55,19 +55,30 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateU
|
||||
}
|
||||
|
||||
const getUserByEmail = `-- name: GetUserByEmail :one
|
||||
SELECT id, email, password_hash, timezone, is_active, created_at, updated_at
|
||||
SELECT id, email, password_hash, timezone, is_active, week_start_day, date_format, time_format,
|
||||
default_event_duration_minutes, default_reminder_minutes, show_weekends,
|
||||
working_hours_start, working_hours_end, notifications_email, created_at, updated_at
|
||||
FROM users
|
||||
WHERE email = $1 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type GetUserByEmailRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
PasswordHash string `json:"password_hash"`
|
||||
Timezone string `json:"timezone"`
|
||||
IsActive bool `json:"is_active"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
PasswordHash string `json:"password_hash"`
|
||||
Timezone string `json:"timezone"`
|
||||
IsActive bool `json:"is_active"`
|
||||
WeekStartDay int16 `json:"week_start_day"`
|
||||
DateFormat string `json:"date_format"`
|
||||
TimeFormat string `json:"time_format"`
|
||||
DefaultEventDurationMinutes int32 `json:"default_event_duration_minutes"`
|
||||
DefaultReminderMinutes int32 `json:"default_reminder_minutes"`
|
||||
ShowWeekends bool `json:"show_weekends"`
|
||||
WorkingHoursStart string `json:"working_hours_start"`
|
||||
WorkingHoursEnd string `json:"working_hours_end"`
|
||||
NotificationsEmail bool `json:"notifications_email"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserByEmail(ctx context.Context, email string) (GetUserByEmailRow, error) {
|
||||
@@ -79,6 +90,15 @@ func (q *Queries) GetUserByEmail(ctx context.Context, email string) (GetUserByEm
|
||||
&i.PasswordHash,
|
||||
&i.Timezone,
|
||||
&i.IsActive,
|
||||
&i.WeekStartDay,
|
||||
&i.DateFormat,
|
||||
&i.TimeFormat,
|
||||
&i.DefaultEventDurationMinutes,
|
||||
&i.DefaultReminderMinutes,
|
||||
&i.ShowWeekends,
|
||||
&i.WorkingHoursStart,
|
||||
&i.WorkingHoursEnd,
|
||||
&i.NotificationsEmail,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
@@ -86,19 +106,30 @@ func (q *Queries) GetUserByEmail(ctx context.Context, email string) (GetUserByEm
|
||||
}
|
||||
|
||||
const getUserByID = `-- name: GetUserByID :one
|
||||
SELECT id, email, password_hash, timezone, is_active, created_at, updated_at
|
||||
SELECT id, email, password_hash, timezone, is_active, week_start_day, date_format, time_format,
|
||||
default_event_duration_minutes, default_reminder_minutes, show_weekends,
|
||||
working_hours_start, working_hours_end, notifications_email, created_at, updated_at
|
||||
FROM users
|
||||
WHERE id = $1 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type GetUserByIDRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
PasswordHash string `json:"password_hash"`
|
||||
Timezone string `json:"timezone"`
|
||||
IsActive bool `json:"is_active"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
PasswordHash string `json:"password_hash"`
|
||||
Timezone string `json:"timezone"`
|
||||
IsActive bool `json:"is_active"`
|
||||
WeekStartDay int16 `json:"week_start_day"`
|
||||
DateFormat string `json:"date_format"`
|
||||
TimeFormat string `json:"time_format"`
|
||||
DefaultEventDurationMinutes int32 `json:"default_event_duration_minutes"`
|
||||
DefaultReminderMinutes int32 `json:"default_reminder_minutes"`
|
||||
ShowWeekends bool `json:"show_weekends"`
|
||||
WorkingHoursStart string `json:"working_hours_start"`
|
||||
WorkingHoursEnd string `json:"working_hours_end"`
|
||||
NotificationsEmail bool `json:"notifications_email"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserByID(ctx context.Context, id pgtype.UUID) (GetUserByIDRow, error) {
|
||||
@@ -110,6 +141,15 @@ func (q *Queries) GetUserByID(ctx context.Context, id pgtype.UUID) (GetUserByIDR
|
||||
&i.PasswordHash,
|
||||
&i.Timezone,
|
||||
&i.IsActive,
|
||||
&i.WeekStartDay,
|
||||
&i.DateFormat,
|
||||
&i.TimeFormat,
|
||||
&i.DefaultEventDurationMinutes,
|
||||
&i.DefaultReminderMinutes,
|
||||
&i.ShowWeekends,
|
||||
&i.WorkingHoursStart,
|
||||
&i.WorkingHoursEnd,
|
||||
&i.NotificationsEmail,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
@@ -129,28 +169,69 @@ func (q *Queries) SoftDeleteUser(ctx context.Context, id pgtype.UUID) error {
|
||||
const updateUser = `-- name: UpdateUser :one
|
||||
UPDATE users
|
||||
SET timezone = COALESCE($1::TEXT, timezone),
|
||||
week_start_day = COALESCE($2::SMALLINT, week_start_day),
|
||||
date_format = COALESCE($3::TEXT, date_format),
|
||||
time_format = COALESCE($4::TEXT, time_format),
|
||||
default_event_duration_minutes = COALESCE($5::INTEGER, default_event_duration_minutes),
|
||||
default_reminder_minutes = COALESCE($6::INTEGER, default_reminder_minutes),
|
||||
show_weekends = COALESCE($7::BOOLEAN, show_weekends),
|
||||
working_hours_start = COALESCE($8::TEXT, working_hours_start),
|
||||
working_hours_end = COALESCE($9::TEXT, working_hours_end),
|
||||
notifications_email = COALESCE($10::BOOLEAN, notifications_email),
|
||||
updated_at = now()
|
||||
WHERE id = $2 AND deleted_at IS NULL
|
||||
RETURNING id, email, password_hash, timezone, is_active, created_at, updated_at
|
||||
WHERE id = $11 AND deleted_at IS NULL
|
||||
RETURNING id, email, password_hash, timezone, is_active, week_start_day, date_format, time_format,
|
||||
default_event_duration_minutes, default_reminder_minutes, show_weekends,
|
||||
working_hours_start, working_hours_end, notifications_email, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateUserParams struct {
|
||||
Timezone pgtype.Text `json:"timezone"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Timezone pgtype.Text `json:"timezone"`
|
||||
WeekStartDay pgtype.Int2 `json:"week_start_day"`
|
||||
DateFormat pgtype.Text `json:"date_format"`
|
||||
TimeFormat pgtype.Text `json:"time_format"`
|
||||
DefaultEventDurationMinutes pgtype.Int4 `json:"default_event_duration_minutes"`
|
||||
DefaultReminderMinutes pgtype.Int4 `json:"default_reminder_minutes"`
|
||||
ShowWeekends pgtype.Bool `json:"show_weekends"`
|
||||
WorkingHoursStart pgtype.Text `json:"working_hours_start"`
|
||||
WorkingHoursEnd pgtype.Text `json:"working_hours_end"`
|
||||
NotificationsEmail pgtype.Bool `json:"notifications_email"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
}
|
||||
|
||||
type UpdateUserRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
PasswordHash string `json:"password_hash"`
|
||||
Timezone string `json:"timezone"`
|
||||
IsActive bool `json:"is_active"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
PasswordHash string `json:"password_hash"`
|
||||
Timezone string `json:"timezone"`
|
||||
IsActive bool `json:"is_active"`
|
||||
WeekStartDay int16 `json:"week_start_day"`
|
||||
DateFormat string `json:"date_format"`
|
||||
TimeFormat string `json:"time_format"`
|
||||
DefaultEventDurationMinutes int32 `json:"default_event_duration_minutes"`
|
||||
DefaultReminderMinutes int32 `json:"default_reminder_minutes"`
|
||||
ShowWeekends bool `json:"show_weekends"`
|
||||
WorkingHoursStart string `json:"working_hours_start"`
|
||||
WorkingHoursEnd string `json:"working_hours_end"`
|
||||
NotificationsEmail bool `json:"notifications_email"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (UpdateUserRow, error) {
|
||||
row := q.db.QueryRow(ctx, updateUser, arg.Timezone, arg.ID)
|
||||
row := q.db.QueryRow(ctx, updateUser,
|
||||
arg.Timezone,
|
||||
arg.WeekStartDay,
|
||||
arg.DateFormat,
|
||||
arg.TimeFormat,
|
||||
arg.DefaultEventDurationMinutes,
|
||||
arg.DefaultReminderMinutes,
|
||||
arg.ShowWeekends,
|
||||
arg.WorkingHoursStart,
|
||||
arg.WorkingHoursEnd,
|
||||
arg.NotificationsEmail,
|
||||
arg.ID,
|
||||
)
|
||||
var i UpdateUserRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
@@ -158,6 +239,15 @@ func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (UpdateU
|
||||
&i.PasswordHash,
|
||||
&i.Timezone,
|
||||
&i.IsActive,
|
||||
&i.WeekStartDay,
|
||||
&i.DateFormat,
|
||||
&i.TimeFormat,
|
||||
&i.DefaultEventDurationMinutes,
|
||||
&i.DefaultReminderMinutes,
|
||||
&i.ShowWeekends,
|
||||
&i.WorkingHoursStart,
|
||||
&i.WorkingHoursEnd,
|
||||
&i.NotificationsEmail,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user