feat: add notification UI

showPopup was also refactored to be better
This commit is contained in:
Jordan Knott
2020-08-12 20:54:14 -05:00
parent feea209507
commit 0caa803d27
34 changed files with 2516 additions and 104 deletions

View File

@ -16,6 +16,22 @@ type LabelColor struct {
Name string `json:"name"`
}
type Notification struct {
NotificationID uuid.UUID `json:"notification_id"`
NotificationObjectID uuid.UUID `json:"notification_object_id"`
NotifierID uuid.UUID `json:"notifier_id"`
Read bool `json:"read"`
}
type NotificationObject struct {
NotificationObjectID uuid.UUID `json:"notification_object_id"`
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"`
}
type Organization struct {
OrganizationID uuid.UUID `json:"organization_id"`
CreatedAt time.Time `json:"created_at"`

View File

@ -0,0 +1,177 @@
// 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
}

View File

@ -10,6 +10,8 @@ import (
type Querier interface {
CreateLabelColor(ctx context.Context, arg CreateLabelColorParams) (LabelColor, error)
CreateNotification(ctx context.Context, arg CreateNotificationParams) (Notification, error)
CreateNotificationObject(ctx context.Context, arg CreateNotificationObjectParams) (NotificationObject, error)
CreateOrganization(ctx context.Context, arg CreateOrganizationParams) (Organization, error)
CreateProject(ctx context.Context, arg CreateProjectParams) (Project, error)
CreateProjectLabel(ctx context.Context, arg CreateProjectLabelParams) (ProjectLabel, error)
@ -42,6 +44,7 @@ type Querier interface {
DeleteTeamByID(ctx context.Context, teamID uuid.UUID) error
DeleteTeamMember(ctx context.Context, arg DeleteTeamMemberParams) error
DeleteUserAccountByID(ctx context.Context, userID uuid.UUID) error
GetAllNotificationsForUserID(ctx context.Context, notifierID uuid.UUID) ([]Notification, error)
GetAllOrganizations(ctx context.Context) ([]Organization, error)
GetAllProjects(ctx context.Context) ([]Project, error)
GetAllProjectsForTeam(ctx context.Context, teamID uuid.UUID) ([]Project, error)
@ -51,10 +54,13 @@ type Querier interface {
GetAllUserAccounts(ctx context.Context) ([]UserAccount, error)
GetAllVisibleProjectsForUserID(ctx context.Context, userID uuid.UUID) ([]Project, error)
GetAssignedMembersForTask(ctx context.Context, taskID uuid.UUID) ([]TaskAssigned, error)
GetEntityForNotificationID(ctx context.Context, notificationID uuid.UUID) (GetEntityForNotificationIDRow, error)
GetEntityIDForNotificationID(ctx context.Context, notificationID uuid.UUID) (uuid.UUID, error)
GetLabelColorByID(ctx context.Context, labelColorID uuid.UUID) (LabelColor, error)
GetLabelColors(ctx context.Context) ([]LabelColor, error)
GetMemberProjectIDsForUserID(ctx context.Context, userID uuid.UUID) ([]uuid.UUID, error)
GetMemberTeamIDsForUserID(ctx context.Context, userID uuid.UUID) ([]uuid.UUID, error)
GetNotificationForNotificationID(ctx context.Context, notificationID uuid.UUID) (GetNotificationForNotificationIDRow, error)
GetProjectByID(ctx context.Context, projectID uuid.UUID) (Project, error)
GetProjectIDForTask(ctx context.Context, taskID uuid.UUID) (uuid.UUID, error)
GetProjectLabelByID(ctx context.Context, projectLabelID uuid.UUID) (ProjectLabel, error)

View File

@ -0,0 +1,28 @@
-- name: GetAllNotificationsForUserID :many
SELECT n.* 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;
-- name: GetNotificationForNotificationID :one
SELECT n.*, no.* FROM notification as n
INNER JOIN notification_object as no ON no.notification_object_id = n.notification_object_id
WHERE n.notification_id = $1;
-- name: CreateNotificationObject :one
INSERT INTO notification_object(entity_type, action_type, entity_id, created_on, actor_id)
VALUES ($1, $2, $3, $4, $5) RETURNING *;
-- 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;
-- 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;
-- name: CreateNotification :one
INSERT INTO notification(notification_object_id, notifier_id)
VALUES ($1, $2) RETURNING *;