Skip to content

Commit 7fbaf1a

Browse files
add new fields on inboxes for ai review settings
1 parent 3ae414d commit 7fbaf1a

File tree

8 files changed

+93
-37
lines changed

8 files changed

+93
-37
lines changed

api/handle_inboxes.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,14 @@ func handlePatchInbox(uc usecases.Usecases) func(c *gin.Context) {
153153
return
154154
}
155155

156-
var data struct {
157-
Name *string `json:"name"`
158-
EscalationInboxId *uuid.UUID `json:"escalation_inbox_id" binding:"omitempty,uuid"`
159-
AutoAssignEnabled *bool `json:"auto_assign_enabled"`
160-
}
156+
var data dto.UpdateInboxInput
161157
if err := c.ShouldBind(&data); err != nil {
162158
c.Status(http.StatusBadRequest)
163159
return
164160
}
165161

166162
usecase := usecasesWithCreds(ctx, uc).NewInboxUsecase()
167-
inbox, err := usecase.UpdateInbox(ctx, getInboxInput.InboxId.Uuid(), data.Name,
168-
data.EscalationInboxId, data.AutoAssignEnabled)
163+
inbox, err := usecase.UpdateInbox(ctx, getInboxInput.InboxId.Uuid(), dto.AdaptUpdateInboxInput(data))
169164
if presentError(ctx, c, err) {
170165
return
171166
}

dto/inbox_dto.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,23 @@ func AdaptInboxMetadataDto(i models.InboxMetadata) InboxMetadataDto {
6767
Name: i.Name,
6868
}
6969
}
70+
71+
type UpdateInboxInput struct {
72+
Name *string `json:"name"`
73+
EscalationInboxId *uuid.UUID `json:"escalation_inbox_id"`
74+
AutoAssignEnabled *bool `json:"auto_assign_enabled"`
75+
CaseReviewManual *bool `json:"case_review_manual"`
76+
CaseReviewOnCaseCreated *bool `json:"case_review_on_case_created"`
77+
CaseReviewOnEscalate *bool `json:"case_review_on_escalate"`
78+
}
79+
80+
func AdaptUpdateInboxInput(i UpdateInboxInput) models.UpdateInboxInput {
81+
return models.UpdateInboxInput{
82+
Name: i.Name,
83+
EscalationInboxId: i.EscalationInboxId,
84+
AutoAssignEnabled: i.AutoAssignEnabled,
85+
CaseReviewManual: i.CaseReviewManual,
86+
CaseReviewOnCaseCreated: i.CaseReviewOnCaseCreated,
87+
CaseReviewOnEscalate: i.CaseReviewOnEscalate,
88+
}
89+
}

mocks/inboxes_repository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ func (r *InboxRepository) CreateInbox(ctx context.Context, exec repositories.Exe
3434
}
3535

3636
func (r *InboxRepository) UpdateInbox(ctx context.Context, exec repositories.Executor,
37-
inboxId uuid.UUID, name *string, escalationInboxId *uuid.UUID, autoAssignEnabled *bool,
37+
inboxId uuid.UUID, input models.UpdateInboxInput,
3838
) error {
39-
args := r.Called(exec, inboxId, name, escalationInboxId, autoAssignEnabled)
39+
args := r.Called(exec, inboxId, input)
4040
return args.Error(0)
4141
}
4242

models/inbox.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ type Inbox struct {
2424
UpdatedAt time.Time
2525
InboxUsers []InboxUser
2626
CasesCount *int
27+
28+
// Fields for case review (automatic or manual) settings. May be moved to a separate implementation if or when
29+
// we have more advanced automations implemented on cases.
30+
CaseReviewManual bool
31+
CaseReviewOnCaseCreated bool
32+
CaseReviewOnEscalate bool
2733
}
2834

