- 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
110 lines
2.0 KiB
Go
110 lines
2.0 KiB
Go
package utils
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
func ToPgUUID(id uuid.UUID) pgtype.UUID {
|
|
return pgtype.UUID{Bytes: id, Valid: true}
|
|
}
|
|
|
|
func FromPgUUID(id pgtype.UUID) uuid.UUID {
|
|
if !id.Valid {
|
|
return uuid.Nil
|
|
}
|
|
return uuid.UUID(id.Bytes)
|
|
}
|
|
|
|
func ToPgTimestamptz(t time.Time) pgtype.Timestamptz {
|
|
return pgtype.Timestamptz{Time: t, Valid: true}
|
|
}
|
|
|
|
func ToPgTimestamptzPtr(t *time.Time) pgtype.Timestamptz {
|
|
if t == nil {
|
|
return pgtype.Timestamptz{Valid: false}
|
|
}
|
|
return pgtype.Timestamptz{Time: *t, Valid: true}
|
|
}
|
|
|
|
func FromPgTimestamptz(t pgtype.Timestamptz) time.Time {
|
|
if !t.Valid {
|
|
return time.Time{}
|
|
}
|
|
return t.Time
|
|
}
|
|
|
|
func FromPgTimestamptzPtr(t pgtype.Timestamptz) *time.Time {
|
|
if !t.Valid {
|
|
return nil
|
|
}
|
|
return &t.Time
|
|
}
|
|
|
|
func ToPgText(s string) pgtype.Text {
|
|
if s == "" {
|
|
return pgtype.Text{Valid: false}
|
|
}
|
|
return pgtype.Text{String: s, Valid: true}
|
|
}
|
|
|
|
func ToPgTextPtr(s *string) pgtype.Text {
|
|
if s == nil {
|
|
return pgtype.Text{Valid: false}
|
|
}
|
|
return pgtype.Text{String: *s, Valid: true}
|
|
}
|
|
|
|
func FromPgText(t pgtype.Text) *string {
|
|
if !t.Valid {
|
|
return nil
|
|
}
|
|
return &t.String
|
|
}
|
|
|
|
func FromPgTextValue(t pgtype.Text) string {
|
|
if !t.Valid {
|
|
return ""
|
|
}
|
|
return t.String
|
|
}
|
|
|
|
func ToPgBool(b bool) pgtype.Bool {
|
|
return pgtype.Bool{Bool: b, Valid: true}
|
|
}
|
|
|
|
func ToPgInt2Ptr(i *int) pgtype.Int2 {
|
|
if i == nil {
|
|
return pgtype.Int2{Valid: false}
|
|
}
|
|
return pgtype.Int2{Int16: int16(*i), Valid: true}
|
|
}
|
|
|
|
func ToPgInt4Ptr(i *int) pgtype.Int4 {
|
|
if i == nil {
|
|
return pgtype.Int4{Valid: false}
|
|
}
|
|
return pgtype.Int4{Int32: int32(*i), Valid: true}
|
|
}
|
|
|
|
func ToPgBoolPtr(b *bool) pgtype.Bool {
|
|
if b == nil {
|
|
return pgtype.Bool{Valid: false}
|
|
}
|
|
return pgtype.Bool{Bool: *b, Valid: true}
|
|
}
|
|
|
|
func NullPgUUID() pgtype.UUID {
|
|
return pgtype.UUID{Valid: false}
|
|
}
|
|
|
|
func NullPgTimestamptz() pgtype.Timestamptz {
|
|
return pgtype.Timestamptz{Valid: false}
|
|
}
|
|
|
|
func NullPgText() pgtype.Text {
|
|
return pgtype.Text{Valid: false}
|
|
}
|