mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-09-22 02:23:32 +00:00
92b614ddf6
- 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 .
92 lines
2.2 KiB
Go
92 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
cmodels "github.com/abhinavxd/libredesk/internal/conversation/models"
|
|
"github.com/abhinavxd/libredesk/internal/envelope"
|
|
"github.com/valyala/fasthttp"
|
|
"github.com/zerodha/fastglue"
|
|
)
|
|
|
|
func handleGetStatuses(r *fastglue.Request) error {
|
|
var (
|
|
app = r.Context.(*App)
|
|
)
|
|
out, err := app.status.GetAll()
|
|
if err != nil {
|
|
return sendErrorEnvelope(r, err)
|
|
}
|
|
return r.SendEnvelope(out)
|
|
}
|
|
|
|
func handleCreateStatus(r *fastglue.Request) error {
|
|
var (
|
|
app = r.Context.(*App)
|
|
status = cmodels.Status{}
|
|
)
|
|
if err := r.Decode(&status, "json"); err != nil {
|
|
return r.SendErrorEnvelope(fasthttp.StatusBadRequest, "decode failed", err.Error(), envelope.InputError)
|
|
}
|
|
|
|
if status.Name == "" {
|
|
return r.SendErrorEnvelope(fasthttp.StatusBadRequest, "Empty status `Name`", nil, envelope.InputError)
|
|
}
|
|
|
|
err := app.status.Create(status.Name)
|
|
if err != nil {
|
|
return sendErrorEnvelope(r, err)
|
|
}
|
|
|
|
return r.SendEnvelope(true)
|
|
}
|
|
|
|
func handleDeleteStatus(r *fastglue.Request) error {
|
|
var (
|
|
app = r.Context.(*App)
|
|
)
|
|
id, err := strconv.Atoi(r.RequestCtx.UserValue("id").(string))
|
|
if err != nil || id == 0 {
|
|
return r.SendErrorEnvelope(fasthttp.StatusBadRequest,
|
|
"Invalid status `id`.", nil, envelope.InputError)
|
|
}
|
|
|
|
if id <= 0 {
|
|
return r.SendErrorEnvelope(fasthttp.StatusBadRequest, "Empty status `ID`", nil, envelope.InputError)
|
|
}
|
|
|
|
err = app.status.Delete(id)
|
|
if err != nil {
|
|
return sendErrorEnvelope(r, err)
|
|
}
|
|
|
|
return r.SendEnvelope(true)
|
|
}
|
|
|
|
func handleUpdateStatus(r *fastglue.Request) error {
|
|
var (
|
|
app = r.Context.(*App)
|
|
status = cmodels.Status{}
|
|
)
|
|
id, err := strconv.Atoi(r.RequestCtx.UserValue("id").(string))
|
|
if err != nil || id == 0 {
|
|
return r.SendErrorEnvelope(fasthttp.StatusBadRequest,
|
|
"Invalid status `id`.", nil, envelope.InputError)
|
|
}
|
|
|
|
if err := r.Decode(&status, "json"); err != nil {
|
|
return r.SendErrorEnvelope(fasthttp.StatusBadRequest, "decode failed", err.Error(), envelope.InputError)
|
|
}
|
|
|
|
if status.Name == "" {
|
|
return r.SendErrorEnvelope(fasthttp.StatusBadRequest, "Empty status `Name`", nil, envelope.InputError)
|
|
}
|
|
|
|
err = app.status.Update(id, status.Name)
|
|
if err != nil {
|
|
return sendErrorEnvelope(r, err)
|
|
}
|
|
|
|
return r.SendEnvelope(true)
|
|
}
|