first commit
Made-with: Cursor
This commit is contained in:
134
internal/repository/api_keys.sql.go
Normal file
134
internal/repository/api_keys.sql.go
Normal file
@@ -0,0 +1,134 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: api_keys.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createAPIKey = `-- name: CreateAPIKey :one
|
||||
INSERT INTO api_keys (id, user_id, name, key_hash, scopes)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id, user_id, name, key_hash, scopes, created_at, revoked_at
|
||||
`
|
||||
|
||||
type CreateAPIKeyParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Name string `json:"name"`
|
||||
KeyHash string `json:"key_hash"`
|
||||
Scopes []byte `json:"scopes"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateAPIKey(ctx context.Context, arg CreateAPIKeyParams) (ApiKey, error) {
|
||||
row := q.db.QueryRow(ctx, createAPIKey,
|
||||
arg.ID,
|
||||
arg.UserID,
|
||||
arg.Name,
|
||||
arg.KeyHash,
|
||||
arg.Scopes,
|
||||
)
|
||||
var i ApiKey
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.Name,
|
||||
&i.KeyHash,
|
||||
&i.Scopes,
|
||||
&i.CreatedAt,
|
||||
&i.RevokedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getAPIKeyByHash = `-- name: GetAPIKeyByHash :one
|
||||
SELECT id, user_id, name, key_hash, scopes, created_at, revoked_at
|
||||
FROM api_keys
|
||||
WHERE key_hash = $1 AND revoked_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) GetAPIKeyByHash(ctx context.Context, keyHash string) (ApiKey, error) {
|
||||
row := q.db.QueryRow(ctx, getAPIKeyByHash, keyHash)
|
||||
var i ApiKey
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.Name,
|
||||
&i.KeyHash,
|
||||
&i.Scopes,
|
||||
&i.CreatedAt,
|
||||
&i.RevokedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listAPIKeysByUser = `-- name: ListAPIKeysByUser :many
|
||||
SELECT id, name, scopes, created_at, revoked_at
|
||||
FROM api_keys
|
||||
WHERE user_id = $1
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
type ListAPIKeysByUserRow struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Scopes []byte `json:"scopes"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
RevokedAt pgtype.Timestamptz `json:"revoked_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListAPIKeysByUser(ctx context.Context, userID pgtype.UUID) ([]ListAPIKeysByUserRow, error) {
|
||||
rows, err := q.db.Query(ctx, listAPIKeysByUser, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListAPIKeysByUserRow{}
|
||||
for rows.Next() {
|
||||
var i ListAPIKeysByUserRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Scopes,
|
||||
&i.CreatedAt,
|
||||
&i.RevokedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const revokeAPIKey = `-- name: RevokeAPIKey :exec
|
||||
UPDATE api_keys SET revoked_at = now()
|
||||
WHERE id = $1 AND user_id = $2 AND revoked_at IS NULL
|
||||
`
|
||||
|
||||
type RevokeAPIKeyParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) RevokeAPIKey(ctx context.Context, arg RevokeAPIKeyParams) error {
|
||||
_, err := q.db.Exec(ctx, revokeAPIKey, arg.ID, arg.UserID)
|
||||
return err
|
||||
}
|
||||
|
||||
const revokeAllUserAPIKeys = `-- name: RevokeAllUserAPIKeys :exec
|
||||
UPDATE api_keys SET revoked_at = now()
|
||||
WHERE user_id = $1 AND revoked_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) RevokeAllUserAPIKeys(ctx context.Context, userID pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, revokeAllUserAPIKeys, userID)
|
||||
return err
|
||||
}
|
||||
72
internal/repository/attachments.sql.go
Normal file
72
internal/repository/attachments.sql.go
Normal file
@@ -0,0 +1,72 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: attachments.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createAttachment = `-- name: CreateAttachment :one
|
||||
INSERT INTO event_attachments (id, event_id, file_url)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING id, event_id, file_url
|
||||
`
|
||||
|
||||
type CreateAttachmentParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
EventID pgtype.UUID `json:"event_id"`
|
||||
FileUrl string `json:"file_url"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateAttachment(ctx context.Context, arg CreateAttachmentParams) (EventAttachment, error) {
|
||||
row := q.db.QueryRow(ctx, createAttachment, arg.ID, arg.EventID, arg.FileUrl)
|
||||
var i EventAttachment
|
||||
err := row.Scan(&i.ID, &i.EventID, &i.FileUrl)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteAttachment = `-- name: DeleteAttachment :exec
|
||||
DELETE FROM event_attachments WHERE id = $1 AND event_id = $2
|
||||
`
|
||||
|
||||
type DeleteAttachmentParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
EventID pgtype.UUID `json:"event_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteAttachment(ctx context.Context, arg DeleteAttachmentParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteAttachment, arg.ID, arg.EventID)
|
||||
return err
|
||||
}
|
||||
|
||||
const listAttachmentsByEvent = `-- name: ListAttachmentsByEvent :many
|
||||
SELECT id, event_id, file_url
|
||||
FROM event_attachments
|
||||
WHERE event_id = $1
|
||||
ORDER BY id ASC
|
||||
`
|
||||
|
||||
func (q *Queries) ListAttachmentsByEvent(ctx context.Context, eventID pgtype.UUID) ([]EventAttachment, error) {
|
||||
rows, err := q.db.Query(ctx, listAttachmentsByEvent, eventID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []EventAttachment{}
|
||||
for rows.Next() {
|
||||
var i EventAttachment
|
||||
if err := rows.Scan(&i.ID, &i.EventID, &i.FileUrl); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
135
internal/repository/attendees.sql.go
Normal file
135
internal/repository/attendees.sql.go
Normal file
@@ -0,0 +1,135 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: attendees.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createAttendee = `-- name: CreateAttendee :one
|
||||
INSERT INTO event_attendees (id, event_id, user_id, email, status)
|
||||
VALUES ($1, $2, $3, $4, 'pending')
|
||||
RETURNING id, event_id, user_id, email, status
|
||||
`
|
||||
|
||||
type CreateAttendeeParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
EventID pgtype.UUID `json:"event_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Email pgtype.Text `json:"email"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateAttendee(ctx context.Context, arg CreateAttendeeParams) (EventAttendee, error) {
|
||||
row := q.db.QueryRow(ctx, createAttendee,
|
||||
arg.ID,
|
||||
arg.EventID,
|
||||
arg.UserID,
|
||||
arg.Email,
|
||||
)
|
||||
var i EventAttendee
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.EventID,
|
||||
&i.UserID,
|
||||
&i.Email,
|
||||
&i.Status,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteAttendee = `-- name: DeleteAttendee :exec
|
||||
DELETE FROM event_attendees
|
||||
WHERE id = $1 AND event_id = $2
|
||||
`
|
||||
|
||||
type DeleteAttendeeParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
EventID pgtype.UUID `json:"event_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteAttendee(ctx context.Context, arg DeleteAttendeeParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteAttendee, arg.ID, arg.EventID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getAttendeeByID = `-- name: GetAttendeeByID :one
|
||||
SELECT id, event_id, user_id, email, status
|
||||
FROM event_attendees
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetAttendeeByID(ctx context.Context, id pgtype.UUID) (EventAttendee, error) {
|
||||
row := q.db.QueryRow(ctx, getAttendeeByID, id)
|
||||
var i EventAttendee
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.EventID,
|
||||
&i.UserID,
|
||||
&i.Email,
|
||||
&i.Status,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listAttendeesByEvent = `-- name: ListAttendeesByEvent :many
|
||||
SELECT id, event_id, user_id, email, status
|
||||
FROM event_attendees
|
||||
WHERE event_id = $1
|
||||
ORDER BY id ASC
|
||||
`
|
||||
|
||||
func (q *Queries) ListAttendeesByEvent(ctx context.Context, eventID pgtype.UUID) ([]EventAttendee, error) {
|
||||
rows, err := q.db.Query(ctx, listAttendeesByEvent, eventID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []EventAttendee{}
|
||||
for rows.Next() {
|
||||
var i EventAttendee
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.EventID,
|
||||
&i.UserID,
|
||||
&i.Email,
|
||||
&i.Status,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateAttendeeStatus = `-- name: UpdateAttendeeStatus :one
|
||||
UPDATE event_attendees
|
||||
SET status = $2
|
||||
WHERE id = $1
|
||||
RETURNING id, event_id, user_id, email, status
|
||||
`
|
||||
|
||||
type UpdateAttendeeStatusParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateAttendeeStatus(ctx context.Context, arg UpdateAttendeeStatusParams) (EventAttendee, error) {
|
||||
row := q.db.QueryRow(ctx, updateAttendeeStatus, arg.ID, arg.Status)
|
||||
var i EventAttendee
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.EventID,
|
||||
&i.UserID,
|
||||
&i.Email,
|
||||
&i.Status,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
34
internal/repository/audit_logs.sql.go
Normal file
34
internal/repository/audit_logs.sql.go
Normal file
@@ -0,0 +1,34 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: audit_logs.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createAuditLog = `-- name: CreateAuditLog :exec
|
||||
INSERT INTO audit_logs (entity_type, entity_id, action, user_id)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
`
|
||||
|
||||
type CreateAuditLogParams struct {
|
||||
EntityType string `json:"entity_type"`
|
||||
EntityID pgtype.UUID `json:"entity_id"`
|
||||
Action string `json:"action"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateAuditLog(ctx context.Context, arg CreateAuditLogParams) error {
|
||||
_, err := q.db.Exec(ctx, createAuditLog,
|
||||
arg.EntityType,
|
||||
arg.EntityID,
|
||||
arg.Action,
|
||||
arg.UserID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
148
internal/repository/booking_links.sql.go
Normal file
148
internal/repository/booking_links.sql.go
Normal file
@@ -0,0 +1,148 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: booking_links.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createBookingLink = `-- name: CreateBookingLink :one
|
||||
INSERT INTO booking_links (id, calendar_id, token, duration_minutes, buffer_minutes, timezone, working_hours, active)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
RETURNING id, calendar_id, token, duration_minutes, buffer_minutes, timezone, working_hours, active, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateBookingLinkParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
Token string `json:"token"`
|
||||
DurationMinutes int32 `json:"duration_minutes"`
|
||||
BufferMinutes int32 `json:"buffer_minutes"`
|
||||
Timezone string `json:"timezone"`
|
||||
WorkingHours []byte `json:"working_hours"`
|
||||
Active bool `json:"active"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateBookingLink(ctx context.Context, arg CreateBookingLinkParams) (BookingLink, error) {
|
||||
row := q.db.QueryRow(ctx, createBookingLink,
|
||||
arg.ID,
|
||||
arg.CalendarID,
|
||||
arg.Token,
|
||||
arg.DurationMinutes,
|
||||
arg.BufferMinutes,
|
||||
arg.Timezone,
|
||||
arg.WorkingHours,
|
||||
arg.Active,
|
||||
)
|
||||
var i BookingLink
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CalendarID,
|
||||
&i.Token,
|
||||
&i.DurationMinutes,
|
||||
&i.BufferMinutes,
|
||||
&i.Timezone,
|
||||
&i.WorkingHours,
|
||||
&i.Active,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getBookingLinkByCalendar = `-- name: GetBookingLinkByCalendar :one
|
||||
SELECT id, calendar_id, token, duration_minutes, buffer_minutes, timezone, working_hours, active, created_at, updated_at FROM booking_links
|
||||
WHERE calendar_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetBookingLinkByCalendar(ctx context.Context, calendarID pgtype.UUID) (BookingLink, error) {
|
||||
row := q.db.QueryRow(ctx, getBookingLinkByCalendar, calendarID)
|
||||
var i BookingLink
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CalendarID,
|
||||
&i.Token,
|
||||
&i.DurationMinutes,
|
||||
&i.BufferMinutes,
|
||||
&i.Timezone,
|
||||
&i.WorkingHours,
|
||||
&i.Active,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getBookingLinkByToken = `-- name: GetBookingLinkByToken :one
|
||||
SELECT id, calendar_id, token, duration_minutes, buffer_minutes, timezone, working_hours, active, created_at, updated_at FROM booking_links
|
||||
WHERE token = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetBookingLinkByToken(ctx context.Context, token string) (BookingLink, error) {
|
||||
row := q.db.QueryRow(ctx, getBookingLinkByToken, token)
|
||||
var i BookingLink
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CalendarID,
|
||||
&i.Token,
|
||||
&i.DurationMinutes,
|
||||
&i.BufferMinutes,
|
||||
&i.Timezone,
|
||||
&i.WorkingHours,
|
||||
&i.Active,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateBookingLink = `-- name: UpdateBookingLink :one
|
||||
UPDATE booking_links
|
||||
SET duration_minutes = COALESCE($2, duration_minutes),
|
||||
buffer_minutes = COALESCE($3, buffer_minutes),
|
||||
timezone = COALESCE($4, timezone),
|
||||
working_hours = COALESCE($5, working_hours),
|
||||
active = COALESCE($6, active),
|
||||
updated_at = now()
|
||||
WHERE id = $1
|
||||
RETURNING id, calendar_id, token, duration_minutes, buffer_minutes, timezone, working_hours, active, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateBookingLinkParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
DurationMinutes int32 `json:"duration_minutes"`
|
||||
BufferMinutes int32 `json:"buffer_minutes"`
|
||||
Timezone string `json:"timezone"`
|
||||
WorkingHours []byte `json:"working_hours"`
|
||||
Active bool `json:"active"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateBookingLink(ctx context.Context, arg UpdateBookingLinkParams) (BookingLink, error) {
|
||||
row := q.db.QueryRow(ctx, updateBookingLink,
|
||||
arg.ID,
|
||||
arg.DurationMinutes,
|
||||
arg.BufferMinutes,
|
||||
arg.Timezone,
|
||||
arg.WorkingHours,
|
||||
arg.Active,
|
||||
)
|
||||
var i BookingLink
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CalendarID,
|
||||
&i.Token,
|
||||
&i.DurationMinutes,
|
||||
&i.BufferMinutes,
|
||||
&i.Timezone,
|
||||
&i.WorkingHours,
|
||||
&i.Active,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
105
internal/repository/calendar_members.sql.go
Normal file
105
internal/repository/calendar_members.sql.go
Normal file
@@ -0,0 +1,105 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: calendar_members.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const deleteAllCalendarMembers = `-- name: DeleteAllCalendarMembers :exec
|
||||
DELETE FROM calendar_members
|
||||
WHERE calendar_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteAllCalendarMembers(ctx context.Context, calendarID pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteAllCalendarMembers, calendarID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteCalendarMember = `-- name: DeleteCalendarMember :exec
|
||||
DELETE FROM calendar_members
|
||||
WHERE calendar_id = $1 AND user_id = $2
|
||||
`
|
||||
|
||||
type DeleteCalendarMemberParams struct {
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteCalendarMember(ctx context.Context, arg DeleteCalendarMemberParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteCalendarMember, arg.CalendarID, arg.UserID)
|
||||
return err
|
||||
}
|
||||
|
||||
const getCalendarMemberRole = `-- name: GetCalendarMemberRole :one
|
||||
SELECT role FROM calendar_members
|
||||
WHERE calendar_id = $1 AND user_id = $2
|
||||
`
|
||||
|
||||
type GetCalendarMemberRoleParams struct {
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetCalendarMemberRole(ctx context.Context, arg GetCalendarMemberRoleParams) (string, error) {
|
||||
row := q.db.QueryRow(ctx, getCalendarMemberRole, arg.CalendarID, arg.UserID)
|
||||
var role string
|
||||
err := row.Scan(&role)
|
||||
return role, err
|
||||
}
|
||||
|
||||
const listCalendarMembers = `-- name: ListCalendarMembers :many
|
||||
SELECT cm.user_id, u.email, cm.role
|
||||
FROM calendar_members cm
|
||||
JOIN users u ON u.id = cm.user_id
|
||||
WHERE cm.calendar_id = $1 AND u.deleted_at IS NULL
|
||||
ORDER BY cm.role ASC
|
||||
`
|
||||
|
||||
type ListCalendarMembersRow struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Email string `json:"email"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListCalendarMembers(ctx context.Context, calendarID pgtype.UUID) ([]ListCalendarMembersRow, error) {
|
||||
rows, err := q.db.Query(ctx, listCalendarMembers, calendarID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListCalendarMembersRow{}
|
||||
for rows.Next() {
|
||||
var i ListCalendarMembersRow
|
||||
if err := rows.Scan(&i.UserID, &i.Email, &i.Role); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const upsertCalendarMember = `-- name: UpsertCalendarMember :exec
|
||||
INSERT INTO calendar_members (calendar_id, user_id, role)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (calendar_id, user_id) DO UPDATE SET role = $3
|
||||
`
|
||||
|
||||
type UpsertCalendarMemberParams struct {
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertCalendarMember(ctx context.Context, arg UpsertCalendarMemberParams) error {
|
||||
_, err := q.db.Exec(ctx, upsertCalendarMember, arg.CalendarID, arg.UserID, arg.Role)
|
||||
return err
|
||||
}
|
||||
209
internal/repository/calendars.sql.go
Normal file
209
internal/repository/calendars.sql.go
Normal file
@@ -0,0 +1,209 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: calendars.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
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
|
||||
`
|
||||
|
||||
type CreateCalendarParams 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"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateCalendar(ctx context.Context, arg CreateCalendarParams) (CreateCalendarRow, error) {
|
||||
row := q.db.QueryRow(ctx, createCalendar,
|
||||
arg.ID,
|
||||
arg.OwnerID,
|
||||
arg.Name,
|
||||
arg.Color,
|
||||
arg.IsPublic,
|
||||
)
|
||||
var i CreateCalendarRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.Name,
|
||||
&i.Color,
|
||||
&i.IsPublic,
|
||||
&i.PublicToken,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getCalendarByID = `-- name: GetCalendarByID :one
|
||||
SELECT id, owner_id, name, color, is_public, public_token, 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"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetCalendarByID(ctx context.Context, id pgtype.UUID) (GetCalendarByIDRow, error) {
|
||||
row := q.db.QueryRow(ctx, getCalendarByID, id)
|
||||
var i GetCalendarByIDRow
|
||||
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
|
||||
JOIN calendar_members cm ON cm.calendar_id = c.id
|
||||
WHERE cm.user_id = $1 AND c.deleted_at IS NULL
|
||||
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"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListCalendarsByUser(ctx context.Context, userID pgtype.UUID) ([]ListCalendarsByUserRow, error) {
|
||||
rows, err := q.db.Query(ctx, listCalendarsByUser, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []ListCalendarsByUserRow{}
|
||||
for rows.Next() {
|
||||
var i ListCalendarsByUserRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.Name,
|
||||
&i.Color,
|
||||
&i.IsPublic,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Role,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const softDeleteCalendar = `-- name: SoftDeleteCalendar :exec
|
||||
UPDATE calendars SET deleted_at = now(), updated_at = now()
|
||||
WHERE id = $1 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) SoftDeleteCalendar(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, softDeleteCalendar, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const softDeleteCalendarsByOwner = `-- name: SoftDeleteCalendarsByOwner :exec
|
||||
UPDATE calendars SET deleted_at = now(), updated_at = now()
|
||||
WHERE owner_id = $1 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) SoftDeleteCalendarsByOwner(ctx context.Context, ownerID pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, softDeleteCalendarsByOwner, ownerID)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateCalendar = `-- name: UpdateCalendar :one
|
||||
UPDATE calendars
|
||||
SET name = COALESCE($1::TEXT, name),
|
||||
color = COALESCE($2::TEXT, color),
|
||||
is_public = COALESCE($3::BOOLEAN, is_public),
|
||||
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
|
||||
`
|
||||
|
||||
type UpdateCalendarParams struct {
|
||||
Name pgtype.Text `json:"name"`
|
||||
Color pgtype.Text `json:"color"`
|
||||
IsPublic pgtype.Bool `json:"is_public"`
|
||||
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"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateCalendar(ctx context.Context, arg UpdateCalendarParams) (UpdateCalendarRow, error) {
|
||||
row := q.db.QueryRow(ctx, updateCalendar,
|
||||
arg.Name,
|
||||
arg.Color,
|
||||
arg.IsPublic,
|
||||
arg.ID,
|
||||
)
|
||||
var i UpdateCalendarRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.Name,
|
||||
&i.Color,
|
||||
&i.IsPublic,
|
||||
&i.PublicToken,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
228
internal/repository/contacts.sql.go
Normal file
228
internal/repository/contacts.sql.go
Normal file
@@ -0,0 +1,228 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: contacts.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createContact = `-- name: CreateContact :one
|
||||
INSERT INTO contacts (id, owner_id, first_name, last_name, email, phone, company, notes)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
RETURNING id, owner_id, first_name, last_name, email, phone, company, notes, created_at, updated_at, deleted_at
|
||||
`
|
||||
|
||||
type CreateContactParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
FirstName pgtype.Text `json:"first_name"`
|
||||
LastName pgtype.Text `json:"last_name"`
|
||||
Email pgtype.Text `json:"email"`
|
||||
Phone pgtype.Text `json:"phone"`
|
||||
Company pgtype.Text `json:"company"`
|
||||
Notes pgtype.Text `json:"notes"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateContact(ctx context.Context, arg CreateContactParams) (Contact, error) {
|
||||
row := q.db.QueryRow(ctx, createContact,
|
||||
arg.ID,
|
||||
arg.OwnerID,
|
||||
arg.FirstName,
|
||||
arg.LastName,
|
||||
arg.Email,
|
||||
arg.Phone,
|
||||
arg.Company,
|
||||
arg.Notes,
|
||||
)
|
||||
var i Contact
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.Email,
|
||||
&i.Phone,
|
||||
&i.Company,
|
||||
&i.Notes,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getContactByID = `-- name: GetContactByID :one
|
||||
SELECT id, owner_id, first_name, last_name, email, phone, company, notes, created_at, updated_at, deleted_at FROM contacts
|
||||
WHERE id = $1 AND owner_id = $2 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type GetContactByIDParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetContactByID(ctx context.Context, arg GetContactByIDParams) (Contact, error) {
|
||||
row := q.db.QueryRow(ctx, getContactByID, arg.ID, arg.OwnerID)
|
||||
var i Contact
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.Email,
|
||||
&i.Phone,
|
||||
&i.Company,
|
||||
&i.Notes,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listContacts = `-- name: ListContacts :many
|
||||
SELECT id, owner_id, first_name, last_name, email, phone, company, notes, created_at, updated_at, deleted_at FROM contacts
|
||||
WHERE owner_id = $1
|
||||
AND deleted_at IS NULL
|
||||
AND (
|
||||
$2::TEXT IS NULL
|
||||
OR first_name ILIKE '%' || $2::TEXT || '%'
|
||||
OR last_name ILIKE '%' || $2::TEXT || '%'
|
||||
OR email ILIKE '%' || $2::TEXT || '%'
|
||||
OR company ILIKE '%' || $2::TEXT || '%'
|
||||
)
|
||||
AND (
|
||||
$3::TIMESTAMPTZ IS NULL
|
||||
OR (created_at, id) > ($3::TIMESTAMPTZ, $4::UUID)
|
||||
)
|
||||
ORDER BY created_at ASC, id ASC
|
||||
LIMIT $5
|
||||
`
|
||||
|
||||
type ListContactsParams struct {
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
Search pgtype.Text `json:"search"`
|
||||
CursorTime pgtype.Timestamptz `json:"cursor_time"`
|
||||
CursorID pgtype.UUID `json:"cursor_id"`
|
||||
Lim int32 `json:"lim"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListContacts(ctx context.Context, arg ListContactsParams) ([]Contact, error) {
|
||||
rows, err := q.db.Query(ctx, listContacts,
|
||||
arg.OwnerID,
|
||||
arg.Search,
|
||||
arg.CursorTime,
|
||||
arg.CursorID,
|
||||
arg.Lim,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Contact{}
|
||||
for rows.Next() {
|
||||
var i Contact
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.Email,
|
||||
&i.Phone,
|
||||
&i.Company,
|
||||
&i.Notes,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const softDeleteContact = `-- name: SoftDeleteContact :exec
|
||||
UPDATE contacts SET deleted_at = now(), updated_at = now()
|
||||
WHERE id = $1 AND owner_id = $2 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
type SoftDeleteContactParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) SoftDeleteContact(ctx context.Context, arg SoftDeleteContactParams) error {
|
||||
_, err := q.db.Exec(ctx, softDeleteContact, arg.ID, arg.OwnerID)
|
||||
return err
|
||||
}
|
||||
|
||||
const softDeleteContactsByOwner = `-- name: SoftDeleteContactsByOwner :exec
|
||||
UPDATE contacts SET deleted_at = now(), updated_at = now()
|
||||
WHERE owner_id = $1 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) SoftDeleteContactsByOwner(ctx context.Context, ownerID pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, softDeleteContactsByOwner, ownerID)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateContact = `-- name: UpdateContact :one
|
||||
UPDATE contacts
|
||||
SET first_name = COALESCE($1, first_name),
|
||||
last_name = COALESCE($2, last_name),
|
||||
email = COALESCE($3, email),
|
||||
phone = COALESCE($4, phone),
|
||||
company = COALESCE($5, company),
|
||||
notes = COALESCE($6, notes),
|
||||
updated_at = now()
|
||||
WHERE id = $7 AND owner_id = $8 AND deleted_at IS NULL
|
||||
RETURNING id, owner_id, first_name, last_name, email, phone, company, notes, created_at, updated_at, deleted_at
|
||||
`
|
||||
|
||||
type UpdateContactParams struct {
|
||||
FirstName pgtype.Text `json:"first_name"`
|
||||
LastName pgtype.Text `json:"last_name"`
|
||||
Email pgtype.Text `json:"email"`
|
||||
Phone pgtype.Text `json:"phone"`
|
||||
Company pgtype.Text `json:"company"`
|
||||
Notes pgtype.Text `json:"notes"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateContact(ctx context.Context, arg UpdateContactParams) (Contact, error) {
|
||||
row := q.db.QueryRow(ctx, updateContact,
|
||||
arg.FirstName,
|
||||
arg.LastName,
|
||||
arg.Email,
|
||||
arg.Phone,
|
||||
arg.Company,
|
||||
arg.Notes,
|
||||
arg.ID,
|
||||
arg.OwnerID,
|
||||
)
|
||||
var i Contact
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.OwnerID,
|
||||
&i.FirstName,
|
||||
&i.LastName,
|
||||
&i.Email,
|
||||
&i.Phone,
|
||||
&i.Company,
|
||||
&i.Notes,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
32
internal/repository/db.go
Normal file
32
internal/repository/db.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
74
internal/repository/event_exceptions.sql.go
Normal file
74
internal/repository/event_exceptions.sql.go
Normal file
@@ -0,0 +1,74 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: event_exceptions.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createEventException = `-- name: CreateEventException :one
|
||||
INSERT INTO event_exceptions (id, event_id, exception_date, action)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, event_id, exception_date, action
|
||||
`
|
||||
|
||||
type CreateEventExceptionParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
EventID pgtype.UUID `json:"event_id"`
|
||||
ExceptionDate pgtype.Date `json:"exception_date"`
|
||||
Action string `json:"action"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateEventException(ctx context.Context, arg CreateEventExceptionParams) (EventException, error) {
|
||||
row := q.db.QueryRow(ctx, createEventException,
|
||||
arg.ID,
|
||||
arg.EventID,
|
||||
arg.ExceptionDate,
|
||||
arg.Action,
|
||||
)
|
||||
var i EventException
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.EventID,
|
||||
&i.ExceptionDate,
|
||||
&i.Action,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listExceptionsByEvent = `-- name: ListExceptionsByEvent :many
|
||||
SELECT id, event_id, exception_date, action
|
||||
FROM event_exceptions
|
||||
WHERE event_id = $1
|
||||
ORDER BY exception_date ASC
|
||||
`
|
||||
|
||||
func (q *Queries) ListExceptionsByEvent(ctx context.Context, eventID pgtype.UUID) ([]EventException, error) {
|
||||
rows, err := q.db.Query(ctx, listExceptionsByEvent, eventID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []EventException{}
|
||||
for rows.Next() {
|
||||
var i EventException
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.EventID,
|
||||
&i.ExceptionDate,
|
||||
&i.Action,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
479
internal/repository/events.sql.go
Normal file
479
internal/repository/events.sql.go
Normal file
@@ -0,0 +1,479 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: events.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const checkEventOverlap = `-- name: CheckEventOverlap :one
|
||||
SELECT EXISTS(
|
||||
SELECT 1 FROM events
|
||||
WHERE calendar_id = $1
|
||||
AND deleted_at IS NULL
|
||||
AND start_time < $3
|
||||
AND end_time > $2
|
||||
) AS overlap
|
||||
`
|
||||
|
||||
type CheckEventOverlapParams struct {
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
EndTime pgtype.Timestamptz `json:"end_time"`
|
||||
StartTime pgtype.Timestamptz `json:"start_time"`
|
||||
}
|
||||
|
||||
func (q *Queries) CheckEventOverlap(ctx context.Context, arg CheckEventOverlapParams) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, checkEventOverlap, arg.CalendarID, arg.EndTime, arg.StartTime)
|
||||
var overlap bool
|
||||
err := row.Scan(&overlap)
|
||||
return overlap, err
|
||||
}
|
||||
|
||||
const checkEventOverlapForUpdate = `-- name: CheckEventOverlapForUpdate :one
|
||||
SELECT EXISTS(
|
||||
SELECT 1 FROM events
|
||||
WHERE calendar_id = $1
|
||||
AND deleted_at IS NULL
|
||||
AND start_time < $3
|
||||
AND end_time > $2
|
||||
FOR UPDATE
|
||||
) AS overlap
|
||||
`
|
||||
|
||||
type CheckEventOverlapForUpdateParams struct {
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
EndTime pgtype.Timestamptz `json:"end_time"`
|
||||
StartTime pgtype.Timestamptz `json:"start_time"`
|
||||
}
|
||||
|
||||
func (q *Queries) CheckEventOverlapForUpdate(ctx context.Context, arg CheckEventOverlapForUpdateParams) (bool, error) {
|
||||
row := q.db.QueryRow(ctx, checkEventOverlapForUpdate, arg.CalendarID, arg.EndTime, arg.StartTime)
|
||||
var overlap bool
|
||||
err := row.Scan(&overlap)
|
||||
return overlap, err
|
||||
}
|
||||
|
||||
const createEvent = `-- name: CreateEvent :one
|
||||
INSERT INTO events (id, calendar_id, title, description, location, start_time, end_time, timezone, all_day, recurrence_rule, tags, created_by, updated_by)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
|
||||
RETURNING id, calendar_id, title, description, location, start_time, end_time, timezone, all_day, recurrence_rule, tags, created_by, updated_by, created_at, updated_at, deleted_at
|
||||
`
|
||||
|
||||
type CreateEventParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
Location pgtype.Text `json:"location"`
|
||||
StartTime pgtype.Timestamptz `json:"start_time"`
|
||||
EndTime pgtype.Timestamptz `json:"end_time"`
|
||||
Timezone string `json:"timezone"`
|
||||
AllDay bool `json:"all_day"`
|
||||
RecurrenceRule pgtype.Text `json:"recurrence_rule"`
|
||||
Tags []string `json:"tags"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
UpdatedBy pgtype.UUID `json:"updated_by"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateEvent(ctx context.Context, arg CreateEventParams) (Event, error) {
|
||||
row := q.db.QueryRow(ctx, createEvent,
|
||||
arg.ID,
|
||||
arg.CalendarID,
|
||||
arg.Title,
|
||||
arg.Description,
|
||||
arg.Location,
|
||||
arg.StartTime,
|
||||
arg.EndTime,
|
||||
arg.Timezone,
|
||||
arg.AllDay,
|
||||
arg.RecurrenceRule,
|
||||
arg.Tags,
|
||||
arg.CreatedBy,
|
||||
arg.UpdatedBy,
|
||||
)
|
||||
var i Event
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CalendarID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Location,
|
||||
&i.StartTime,
|
||||
&i.EndTime,
|
||||
&i.Timezone,
|
||||
&i.AllDay,
|
||||
&i.RecurrenceRule,
|
||||
&i.Tags,
|
||||
&i.CreatedBy,
|
||||
&i.UpdatedBy,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getEventByID = `-- name: GetEventByID :one
|
||||
SELECT id, calendar_id, title, description, location, start_time, end_time, timezone, all_day, recurrence_rule, tags, created_by, updated_by, created_at, updated_at, deleted_at FROM events
|
||||
WHERE id = $1 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) GetEventByID(ctx context.Context, id pgtype.UUID) (Event, error) {
|
||||
row := q.db.QueryRow(ctx, getEventByID, id)
|
||||
var i Event
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CalendarID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Location,
|
||||
&i.StartTime,
|
||||
&i.EndTime,
|
||||
&i.Timezone,
|
||||
&i.AllDay,
|
||||
&i.RecurrenceRule,
|
||||
&i.Tags,
|
||||
&i.CreatedBy,
|
||||
&i.UpdatedBy,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listEventsByCalendarInRange = `-- name: ListEventsByCalendarInRange :many
|
||||
SELECT id, calendar_id, title, description, location, start_time, end_time, timezone, all_day, recurrence_rule, tags, created_by, updated_by, created_at, updated_at, deleted_at FROM events
|
||||
WHERE calendar_id = $1
|
||||
AND deleted_at IS NULL
|
||||
AND start_time < $3
|
||||
AND end_time > $2
|
||||
ORDER BY start_time ASC
|
||||
`
|
||||
|
||||
type ListEventsByCalendarInRangeParams struct {
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
EndTime pgtype.Timestamptz `json:"end_time"`
|
||||
StartTime pgtype.Timestamptz `json:"start_time"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListEventsByCalendarInRange(ctx context.Context, arg ListEventsByCalendarInRangeParams) ([]Event, error) {
|
||||
rows, err := q.db.Query(ctx, listEventsByCalendarInRange, arg.CalendarID, arg.EndTime, arg.StartTime)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Event{}
|
||||
for rows.Next() {
|
||||
var i Event
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.CalendarID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Location,
|
||||
&i.StartTime,
|
||||
&i.EndTime,
|
||||
&i.Timezone,
|
||||
&i.AllDay,
|
||||
&i.RecurrenceRule,
|
||||
&i.Tags,
|
||||
&i.CreatedBy,
|
||||
&i.UpdatedBy,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listEventsInRange = `-- name: ListEventsInRange :many
|
||||
SELECT e.id, e.calendar_id, e.title, e.description, e.location, e.start_time, e.end_time, e.timezone, e.all_day, e.recurrence_rule, e.tags, e.created_by, e.updated_by, e.created_at, e.updated_at, e.deleted_at FROM events e
|
||||
JOIN calendar_members cm ON cm.calendar_id = e.calendar_id
|
||||
WHERE cm.user_id = $1
|
||||
AND e.deleted_at IS NULL
|
||||
AND e.start_time < $2
|
||||
AND e.end_time > $3
|
||||
AND ($4::UUID IS NULL OR e.calendar_id = $4::UUID)
|
||||
AND ($5::TEXT IS NULL OR (e.title ILIKE '%' || $5::TEXT || '%' OR e.description ILIKE '%' || $5::TEXT || '%'))
|
||||
AND ($6::TEXT IS NULL OR $6::TEXT = ANY(e.tags))
|
||||
AND (
|
||||
$7::TIMESTAMPTZ IS NULL
|
||||
OR (e.start_time, e.id) > ($7::TIMESTAMPTZ, $8::UUID)
|
||||
)
|
||||
ORDER BY e.start_time ASC, e.id ASC
|
||||
LIMIT $9
|
||||
`
|
||||
|
||||
type ListEventsInRangeParams struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
RangeEnd pgtype.Timestamptz `json:"range_end"`
|
||||
RangeStart pgtype.Timestamptz `json:"range_start"`
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
Search pgtype.Text `json:"search"`
|
||||
Tag pgtype.Text `json:"tag"`
|
||||
CursorTime pgtype.Timestamptz `json:"cursor_time"`
|
||||
CursorID pgtype.UUID `json:"cursor_id"`
|
||||
Lim int32 `json:"lim"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListEventsInRange(ctx context.Context, arg ListEventsInRangeParams) ([]Event, error) {
|
||||
rows, err := q.db.Query(ctx, listEventsInRange,
|
||||
arg.UserID,
|
||||
arg.RangeEnd,
|
||||
arg.RangeStart,
|
||||
arg.CalendarID,
|
||||
arg.Search,
|
||||
arg.Tag,
|
||||
arg.CursorTime,
|
||||
arg.CursorID,
|
||||
arg.Lim,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Event{}
|
||||
for rows.Next() {
|
||||
var i Event
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.CalendarID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Location,
|
||||
&i.StartTime,
|
||||
&i.EndTime,
|
||||
&i.Timezone,
|
||||
&i.AllDay,
|
||||
&i.RecurrenceRule,
|
||||
&i.Tags,
|
||||
&i.CreatedBy,
|
||||
&i.UpdatedBy,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listRecurringEventsByCalendar = `-- name: ListRecurringEventsByCalendar :many
|
||||
SELECT id, calendar_id, title, description, location, start_time, end_time, timezone, all_day, recurrence_rule, tags, created_by, updated_by, created_at, updated_at, deleted_at FROM events
|
||||
WHERE calendar_id = $1
|
||||
AND deleted_at IS NULL
|
||||
AND recurrence_rule IS NOT NULL
|
||||
AND start_time <= $2
|
||||
ORDER BY start_time ASC
|
||||
`
|
||||
|
||||
type ListRecurringEventsByCalendarParams struct {
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
StartTime pgtype.Timestamptz `json:"start_time"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListRecurringEventsByCalendar(ctx context.Context, arg ListRecurringEventsByCalendarParams) ([]Event, error) {
|
||||
rows, err := q.db.Query(ctx, listRecurringEventsByCalendar, arg.CalendarID, arg.StartTime)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Event{}
|
||||
for rows.Next() {
|
||||
var i Event
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.CalendarID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Location,
|
||||
&i.StartTime,
|
||||
&i.EndTime,
|
||||
&i.Timezone,
|
||||
&i.AllDay,
|
||||
&i.RecurrenceRule,
|
||||
&i.Tags,
|
||||
&i.CreatedBy,
|
||||
&i.UpdatedBy,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listRecurringEventsInRange = `-- name: ListRecurringEventsInRange :many
|
||||
SELECT e.id, e.calendar_id, e.title, e.description, e.location, e.start_time, e.end_time, e.timezone, e.all_day, e.recurrence_rule, e.tags, e.created_by, e.updated_by, e.created_at, e.updated_at, e.deleted_at FROM events e
|
||||
JOIN calendar_members cm ON cm.calendar_id = e.calendar_id
|
||||
WHERE cm.user_id = $1
|
||||
AND e.deleted_at IS NULL
|
||||
AND e.recurrence_rule IS NOT NULL
|
||||
AND e.start_time <= $2
|
||||
AND ($3::UUID IS NULL OR e.calendar_id = $3::UUID)
|
||||
ORDER BY e.start_time ASC
|
||||
`
|
||||
|
||||
type ListRecurringEventsInRangeParams struct {
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
RangeEnd pgtype.Timestamptz `json:"range_end"`
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListRecurringEventsInRange(ctx context.Context, arg ListRecurringEventsInRangeParams) ([]Event, error) {
|
||||
rows, err := q.db.Query(ctx, listRecurringEventsInRange, arg.UserID, arg.RangeEnd, arg.CalendarID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []Event{}
|
||||
for rows.Next() {
|
||||
var i Event
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.CalendarID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Location,
|
||||
&i.StartTime,
|
||||
&i.EndTime,
|
||||
&i.Timezone,
|
||||
&i.AllDay,
|
||||
&i.RecurrenceRule,
|
||||
&i.Tags,
|
||||
&i.CreatedBy,
|
||||
&i.UpdatedBy,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const softDeleteEvent = `-- name: SoftDeleteEvent :exec
|
||||
UPDATE events SET deleted_at = now(), updated_at = now()
|
||||
WHERE id = $1 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) SoftDeleteEvent(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, softDeleteEvent, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const softDeleteEventsByCalendar = `-- name: SoftDeleteEventsByCalendar :exec
|
||||
UPDATE events SET deleted_at = now(), updated_at = now()
|
||||
WHERE calendar_id = $1 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) SoftDeleteEventsByCalendar(ctx context.Context, calendarID pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, softDeleteEventsByCalendar, calendarID)
|
||||
return err
|
||||
}
|
||||
|
||||
const softDeleteEventsByCreator = `-- name: SoftDeleteEventsByCreator :exec
|
||||
UPDATE events SET deleted_at = now(), updated_at = now()
|
||||
WHERE created_by = $1 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) SoftDeleteEventsByCreator(ctx context.Context, createdBy pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, softDeleteEventsByCreator, createdBy)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateEvent = `-- name: UpdateEvent :one
|
||||
UPDATE events
|
||||
SET title = COALESCE($1, title),
|
||||
description = COALESCE($2, description),
|
||||
location = COALESCE($3, location),
|
||||
start_time = COALESCE($4, start_time),
|
||||
end_time = COALESCE($5, end_time),
|
||||
timezone = COALESCE($6, timezone),
|
||||
all_day = COALESCE($7, all_day),
|
||||
recurrence_rule = $8,
|
||||
tags = COALESCE($9, tags),
|
||||
updated_by = $10,
|
||||
updated_at = now()
|
||||
WHERE id = $11 AND deleted_at IS NULL
|
||||
RETURNING id, calendar_id, title, description, location, start_time, end_time, timezone, all_day, recurrence_rule, tags, created_by, updated_by, created_at, updated_at, deleted_at
|
||||
`
|
||||
|
||||
type UpdateEventParams struct {
|
||||
Title pgtype.Text `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
Location pgtype.Text `json:"location"`
|
||||
StartTime pgtype.Timestamptz `json:"start_time"`
|
||||
EndTime pgtype.Timestamptz `json:"end_time"`
|
||||
Timezone pgtype.Text `json:"timezone"`
|
||||
AllDay pgtype.Bool `json:"all_day"`
|
||||
RecurrenceRule pgtype.Text `json:"recurrence_rule"`
|
||||
Tags []string `json:"tags"`
|
||||
UpdatedBy pgtype.UUID `json:"updated_by"`
|
||||
ID pgtype.UUID `json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateEvent(ctx context.Context, arg UpdateEventParams) (Event, error) {
|
||||
row := q.db.QueryRow(ctx, updateEvent,
|
||||
arg.Title,
|
||||
arg.Description,
|
||||
arg.Location,
|
||||
arg.StartTime,
|
||||
arg.EndTime,
|
||||
arg.Timezone,
|
||||
arg.AllDay,
|
||||
arg.RecurrenceRule,
|
||||
arg.Tags,
|
||||
arg.UpdatedBy,
|
||||
arg.ID,
|
||||
)
|
||||
var i Event
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CalendarID,
|
||||
&i.Title,
|
||||
&i.Description,
|
||||
&i.Location,
|
||||
&i.StartTime,
|
||||
&i.EndTime,
|
||||
&i.Timezone,
|
||||
&i.AllDay,
|
||||
&i.RecurrenceRule,
|
||||
&i.Tags,
|
||||
&i.CreatedBy,
|
||||
&i.UpdatedBy,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.DeletedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
139
internal/repository/models.go
Normal file
139
internal/repository/models.go
Normal file
@@ -0,0 +1,139 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type ApiKey struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Name string `json:"name"`
|
||||
KeyHash string `json:"key_hash"`
|
||||
Scopes []byte `json:"scopes"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
RevokedAt pgtype.Timestamptz `json:"revoked_at"`
|
||||
}
|
||||
|
||||
type AuditLog struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
EntityType string `json:"entity_type"`
|
||||
EntityID pgtype.UUID `json:"entity_id"`
|
||||
Action string `json:"action"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
type BookingLink struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
Token string `json:"token"`
|
||||
DurationMinutes int32 `json:"duration_minutes"`
|
||||
BufferMinutes int32 `json:"buffer_minutes"`
|
||||
Timezone string `json:"timezone"`
|
||||
WorkingHours []byte `json:"working_hours"`
|
||||
Active bool `json:"active"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
type CalendarMember struct {
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Role string `json:"role"`
|
||||
}
|
||||
|
||||
type Contact struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
OwnerID pgtype.UUID `json:"owner_id"`
|
||||
FirstName pgtype.Text `json:"first_name"`
|
||||
LastName pgtype.Text `json:"last_name"`
|
||||
Email pgtype.Text `json:"email"`
|
||||
Phone pgtype.Text `json:"phone"`
|
||||
Company pgtype.Text `json:"company"`
|
||||
Notes pgtype.Text `json:"notes"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
DeletedAt pgtype.Timestamptz `json:"deleted_at"`
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
CalendarID pgtype.UUID `json:"calendar_id"`
|
||||
Title string `json:"title"`
|
||||
Description pgtype.Text `json:"description"`
|
||||
Location pgtype.Text `json:"location"`
|
||||
StartTime pgtype.Timestamptz `json:"start_time"`
|
||||
EndTime pgtype.Timestamptz `json:"end_time"`
|
||||
Timezone string `json:"timezone"`
|
||||
AllDay bool `json:"all_day"`
|
||||
RecurrenceRule pgtype.Text `json:"recurrence_rule"`
|
||||
Tags []string `json:"tags"`
|
||||
CreatedBy pgtype.UUID `json:"created_by"`
|
||||
UpdatedBy pgtype.UUID `json:"updated_by"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
DeletedAt pgtype.Timestamptz `json:"deleted_at"`
|
||||
}
|
||||
|
||||
type EventAttachment struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
EventID pgtype.UUID `json:"event_id"`
|
||||
FileUrl string `json:"file_url"`
|
||||
}
|
||||
|
||||
type EventAttendee struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
EventID pgtype.UUID `json:"event_id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
Email pgtype.Text `json:"email"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type EventException struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
EventID pgtype.UUID `json:"event_id"`
|
||||
ExceptionDate pgtype.Date `json:"exception_date"`
|
||||
Action string `json:"action"`
|
||||
}
|
||||
|
||||
type EventReminder struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
EventID pgtype.UUID `json:"event_id"`
|
||||
MinutesBefore int32 `json:"minutes_before"`
|
||||
}
|
||||
|
||||
type RefreshToken struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
TokenHash string `json:"token_hash"`
|
||||
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
|
||||
RevokedAt pgtype.Timestamptz `json:"revoked_at"`
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
}
|
||||
|
||||
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"`
|
||||
}
|
||||
83
internal/repository/refresh_tokens.sql.go
Normal file
83
internal/repository/refresh_tokens.sql.go
Normal file
@@ -0,0 +1,83 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: refresh_tokens.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createRefreshToken = `-- name: CreateRefreshToken :one
|
||||
INSERT INTO refresh_tokens (id, user_id, token_hash, expires_at)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, user_id, token_hash, expires_at, revoked_at, created_at
|
||||
`
|
||||
|
||||
type CreateRefreshTokenParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
UserID pgtype.UUID `json:"user_id"`
|
||||
TokenHash string `json:"token_hash"`
|
||||
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateRefreshToken(ctx context.Context, arg CreateRefreshTokenParams) (RefreshToken, error) {
|
||||
row := q.db.QueryRow(ctx, createRefreshToken,
|
||||
arg.ID,
|
||||
arg.UserID,
|
||||
arg.TokenHash,
|
||||
arg.ExpiresAt,
|
||||
)
|
||||
var i RefreshToken
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.TokenHash,
|
||||
&i.ExpiresAt,
|
||||
&i.RevokedAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getRefreshTokenByHash = `-- name: GetRefreshTokenByHash :one
|
||||
SELECT id, user_id, token_hash, expires_at, revoked_at, created_at
|
||||
FROM refresh_tokens
|
||||
WHERE token_hash = $1 AND revoked_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) GetRefreshTokenByHash(ctx context.Context, tokenHash string) (RefreshToken, error) {
|
||||
row := q.db.QueryRow(ctx, getRefreshTokenByHash, tokenHash)
|
||||
var i RefreshToken
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.TokenHash,
|
||||
&i.ExpiresAt,
|
||||
&i.RevokedAt,
|
||||
&i.CreatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const revokeAllUserRefreshTokens = `-- name: RevokeAllUserRefreshTokens :exec
|
||||
UPDATE refresh_tokens SET revoked_at = now()
|
||||
WHERE user_id = $1 AND revoked_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) RevokeAllUserRefreshTokens(ctx context.Context, userID pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, revokeAllUserRefreshTokens, userID)
|
||||
return err
|
||||
}
|
||||
|
||||
const revokeRefreshToken = `-- name: RevokeRefreshToken :exec
|
||||
UPDATE refresh_tokens SET revoked_at = now() WHERE token_hash = $1
|
||||
`
|
||||
|
||||
func (q *Queries) RevokeRefreshToken(ctx context.Context, tokenHash string) error {
|
||||
_, err := q.db.Exec(ctx, revokeRefreshToken, tokenHash)
|
||||
return err
|
||||
}
|
||||
83
internal/repository/reminders.sql.go
Normal file
83
internal/repository/reminders.sql.go
Normal file
@@ -0,0 +1,83 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: reminders.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createReminder = `-- name: CreateReminder :one
|
||||
INSERT INTO event_reminders (id, event_id, minutes_before)
|
||||
VALUES ($1, $2, $3)
|
||||
RETURNING id, event_id, minutes_before
|
||||
`
|
||||
|
||||
type CreateReminderParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
EventID pgtype.UUID `json:"event_id"`
|
||||
MinutesBefore int32 `json:"minutes_before"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateReminder(ctx context.Context, arg CreateReminderParams) (EventReminder, error) {
|
||||
row := q.db.QueryRow(ctx, createReminder, arg.ID, arg.EventID, arg.MinutesBefore)
|
||||
var i EventReminder
|
||||
err := row.Scan(&i.ID, &i.EventID, &i.MinutesBefore)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteReminder = `-- name: DeleteReminder :exec
|
||||
DELETE FROM event_reminders
|
||||
WHERE id = $1 AND event_id = $2
|
||||
`
|
||||
|
||||
type DeleteReminderParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
EventID pgtype.UUID `json:"event_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) DeleteReminder(ctx context.Context, arg DeleteReminderParams) error {
|
||||
_, err := q.db.Exec(ctx, deleteReminder, arg.ID, arg.EventID)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteRemindersByEvent = `-- name: DeleteRemindersByEvent :exec
|
||||
DELETE FROM event_reminders
|
||||
WHERE event_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteRemindersByEvent(ctx context.Context, eventID pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteRemindersByEvent, eventID)
|
||||
return err
|
||||
}
|
||||
|
||||
const listRemindersByEvent = `-- name: ListRemindersByEvent :many
|
||||
SELECT id, event_id, minutes_before
|
||||
FROM event_reminders
|
||||
WHERE event_id = $1
|
||||
ORDER BY minutes_before ASC
|
||||
`
|
||||
|
||||
func (q *Queries) ListRemindersByEvent(ctx context.Context, eventID pgtype.UUID) ([]EventReminder, error) {
|
||||
rows, err := q.db.Query(ctx, listRemindersByEvent, eventID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []EventReminder{}
|
||||
for rows.Next() {
|
||||
var i EventReminder
|
||||
if err := rows.Scan(&i.ID, &i.EventID, &i.MinutesBefore); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
165
internal/repository/users.sql.go
Normal file
165
internal/repository/users.sql.go
Normal file
@@ -0,0 +1,165 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: users.sql
|
||||
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createUser = `-- name: CreateUser :one
|
||||
INSERT INTO users (id, email, password_hash, timezone)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, email, password_hash, timezone, is_active, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateUserParams struct {
|
||||
ID pgtype.UUID `json:"id"`
|
||||
Email string `json:"email"`
|
||||
PasswordHash string `json:"password_hash"`
|
||||
Timezone string `json:"timezone"`
|
||||
}
|
||||
|
||||
type CreateUserRow 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"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateUserRow, error) {
|
||||
row := q.db.QueryRow(ctx, createUser,
|
||||
arg.ID,
|
||||
arg.Email,
|
||||
arg.PasswordHash,
|
||||
arg.Timezone,
|
||||
)
|
||||
var i CreateUserRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Email,
|
||||
&i.PasswordHash,
|
||||
&i.Timezone,
|
||||
&i.IsActive,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserByEmail = `-- name: GetUserByEmail :one
|
||||
SELECT id, email, password_hash, timezone, is_active, 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"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserByEmail(ctx context.Context, email string) (GetUserByEmailRow, error) {
|
||||
row := q.db.QueryRow(ctx, getUserByEmail, email)
|
||||
var i GetUserByEmailRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Email,
|
||||
&i.PasswordHash,
|
||||
&i.Timezone,
|
||||
&i.IsActive,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserByID = `-- name: GetUserByID :one
|
||||
SELECT id, email, password_hash, timezone, is_active, 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"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserByID(ctx context.Context, id pgtype.UUID) (GetUserByIDRow, error) {
|
||||
row := q.db.QueryRow(ctx, getUserByID, id)
|
||||
var i GetUserByIDRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Email,
|
||||
&i.PasswordHash,
|
||||
&i.Timezone,
|
||||
&i.IsActive,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const softDeleteUser = `-- name: SoftDeleteUser :exec
|
||||
UPDATE users SET deleted_at = now(), is_active = false, updated_at = now()
|
||||
WHERE id = $1 AND deleted_at IS NULL
|
||||
`
|
||||
|
||||
func (q *Queries) SoftDeleteUser(ctx context.Context, id pgtype.UUID) error {
|
||||
_, err := q.db.Exec(ctx, softDeleteUser, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateUser = `-- name: UpdateUser :one
|
||||
UPDATE users
|
||||
SET timezone = COALESCE($1::TEXT, timezone),
|
||||
updated_at = now()
|
||||
WHERE id = $2 AND deleted_at IS NULL
|
||||
RETURNING id, email, password_hash, timezone, is_active, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateUserParams struct {
|
||||
Timezone pgtype.Text `json:"timezone"`
|
||||
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"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (UpdateUserRow, error) {
|
||||
row := q.db.QueryRow(ctx, updateUser, arg.Timezone, arg.ID)
|
||||
var i UpdateUserRow
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Email,
|
||||
&i.PasswordHash,
|
||||
&i.Timezone,
|
||||
&i.IsActive,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
Reference in New Issue
Block a user