RezinaLMS-BackEnd/gen/db/notification.sql.go

524 lines
13 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: notification.sql
package dbgen
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const CountUnreadNotifications = `-- name: CountUnreadNotifications :one
SELECT COUNT(*)
FROM notifications
WHERE user_id = $1
AND receiver_type = $2
AND is_read = FALSE
`
type CountUnreadNotificationsParams struct {
UserID int64 `json:"user_id"`
ReceiverType string `json:"receiver_type"`
}
func (q *Queries) CountUnreadNotifications(ctx context.Context, arg CountUnreadNotificationsParams) (int64, error) {
row := q.db.QueryRow(ctx, CountUnreadNotifications, arg.UserID, arg.ReceiverType)
var count int64
err := row.Scan(&count)
return count, err
}
const CreateNotification = `-- name: CreateNotification :one
INSERT INTO notifications (
user_id,
receiver_type,
type,
level,
channel,
title,
message,
payload
)
VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7,
$8
)
RETURNING id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type
`
type CreateNotificationParams struct {
UserID int64 `json:"user_id"`
ReceiverType string `json:"receiver_type"`
Type string `json:"type"`
Level string `json:"level"`
Channel pgtype.Text `json:"channel"`
Title string `json:"title"`
Message string `json:"message"`
Payload []byte `json:"payload"`
}
func (q *Queries) CreateNotification(ctx context.Context, arg CreateNotificationParams) (Notification, error) {
row := q.db.QueryRow(ctx, CreateNotification,
arg.UserID,
arg.ReceiverType,
arg.Type,
arg.Level,
arg.Channel,
arg.Title,
arg.Message,
arg.Payload,
)
var i Notification
err := row.Scan(
&i.ID,
&i.UserID,
&i.Type,
&i.Level,
&i.Channel,
&i.Title,
&i.Message,
&i.Payload,
&i.IsRead,
&i.CreatedAt,
&i.ReadAt,
&i.ReceiverType,
)
return i, err
}
const DeleteUserInAppNotification = `-- name: DeleteUserInAppNotification :execrows
DELETE FROM notifications
WHERE id = $1
AND receiver_type = $3
AND user_id = $2
AND channel = 'in_app'
`
type DeleteUserInAppNotificationParams struct {
ID int64 `json:"id"`
UserID int64 `json:"user_id"`
ReceiverType string `json:"receiver_type"`
}
func (q *Queries) DeleteUserInAppNotification(ctx context.Context, arg DeleteUserInAppNotificationParams) (int64, error) {
result, err := q.db.Exec(ctx, DeleteUserInAppNotification, arg.ID, arg.UserID, arg.ReceiverType)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const DeleteUserInAppNotificationsByIDs = `-- name: DeleteUserInAppNotificationsByIDs :execrows
DELETE FROM notifications
WHERE user_id = $1
AND receiver_type = $3
AND channel = 'in_app'
AND id = ANY($2::BIGINT[])
`
type DeleteUserInAppNotificationsByIDsParams struct {
UserID int64 `json:"user_id"`
Column2 []int64 `json:"column_2"`
ReceiverType string `json:"receiver_type"`
}
func (q *Queries) DeleteUserInAppNotificationsByIDs(ctx context.Context, arg DeleteUserInAppNotificationsByIDsParams) (int64, error) {
result, err := q.db.Exec(ctx, DeleteUserInAppNotificationsByIDs, arg.UserID, arg.Column2, arg.ReceiverType)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const DeleteUserNotifications = `-- name: DeleteUserNotifications :exec
DELETE FROM notifications
WHERE user_id = $1
AND receiver_type = $2
`
type DeleteUserNotificationsParams struct {
UserID int64 `json:"user_id"`
ReceiverType string `json:"receiver_type"`
}
func (q *Queries) DeleteUserNotifications(ctx context.Context, arg DeleteUserNotificationsParams) error {
_, err := q.db.Exec(ctx, DeleteUserNotifications, arg.UserID, arg.ReceiverType)
return err
}
const GetAllNotifications = `-- name: GetAllNotifications :many
SELECT id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type
FROM notifications
ORDER BY created_at DESC
LIMIT $1 OFFSET $2
`
type GetAllNotificationsParams struct {
Limit int32 `json:"limit"`
Offset int32 `json:"offset"`
}
func (q *Queries) GetAllNotifications(ctx context.Context, arg GetAllNotificationsParams) ([]Notification, error) {
rows, err := q.db.Query(ctx, GetAllNotifications, arg.Limit, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Notification
for rows.Next() {
var i Notification
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.Type,
&i.Level,
&i.Channel,
&i.Title,
&i.Message,
&i.Payload,
&i.IsRead,
&i.CreatedAt,
&i.ReadAt,
&i.ReceiverType,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const GetFilteredNotificationCount = `-- name: GetFilteredNotificationCount :one
SELECT COUNT(*)
FROM notifications
WHERE
($1::text IS NULL OR channel = $1)
AND ($2::text IS NULL OR type = $2)
AND ($3::bigint IS NULL OR user_id = $3)
AND ($4::boolean IS NULL OR is_read = $4)
AND ($5::timestamptz IS NULL OR created_at >= $5)
AND ($6::timestamptz IS NULL OR created_at <= $6)
`
type GetFilteredNotificationCountParams struct {
FilterChannel pgtype.Text `json:"filter_channel"`
FilterType pgtype.Text `json:"filter_type"`
FilterUserID pgtype.Int8 `json:"filter_user_id"`
FilterIsRead pgtype.Bool `json:"filter_is_read"`
FilterAfter pgtype.Timestamptz `json:"filter_after"`
FilterBefore pgtype.Timestamptz `json:"filter_before"`
}
func (q *Queries) GetFilteredNotificationCount(ctx context.Context, arg GetFilteredNotificationCountParams) (int64, error) {
row := q.db.QueryRow(ctx, GetFilteredNotificationCount,
arg.FilterChannel,
arg.FilterType,
arg.FilterUserID,
arg.FilterIsRead,
arg.FilterAfter,
arg.FilterBefore,
)
var count int64
err := row.Scan(&count)
return count, err
}
const GetFilteredNotifications = `-- name: GetFilteredNotifications :many
SELECT id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type
FROM notifications
WHERE
($1::text IS NULL OR channel = $1)
AND ($2::text IS NULL OR type = $2)
AND ($3::bigint IS NULL OR user_id = $3)
AND ($4::boolean IS NULL OR is_read = $4)
AND ($5::timestamptz IS NULL OR created_at >= $5)
AND ($6::timestamptz IS NULL OR created_at <= $6)
ORDER BY created_at DESC
LIMIT $8 OFFSET $7
`
type GetFilteredNotificationsParams struct {
FilterChannel pgtype.Text `json:"filter_channel"`
FilterType pgtype.Text `json:"filter_type"`
FilterUserID pgtype.Int8 `json:"filter_user_id"`
FilterIsRead pgtype.Bool `json:"filter_is_read"`
FilterAfter pgtype.Timestamptz `json:"filter_after"`
FilterBefore pgtype.Timestamptz `json:"filter_before"`
PageOffset int32 `json:"page_offset"`
PageLimit int32 `json:"page_limit"`
}
func (q *Queries) GetFilteredNotifications(ctx context.Context, arg GetFilteredNotificationsParams) ([]Notification, error) {
rows, err := q.db.Query(ctx, GetFilteredNotifications,
arg.FilterChannel,
arg.FilterType,
arg.FilterUserID,
arg.FilterIsRead,
arg.FilterAfter,
arg.FilterBefore,
arg.PageOffset,
arg.PageLimit,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Notification
for rows.Next() {
var i Notification
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.Type,
&i.Level,
&i.Channel,
&i.Title,
&i.Message,
&i.Payload,
&i.IsRead,
&i.CreatedAt,
&i.ReadAt,
&i.ReceiverType,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const GetNotification = `-- name: GetNotification :one
SELECT id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type
FROM notifications
WHERE id = $1
LIMIT 1
`
func (q *Queries) GetNotification(ctx context.Context, id int64) (Notification, error) {
row := q.db.QueryRow(ctx, GetNotification, id)
var i Notification
err := row.Scan(
&i.ID,
&i.UserID,
&i.Type,
&i.Level,
&i.Channel,
&i.Title,
&i.Message,
&i.Payload,
&i.IsRead,
&i.CreatedAt,
&i.ReadAt,
&i.ReceiverType,
)
return i, err
}
const GetTotalNotificationCount = `-- name: GetTotalNotificationCount :one
SELECT COUNT(*)
FROM notifications
`
func (q *Queries) GetTotalNotificationCount(ctx context.Context) (int64, error) {
row := q.db.QueryRow(ctx, GetTotalNotificationCount)
var count int64
err := row.Scan(&count)
return count, err
}
const GetUserNotificationCount = `-- name: GetUserNotificationCount :one
SELECT COUNT(*)
FROM notifications
WHERE user_id = $1
AND receiver_type = $2
`
type GetUserNotificationCountParams struct {
UserID int64 `json:"user_id"`
ReceiverType string `json:"receiver_type"`
}
func (q *Queries) GetUserNotificationCount(ctx context.Context, arg GetUserNotificationCountParams) (int64, error) {
row := q.db.QueryRow(ctx, GetUserNotificationCount, arg.UserID, arg.ReceiverType)
var count int64
err := row.Scan(&count)
return count, err
}
const GetUserNotifications = `-- name: GetUserNotifications :many
SELECT id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type
FROM notifications
WHERE user_id = $1
AND receiver_type = $4
ORDER BY created_at DESC
LIMIT $2 OFFSET $3
`
type GetUserNotificationsParams struct {
UserID int64 `json:"user_id"`
Limit int32 `json:"limit"`
Offset int32 `json:"offset"`
ReceiverType string `json:"receiver_type"`
}
func (q *Queries) GetUserNotifications(ctx context.Context, arg GetUserNotificationsParams) ([]Notification, error) {
rows, err := q.db.Query(ctx, GetUserNotifications,
arg.UserID,
arg.Limit,
arg.Offset,
arg.ReceiverType,
)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Notification
for rows.Next() {
var i Notification
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.Type,
&i.Level,
&i.Channel,
&i.Title,
&i.Message,
&i.Payload,
&i.IsRead,
&i.CreatedAt,
&i.ReadAt,
&i.ReceiverType,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const MarkAllUserNotificationsAsRead = `-- name: MarkAllUserNotificationsAsRead :exec
UPDATE notifications
SET is_read = TRUE,
read_at = NOW()
WHERE user_id = $1
AND receiver_type = $2
AND is_read = FALSE
`
type MarkAllUserNotificationsAsReadParams struct {
UserID int64 `json:"user_id"`
ReceiverType string `json:"receiver_type"`
}
func (q *Queries) MarkAllUserNotificationsAsRead(ctx context.Context, arg MarkAllUserNotificationsAsReadParams) error {
_, err := q.db.Exec(ctx, MarkAllUserNotificationsAsRead, arg.UserID, arg.ReceiverType)
return err
}
const MarkAllUserNotificationsAsUnread = `-- name: MarkAllUserNotificationsAsUnread :exec
UPDATE notifications
SET is_read = FALSE,
read_at = NULL
WHERE user_id = $1
AND receiver_type = $2
AND is_read = TRUE
`
type MarkAllUserNotificationsAsUnreadParams struct {
UserID int64 `json:"user_id"`
ReceiverType string `json:"receiver_type"`
}
func (q *Queries) MarkAllUserNotificationsAsUnread(ctx context.Context, arg MarkAllUserNotificationsAsUnreadParams) error {
_, err := q.db.Exec(ctx, MarkAllUserNotificationsAsUnread, arg.UserID, arg.ReceiverType)
return err
}
const MarkNotificationAsRead = `-- name: MarkNotificationAsRead :one
UPDATE notifications
SET is_read = TRUE,
read_at = NOW()
WHERE id = $1
AND receiver_type = $2 AND user_id = $3
RETURNING id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type
`
type MarkNotificationAsReadParams struct {
ID int64 `json:"id"`
ReceiverType string `json:"receiver_type"`
RequesterID int64 `json:"requester_id"`
}
func (q *Queries) MarkNotificationAsRead(ctx context.Context, arg MarkNotificationAsReadParams) (Notification, error) {
row := q.db.QueryRow(ctx, MarkNotificationAsRead, arg.ID, arg.ReceiverType, arg.RequesterID)
var i Notification
err := row.Scan(
&i.ID,
&i.UserID,
&i.Type,
&i.Level,
&i.Channel,
&i.Title,
&i.Message,
&i.Payload,
&i.IsRead,
&i.CreatedAt,
&i.ReadAt,
&i.ReceiverType,
)
return i, err
}
const MarkNotificationAsUnread = `-- name: MarkNotificationAsUnread :one
UPDATE notifications
SET is_read = FALSE,
read_at = NULL
WHERE id = $1
AND receiver_type = $2 AND user_id = $3
RETURNING id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at, receiver_type
`
type MarkNotificationAsUnreadParams struct {
ID int64 `json:"id"`
ReceiverType string `json:"receiver_type"`
RequesterID int64 `json:"requester_id"`
}
func (q *Queries) MarkNotificationAsUnread(ctx context.Context, arg MarkNotificationAsUnreadParams) (Notification, error) {
row := q.db.QueryRow(ctx, MarkNotificationAsUnread, arg.ID, arg.ReceiverType, arg.RequesterID)
var i Notification
err := row.Scan(
&i.ID,
&i.UserID,
&i.Type,
&i.Level,
&i.Channel,
&i.Title,
&i.Message,
&i.Payload,
&i.IsRead,
&i.CreatedAt,
&i.ReadAt,
&i.ReceiverType,
)
return i, err
}