2935
type InboxMetadata struct {
@@ -47,7 +53,10 @@ type CreateInboxInput struct {
4753
}
4854

4955
type UpdateInboxInput struct {
50-
Id uuid.UUID
51-
Name string
52-
EscalationInboxId *uuid.UUID
56+
Name *string `json:"name"`
57+
EscalationInboxId *uuid.UUID `json:"escalation_inbox_id"`
58+
AutoAssignEnabled *bool `json:"auto_assign_enabled"`
59+
CaseReviewManual *bool `json:"case_review_manual"`
60+
CaseReviewOnCaseCreated *bool `json:"case_review_on_case_created"`
61+
CaseReviewOnEscalate *bool `json:"case_review_on_escalate"`
5362
}

repositories/dbmodels/db_inbox.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ type DBInbox struct {
1919
Status string `db:"status"`
2020
EscalationInboxId *uuid.UUID `db:"escalation_inbox_id"`
2121
AutoAssignEnabled bool `db:"auto_assign_enabled"`
22+
23+
// Fields for case review (automatic or manual) settings. May be moved to a separate implementation if or when
24+
// we have more advanced automations implemented on cases.
25+
CaseReviewManual bool `db:"case_review_manual"`
26+
CaseReviewOnCaseCreated bool `db:"case_review_on_case_created"`
27+
CaseReviewOnEscalate bool `db:"case_review_on_escalate"`
2228
}
2329

2430
const TABLE_INBOXES = "inboxes"
@@ -27,14 +33,17 @@ var SelectInboxColumn = utils.ColumnList[DBInbox]()
2733

2834
func AdaptInbox(db DBInbox) (models.Inbox, error) {
2935
return models.Inbox{
30-
Id: db.Id,
31-
OrganizationId: db.OrganizationId,
32-
CreatedAt: db.CreatedAt,
33-
UpdatedAt: db.UpdatedAt,
34-
Name: db.Name,
35-
Status: models.InboxStatus(db.Status),
36-
EscalationInboxId: db.EscalationInboxId,
37-
AutoAssignEnabled: db.AutoAssignEnabled,
36+
Id: db.Id,
37+
OrganizationId: db.OrganizationId,
38+
CreatedAt: db.CreatedAt,
39+
UpdatedAt: db.UpdatedAt,
40+
Name: db.Name,
41+
Status: models.InboxStatus(db.Status),
42+
EscalationInboxId: db.EscalationInboxId,
43+
AutoAssignEnabled: db.AutoAssignEnabled,
44+
CaseReviewManual: db.CaseReviewManual,
45+
CaseReviewOnCaseCreated: db.CaseReviewOnCaseCreated,
46+
CaseReviewOnEscalate: db.CaseReviewOnEscalate,
3847
}, nil
3948
}
4049

repositories/inboxes_repository.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,30 +118,41 @@ func (repo *MarbleDbRepository) UpdateInbox(
118118
ctx context.Context,
119119
exec Executor,
120120
inboxId uuid.UUID,
121-
name *string,
122-
escalationInboxId *uuid.UUID,
123-
autoAssignEnabled *bool,
121+
input models.UpdateInboxInput,
124122
) error {
125123
if err := validateMarbleDbExecutor(exec); err != nil {
126124
return err
127125
}
128126

129-
sql := NewQueryBuilder().Update(dbmodels.TABLE_INBOXES).
127+
sql := NewQueryBuilder().
128+
Update(dbmodels.TABLE_INBOXES).
130129
Set("updated_at", squirrel.Expr("NOW()")).
131130
Where(squirrel.Eq{"id": inboxId})
132131

133132
hasUpdates := false
134133

135-
if name != nil {
136-
sql = sql.Set("name", *name)
134+
if input.Name != nil {
135+
sql = sql.Set("name", *input.Name)
137136
hasUpdates = true
138137
}
139-
if escalationInboxId != nil {
140-
sql = sql.Set("escalation_inbox_id", *escalationInboxId)
138+
if input.EscalationInboxId != nil {
139+
sql = sql.Set("escalation_inbox_id", *input.EscalationInboxId)
141140
hasUpdates = true
142141
}
143-
if autoAssignEnabled != nil {
144-
sql = sql.Set("auto_assign_enabled", *autoAssignEnabled)
142+
if input.AutoAssignEnabled != nil {
143+
sql = sql.Set("auto_assign_enabled", *input.AutoAssignEnabled)
144+
hasUpdates = true
145+
}
146+
if input.CaseReviewManual != nil {
147+
sql = sql.Set("case_review_manual", *input.CaseReviewManual)
148+
hasUpdates = true
149+
}
150+
if input.CaseReviewOnCaseCreated != nil {
151+
sql = sql.Set("case_review_on_case_created", *input.CaseReviewOnCaseCreated)
152+
hasUpdates = true
153+
}
154+
if input.CaseReviewOnEscalate != nil {
155+
sql = sql.Set("case_review_on_escalate", *input.CaseReviewOnEscalate)
145156
hasUpdates = true
146157
}
147158

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- +goose Up
2+
-- +goose StatementBegin
3+
ALTER TABLE inboxes
4+
ADD COLUMN case_review_manual BOOLEAN NOT NULL DEFAULT false,
5+
ADD COLUMN case_review_on_case_created BOOLEAN NOT NULL DEFAULT false,
6+
ADD COLUMN case_review_on_escalate BOOLEAN NOT NULL DEFAULT false;
7+
8+
-- +goose StatementEnd
9+
-- +goose Down
10+
-- +goose StatementBegin
11+
ALTER TABLE inboxes
12+
DROP COLUMN case_review_manual,
13+
DROP COLUMN case_review_on_case_created,
14+
DROP COLUMN case_review_on_escalate;
15+
16+
-- +goose StatementEnd

usecases/inboxes_usecase.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ type InboxRepository interface {
1919
inboxIds []uuid.UUID, withCaseCount bool) ([]models.Inbox, error)
2020
CreateInbox(ctx context.Context, exec repositories.Executor,
2121
createInboxAttributes models.CreateInboxInput, newInboxId uuid.UUID) error
22-
UpdateInbox(ctx context.Context, exec repositories.Executor,
23-
inboxId uuid.UUID, name *string, escalationInboxId *uuid.UUID, autoAssignEnabled *bool) error
22+
UpdateInbox(ctx context.Context, exec repositories.Executor, inboxId uuid.UUID, input models.UpdateInboxInput) error
2423
SoftDeleteInbox(ctx context.Context, exec repositories.Executor, inboxId uuid.UUID) error
2524

2625
ListOrganizationCases(ctx context.Context, exec repositories.Executor, filters models.CaseFilters,
@@ -114,9 +113,7 @@ func (usecase *InboxUsecase) CreateInbox(ctx context.Context, input models.Creat
114113
return inbox, nil
115114
}
116115

117-
func (usecase *InboxUsecase) UpdateInbox(ctx context.Context, inboxId uuid.UUID, name *string,
118-
escalationInboxId *uuid.UUID, autoAssignEnabled *bool,
119-
) (models.Inbox, error) {
116+
func (usecase *InboxUsecase) UpdateInbox(ctx context.Context, inboxId uuid.UUID, input models.UpdateInboxInput) (models.Inbox, error) {
120117
inbox, err := executor_factory.TransactionReturnValue(
121118
ctx,
122119
usecase.transactionFactory,
@@ -135,8 +132,7 @@ func (usecase *InboxUsecase) UpdateInbox(ctx context.Context, inboxId uuid.UUID,
135132
return models.Inbox{}, err
136133
}
137134

138-
if err := usecase.inboxRepository.UpdateInbox(ctx, tx, inboxId, name,
139-
escalationInboxId, autoAssignEnabled); err != nil {
135+
if err := usecase.inboxRepository.UpdateInbox(ctx, tx, inboxId, input); err != nil {
140136
return models.Inbox{}, err
141137
}
142138

0 commit comments

Comments
 (0)