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

277 lines
5.9 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.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 is_read = FALSE
`
func (q *Queries) CountUnreadNotifications(ctx context.Context, userID int64) (int64, error) {
row := q.db.QueryRow(ctx, CountUnreadNotifications, userID)
var count int64
err := row.Scan(&count)
return count, err
}
const CreateNotification = `-- name: CreateNotification :one
INSERT INTO notifications (
user_id,
type,
level,
channel,
title,
message,
payload
)
VALUES (
$1,
$2,
$3,
$4,
$5,
$6,
$7
)
RETURNING id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at
`
type CreateNotificationParams struct {
UserID int64 `json:"user_id"`
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.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,
)
return i, err
}
const DeleteUserNotifications = `-- name: DeleteUserNotifications :exec
DELETE FROM notifications
WHERE user_id = $1
`
func (q *Queries) DeleteUserNotifications(ctx context.Context, userID int64) error {
_, err := q.db.Exec(ctx, DeleteUserNotifications, userID)
return err
}
const GetAllNotifications = `-- name: GetAllNotifications :many
SELECT id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at
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,
); 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
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,
)
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
`
func (q *Queries) GetUserNotificationCount(ctx context.Context, userID int64) (int64, error) {
row := q.db.QueryRow(ctx, GetUserNotificationCount, userID)
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
FROM notifications
WHERE user_id = $1
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"`
}
func (q *Queries) GetUserNotifications(ctx context.Context, arg GetUserNotificationsParams) ([]Notification, error) {
rows, err := q.db.Query(ctx, GetUserNotifications, arg.UserID, 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,
); 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 is_read = FALSE
`
func (q *Queries) MarkAllUserNotificationsAsRead(ctx context.Context, userID int64) error {
_, err := q.db.Exec(ctx, MarkAllUserNotificationsAsRead, userID)
return err
}
const MarkNotificationAsRead = `-- name: MarkNotificationAsRead :one
UPDATE notifications
SET is_read = TRUE,
read_at = NOW()
WHERE id = $1
RETURNING id, user_id, type, level, channel, title, message, payload, is_read, created_at, read_at
`
func (q *Queries) MarkNotificationAsRead(ctx context.Context, id int64) (Notification, error) {
row := q.db.QueryRow(ctx, MarkNotificationAsRead, 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,
)
return i, err
}