mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #14005 from rainzm/notify/topic_1_1_notification
feat(notify): add topic_type in notification details
This commit is contained in:
@@ -77,6 +77,7 @@ type NotificationDetails struct {
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
ReceiveDetails []ReceiveDetail `json:"receive_details"`
|
||||
TopicType string `json:"topic_type"`
|
||||
}
|
||||
|
||||
type NotificationListInput struct {
|
||||
|
||||
@@ -464,14 +464,45 @@ func (nm *SNotificationManager) FetchCustomizeColumns(
|
||||
resRows := nm.SStatusStandaloneResourceBaseManager.FetchCustomizeColumns(ctx, userCred, query, objs, fields, isList)
|
||||
|
||||
var err error
|
||||
notifications := make([]*SNotification, len(objs))
|
||||
for i := range notifications {
|
||||
notifications[i] = objs[i].(*SNotification)
|
||||
}
|
||||
// fetch topic_type
|
||||
eventTopictypes := make(map[string]string)
|
||||
for i := range notifications {
|
||||
eventTopictypes[notifications[i].EventId] = ""
|
||||
}
|
||||
eventIds := make([]string, 0, len(eventTopictypes))
|
||||
for eventId := range eventTopictypes {
|
||||
eventIds = append(eventIds, eventId)
|
||||
}
|
||||
eventSubq := EventManager.Query("topic_id", "id").In("id", eventIds).SubQuery()
|
||||
topicQ := TopicManager.Query("type")
|
||||
topicQ = topicQ.Join(eventSubq, sqlchemy.Equals(topicQ.Field("id"), eventSubq.Field("topic_id")))
|
||||
topicQ.AppendField(eventSubq.Field("id", "event_id"))
|
||||
type eventTopictype struct {
|
||||
EventId string
|
||||
Type string
|
||||
}
|
||||
ets := make([]eventTopictype, 0)
|
||||
err = topicQ.All(&ets)
|
||||
if err != nil {
|
||||
log.Errorf("unable to fetch topic with eventId %s", eventIds)
|
||||
return rows
|
||||
}
|
||||
for i := range ets {
|
||||
eventTopictypes[ets[i].EventId] = ets[i].Type
|
||||
}
|
||||
|
||||
for i := range rows {
|
||||
rows[i], err = objs[i].(*SNotification).getMoreDetails(ctx, userCred, query, rows[i])
|
||||
rows[i], err = notifications[i].getMoreDetails(ctx, userCred, query, rows[i])
|
||||
if err != nil {
|
||||
log.Errorf("Notification.getMoreDetails: %v", err)
|
||||
}
|
||||
rows[i].TopicType = eventTopictypes[notifications[i].EventId]
|
||||
rows[i].StatusStandaloneResourceDetails = resRows[i]
|
||||
}
|
||||
|
||||
return rows
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user