first commit
Made-with: Cursor
This commit is contained in:
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
|
||||
}
|
||||
Reference in New Issue
Block a user