fix(ticket): close backend core review gaps
This commit is contained in:
@@ -47,24 +47,16 @@ func BuildTicketWithContext(item *models.Ticket, ctx *TicketBuildContext) *respo
|
||||
}
|
||||
if ctx != nil && ctx.TagsByTicketID != nil {
|
||||
ret.Tags = BuildTagResponses(ctx.TagsByTicketID[item.ID])
|
||||
} else {
|
||||
ret.Tags = BuildTagResponses(services.TicketService.GetTags(item.ID))
|
||||
}
|
||||
if item.CurrentAssigneeID > 0 {
|
||||
if ctx != nil && ctx.Users != nil {
|
||||
ret.CurrentAssigneeName = buildTicketUserDisplayName(ctx.Users[item.CurrentAssigneeID])
|
||||
}
|
||||
if ret.CurrentAssigneeName == "" {
|
||||
ret.CurrentAssigneeName = buildTicketUserDisplayName(services.UserService.Get(item.CurrentAssigneeID))
|
||||
}
|
||||
}
|
||||
if item.CustomerID > 0 {
|
||||
if ctx != nil && ctx.Customers != nil {
|
||||
ret.Customer = BuildCustomer(ctx.Customers[item.CustomerID])
|
||||
}
|
||||
if ret.Customer == nil {
|
||||
ret.Customer = BuildCustomer(services.CustomerService.Get(item.CustomerID))
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
@@ -105,9 +97,6 @@ func BuildTicketProgressWithContext(item *models.TicketProgress, ctx *TicketDeta
|
||||
if ctx != nil && ctx.Users != nil {
|
||||
ret.AuthorName = buildTicketUserDisplayName(ctx.Users[item.AuthorID])
|
||||
}
|
||||
if ret.AuthorName == "" {
|
||||
ret.AuthorName = buildTicketUserDisplayName(services.UserService.Get(item.AuthorID))
|
||||
}
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -58,6 +58,39 @@ func TestBuildLightweightTicket(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildTicketWithoutContextLeavesOptionalLookupsEmpty(t *testing.T) {
|
||||
now := time.Date(2026, 5, 2, 12, 30, 0, 0, time.Local)
|
||||
ticket := &models.Ticket{
|
||||
ID: 12,
|
||||
TicketNo: "TK202605020001",
|
||||
Title: "登录失败",
|
||||
Description: "客户反馈无法登录",
|
||||
CustomerID: 3,
|
||||
CurrentAssigneeID: 5,
|
||||
Status: enums.TicketStatusPending,
|
||||
AuditFields: models.AuditFields{
|
||||
CreateUserID: 1,
|
||||
CreateUserName: "admin",
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
},
|
||||
}
|
||||
|
||||
out := BuildTicket(ticket)
|
||||
if out == nil {
|
||||
t.Fatalf("expected ticket response")
|
||||
}
|
||||
if out.Tags != nil {
|
||||
t.Fatalf("expected tags to stay empty without context, got %+v", out.Tags)
|
||||
}
|
||||
if out.Customer != nil {
|
||||
t.Fatalf("expected customer to stay empty without context, got %+v", out.Customer)
|
||||
}
|
||||
if out.CurrentAssigneeName != "" {
|
||||
t.Fatalf("expected assignee name to stay empty without context, got %q", out.CurrentAssigneeName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildTicketProgress(t *testing.T) {
|
||||
now := time.Date(2026, 5, 2, 12, 30, 0, 0, time.Local)
|
||||
progress := &models.TicketProgress{
|
||||
|
||||
Reference in New Issue
Block a user