Files
libredesk/internal/conversation/priority/priority.go
T
Abhinav Raut 92b614ddf6 feat[automation]: ability to drag and drop automation rule and set their execution order
- feat[automation]: execution mode for automations to execute the first matching rule or run all.
- Refactor automations to use fields, values, operator and select options from @/consts @/composables
- Refactor view filters to use the pick fields, values, operator, select options from @/consts @/composables
- feat: Move from yarn to pnpm!
- feat: Custom component ComboBox, replaces convo sidebar inputs with  combo
box.
- feat: initialize stores on app load to avoid multiple API calls by storing data in Pinia.
- change app fontm trying diff fonts.
- Keep side bar menu items by default open in inboxes .
2025-01-12 06:20:45 +05:30

68 lines
1.7 KiB
Go

// Package priority handles the management of conversation priorities.
package priority
import (
"embed"
"github.com/abhinavxd/libredesk/internal/conversation/priority/models"
"github.com/abhinavxd/libredesk/internal/dbutil"
"github.com/abhinavxd/libredesk/internal/envelope"
"github.com/jmoiron/sqlx"
"github.com/zerodha/logf"
)
var (
//go:embed queries.sql
efs embed.FS
)
// Manager handles changes to priorities.
type Manager struct {
q queries
lo *logf.Logger
}
// Opts contains options for initializing the Manager.
type Opts struct {
DB *sqlx.DB
Lo *logf.Logger
}
// queries contains prepared SQL queries.
type queries struct {
GetAll *sqlx.Stmt `query:"get-all"`
Get *sqlx.Stmt `query:"get"`
}
// New creates and returns a new instance of the Manager.
func New(opts Opts) (*Manager, error) {
var q queries
if err := dbutil.ScanSQLFile("queries.sql", &q, opts.DB, efs); err != nil {
return nil, err
}
return &Manager{
q: q,
lo: opts.Lo,
}, nil
}
// GetAll retrieves all priorities.
func (m *Manager) GetAll() ([]models.Priority, error) {
var priorities = make([]models.Priority, 0)
if err := m.q.GetAll.Select(&priorities); err != nil {
m.lo.Error("error fetching priorities", "error", err)
return nil, envelope.NewError(envelope.GeneralError, "Error fetching priorities", nil)
}
return priorities, nil
}
// Get retrieves a priority by ID.
func (m *Manager) Get(id int) (models.Priority, error) {
var priority models.Priority
if err := m.q.Get.Get(&priority, id); err != nil {
m.lo.Error("error fetching priority", "error", err)
return priority, envelope.NewError(envelope.GeneralError, "Error fetching priority", nil)
}
return priority, nil
}