0caa803d27
showPopup was also refactored to be better
178 lines
5.7 KiB
Go
178 lines
5.7 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// source: notification.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createNotification = `-- name: CreateNotification :one
|
|
INSERT INTO notification(notification_object_id, notifier_id)
|
|
VALUES ($1, $2) RETURNING notification_id, notification_object_id, notifier_id, read
|
|
`
|
|
|
|
type CreateNotificationParams struct {
|
|
NotificationObjectID uuid.UUID `json:"notification_object_id"`
|
|
NotifierID uuid.UUID `json:"notifier_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateNotification(ctx context.Context, arg CreateNotificationParams) (Notification, error) {
|
|
row := q.db.QueryRowContext(ctx, createNotification, arg.NotificationObjectID, arg.NotifierID)
|
|
var i Notification
|
|
err := row.Scan(
|
|
&i.NotificationID,
|
|
&i.NotificationObjectID,
|
|
&i.NotifierID,
|
|
&i.Read,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const createNotificationObject = `-- name: CreateNotificationObject :one
|
|
INSERT INTO notification_object(entity_type, action_type, entity_id, created_on, actor_id)
|
|
VALUES ($1, $2, $3, $4, $5) RETURNING notification_object_id, entity_id, action_type, actor_id, entity_type, created_on
|
|
`
|
|
|
|
type CreateNotificationObjectParams struct {
|
|
EntityType int32 `json:"entity_type"`
|
|
ActionType int32 `json:"action_type"`
|
|
EntityID uuid.UUID `json:"entity_id"`
|
|
CreatedOn time.Time `json:"created_on"`
|
|
ActorID uuid.UUID `json:"actor_id"`
|
|
}
|
|
|
|
func (q *Queries) CreateNotificationObject(ctx context.Context, arg CreateNotificationObjectParams) (NotificationObject, error) {
|
|
row := q.db.QueryRowContext(ctx, createNotificationObject,
|
|
arg.EntityType,
|
|
arg.ActionType,
|
|
arg.EntityID,
|
|
arg.CreatedOn,
|
|
arg.ActorID,
|
|
)
|
|
var i NotificationObject
|
|
err := row.Scan(
|
|
&i.NotificationObjectID,
|
|
&i.EntityID,
|
|
&i.ActionType,
|
|
&i.ActorID,
|
|
&i.EntityType,
|
|
&i.CreatedOn,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getAllNotificationsForUserID = `-- name: GetAllNotificationsForUserID :many
|
|
SELECT n.notification_id, n.notification_object_id, n.notifier_id, n.read FROM notification as n
|
|
INNER JOIN notification_object as no ON no.notification_object_id = n.notification_object_id
|
|
WHERE n.notifier_id = $1 ORDER BY no.created_on DESC
|
|
`
|
|
|
|
func (q *Queries) GetAllNotificationsForUserID(ctx context.Context, notifierID uuid.UUID) ([]Notification, error) {
|
|
rows, err := q.db.QueryContext(ctx, getAllNotificationsForUserID, notifierID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []Notification
|
|
for rows.Next() {
|
|
var i Notification
|
|
if err := rows.Scan(
|
|
&i.NotificationID,
|
|
&i.NotificationObjectID,
|
|
&i.NotifierID,
|
|
&i.Read,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getEntityForNotificationID = `-- name: GetEntityForNotificationID :one
|
|
SELECT no.created_on, no.entity_id, no.entity_type, no.action_type, no.actor_id FROM notification as n
|
|
INNER JOIN notification_object as no ON no.notification_object_id = n.notification_object_id
|
|
WHERE n.notification_id = $1
|
|
`
|
|
|
|
type GetEntityForNotificationIDRow struct {
|
|
CreatedOn time.Time `json:"created_on"`
|
|
EntityID uuid.UUID `json:"entity_id"`
|
|
EntityType int32 `json:"entity_type"`
|
|
ActionType int32 `json:"action_type"`
|
|
ActorID uuid.UUID `json:"actor_id"`
|
|
}
|
|
|
|
func (q *Queries) GetEntityForNotificationID(ctx context.Context, notificationID uuid.UUID) (GetEntityForNotificationIDRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getEntityForNotificationID, notificationID)
|
|
var i GetEntityForNotificationIDRow
|
|
err := row.Scan(
|
|
&i.CreatedOn,
|
|
&i.EntityID,
|
|
&i.EntityType,
|
|
&i.ActionType,
|
|
&i.ActorID,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getEntityIDForNotificationID = `-- name: GetEntityIDForNotificationID :one
|
|
SELECT no.entity_id FROM notification as n
|
|
INNER JOIN notification_object as no ON no.notification_object_id = n.notification_object_id
|
|
WHERE n.notification_id = $1
|
|
`
|
|
|
|
func (q *Queries) GetEntityIDForNotificationID(ctx context.Context, notificationID uuid.UUID) (uuid.UUID, error) {
|
|
row := q.db.QueryRowContext(ctx, getEntityIDForNotificationID, notificationID)
|
|
var entity_id uuid.UUID
|
|
err := row.Scan(&entity_id)
|
|
return entity_id, err
|
|
}
|
|
|
|
const getNotificationForNotificationID = `-- name: GetNotificationForNotificationID :one
|
|
SELECT n.notification_id, n.notification_object_id, n.notifier_id, n.read, no.notification_object_id, no.entity_id, no.action_type, no.actor_id, no.entity_type, no.created_on FROM notification as n
|
|
INNER JOIN notification_object as no ON no.notification_object_id = n.notification_object_id
|
|
WHERE n.notification_id = $1
|
|
`
|
|
|
|
type GetNotificationForNotificationIDRow struct {
|
|
NotificationID uuid.UUID `json:"notification_id"`
|
|
NotificationObjectID uuid.UUID `json:"notification_object_id"`
|
|
NotifierID uuid.UUID `json:"notifier_id"`
|
|
Read bool `json:"read"`
|
|
NotificationObjectID_2 uuid.UUID `json:"notification_object_id_2"`
|
|
EntityID uuid.UUID `json:"entity_id"`
|
|
ActionType int32 `json:"action_type"`
|
|
ActorID uuid.UUID `json:"actor_id"`
|
|
EntityType int32 `json:"entity_type"`
|
|
CreatedOn time.Time `json:"created_on"`
|
|
}
|
|
|
|
func (q *Queries) GetNotificationForNotificationID(ctx context.Context, notificationID uuid.UUID) (GetNotificationForNotificationIDRow, error) {
|
|
row := q.db.QueryRowContext(ctx, getNotificationForNotificationID, notificationID)
|
|
var i GetNotificationForNotificationIDRow
|
|
err := row.Scan(
|
|
&i.NotificationID,
|
|
&i.NotificationObjectID,
|
|
&i.NotifierID,
|
|
&i.Read,
|
|
&i.NotificationObjectID_2,
|
|
&i.EntityID,
|
|
&i.ActionType,
|
|
&i.ActorID,
|
|
&i.EntityType,
|
|
&i.CreatedOn,
|
|
)
|
|
return i, err
|
|
}
|