Skip to content

Commit 08c608a

Browse files
Fix notification watch end date and reuse string helper
Co-authored-by: rudrankriyam <[email protected]>
1 parent 39bf7fa commit 08c608a

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

internal/asc/output_server_api.go

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ func printServerStatusTable(resp *StatusResponse) error {
1111
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
1212
fmt.Fprintln(w, "Subscription Group ID\tOriginal Transaction ID\tStatus")
1313
for _, item := range resp.Data {
14-
groupID := serverStringValue(item.SubscriptionGroupIdentifier)
14+
groupID := stringValue(item.SubscriptionGroupIdentifier)
1515
if len(item.LastTransactions) == 0 {
1616
fmt.Fprintf(w, "%s\t\t\n", groupID)
1717
continue
1818
}
1919
for _, tx := range item.LastTransactions {
2020
fmt.Fprintf(w, "%s\t%s\t%s\n",
2121
groupID,
22-
serverStringValue(tx.OriginalTransactionID),
22+
stringValue(tx.OriginalTransactionID),
2323
formatServerStatus(tx.Status),
2424
)
2525
}
@@ -31,15 +31,15 @@ func printServerStatusMarkdown(resp *StatusResponse) error {
3131
fmt.Fprintln(os.Stdout, "| Subscription Group ID | Original Transaction ID | Status |")
3232
fmt.Fprintln(os.Stdout, "| --- | --- | --- |")
3333
for _, item := range resp.Data {
34-
groupID := serverStringValue(item.SubscriptionGroupIdentifier)
34+
groupID := stringValue(item.SubscriptionGroupIdentifier)
3535
if len(item.LastTransactions) == 0 {
3636
fmt.Fprintf(os.Stdout, "| %s | | |\n", escapeMarkdown(groupID))
3737
continue
3838
}
3939
for _, tx := range item.LastTransactions {
4040
fmt.Fprintf(os.Stdout, "| %s | %s | %s |\n",
4141
escapeMarkdown(groupID),
42-
escapeMarkdown(serverStringValue(tx.OriginalTransactionID)),
42+
escapeMarkdown(stringValue(tx.OriginalTransactionID)),
4343
escapeMarkdown(formatServerStatus(tx.Status)),
4444
)
4545
}
@@ -53,7 +53,7 @@ func printServerHistoryTable(resp *HistoryResponse) error {
5353
fmt.Fprintf(w, "%d\t%t\t%s\n",
5454
len(resp.SignedTransactions),
5555
serverBoolValue(resp.HasMore),
56-
serverStringValue(resp.Revision),
56+
stringValue(resp.Revision),
5757
)
5858
return w.Flush()
5959
}
@@ -64,7 +64,7 @@ func printServerHistoryMarkdown(resp *HistoryResponse) error {
6464
fmt.Fprintf(os.Stdout, "| %d | %t | %s |\n",
6565
len(resp.SignedTransactions),
6666
serverBoolValue(resp.HasMore),
67-
escapeMarkdown(serverStringValue(resp.Revision)),
67+
escapeMarkdown(stringValue(resp.Revision)),
6868
)
6969
return nil
7070
}
@@ -75,7 +75,7 @@ func printServerRefundHistoryTable(resp *RefundHistoryResponse) error {
7575
fmt.Fprintf(w, "%d\t%t\t%s\n",
7676
len(resp.SignedTransactions),
7777
serverBoolValue(resp.HasMore),
78-
serverStringValue(resp.Revision),
78+
stringValue(resp.Revision),
7979
)
8080
return w.Flush()
8181
}
@@ -86,22 +86,22 @@ func printServerRefundHistoryMarkdown(resp *RefundHistoryResponse) error {
8686
fmt.Fprintf(os.Stdout, "| %d | %t | %s |\n",
8787
len(resp.SignedTransactions),
8888
serverBoolValue(resp.HasMore),
89-
escapeMarkdown(serverStringValue(resp.Revision)),
89+
escapeMarkdown(stringValue(resp.Revision)),
9090
)
9191
return nil
9292
}
9393

9494
func printServerTransactionInfoTable(resp *TransactionInfoResponse) error {
9595
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
9696
fmt.Fprintln(w, "Signed Transaction Info")
97-
fmt.Fprintf(w, "%s\n", compactWhitespace(serverStringValue(resp.SignedTransactionInfo)))
97+
fmt.Fprintf(w, "%s\n", compactWhitespace(stringValue(resp.SignedTransactionInfo)))
9898
return w.Flush()
9999
}
100100

101101
func printServerTransactionInfoMarkdown(resp *TransactionInfoResponse) error {
102102
fmt.Fprintln(os.Stdout, "| Signed Transaction Info |")
103103
fmt.Fprintln(os.Stdout, "| --- |")
104-
fmt.Fprintf(os.Stdout, "| %s |\n", escapeMarkdown(compactWhitespace(serverStringValue(resp.SignedTransactionInfo))))
104+
fmt.Fprintf(os.Stdout, "| %s |\n", escapeMarkdown(compactWhitespace(stringValue(resp.SignedTransactionInfo))))
105105
return nil
106106
}
107107

@@ -128,22 +128,22 @@ func printServerOrderLookupMarkdown(resp *OrderLookupResponse) error {
128128
func printServerSendTestNotificationTable(resp *SendTestNotificationResponse) error {
129129
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
130130
fmt.Fprintln(w, "Test Notification Token")
131-
fmt.Fprintf(w, "%s\n", compactWhitespace(serverStringValue(resp.TestNotificationToken)))
131+
fmt.Fprintf(w, "%s\n", compactWhitespace(stringValue(resp.TestNotificationToken)))
132132
return w.Flush()
133133
}
134134

135135
func printServerSendTestNotificationMarkdown(resp *SendTestNotificationResponse) error {
136136
fmt.Fprintln(os.Stdout, "| Test Notification Token |")
137137
fmt.Fprintln(os.Stdout, "| --- |")
138-
fmt.Fprintf(os.Stdout, "| %s |\n", escapeMarkdown(compactWhitespace(serverStringValue(resp.TestNotificationToken))))
138+
fmt.Fprintf(os.Stdout, "| %s |\n", escapeMarkdown(compactWhitespace(stringValue(resp.TestNotificationToken))))
139139
return nil
140140
}
141141

142142
func printServerCheckTestNotificationTable(resp *CheckTestNotificationResponse) error {
143143
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
144144
fmt.Fprintln(w, "Signed Payload\tSend Attempts")
145145
fmt.Fprintf(w, "%s\t%d\n",
146-
compactWhitespace(serverStringValue(resp.SignedPayload)),
146+
compactWhitespace(stringValue(resp.SignedPayload)),
147147
len(resp.SendAttempts),
148148
)
149149
return w.Flush()
@@ -153,7 +153,7 @@ func printServerCheckTestNotificationMarkdown(resp *CheckTestNotificationRespons
153153
fmt.Fprintln(os.Stdout, "| Signed Payload | Send Attempts |")
154154
fmt.Fprintln(os.Stdout, "| --- | --- |")
155155
fmt.Fprintf(os.Stdout, "| %s | %d |\n",
156-
escapeMarkdown(compactWhitespace(serverStringValue(resp.SignedPayload))),
156+
escapeMarkdown(compactWhitespace(stringValue(resp.SignedPayload))),
157157
len(resp.SendAttempts),
158158
)
159159
return nil
@@ -165,7 +165,7 @@ func printServerNotificationHistoryTable(resp *NotificationHistoryResponse) erro
165165
fmt.Fprintf(w, "%d\t%t\t%s\n",
166166
len(resp.NotificationHistory),
167167
serverBoolValue(resp.HasMore),
168-
serverStringValue(resp.PaginationToken),
168+
stringValue(resp.PaginationToken),
169169
)
170170
return w.Flush()
171171
}
@@ -176,7 +176,7 @@ func printServerNotificationHistoryMarkdown(resp *NotificationHistoryResponse) e
176176
fmt.Fprintf(os.Stdout, "| %d | %t | %s |\n",
177177
len(resp.NotificationHistory),
178178
serverBoolValue(resp.HasMore),
179-
escapeMarkdown(serverStringValue(resp.PaginationToken)),
179+
escapeMarkdown(stringValue(resp.PaginationToken)),
180180
)
181181
return nil
182182
}
@@ -200,13 +200,6 @@ func formatServerStatus(status *ServerStatus) string {
200200
return strconv.Itoa(int(*status))
201201
}
202202

203-
func serverStringValue(value *string) string {
204-
if value == nil {
205-
return ""
206-
}
207-
return *value
208-
}
209-
210203
func serverBoolValue(value *bool) bool {
211204
if value == nil {
212205
return false

internal/cli/server/server_notifications.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,9 @@ func watchNotificationHistory(ctx context.Context, client *asc.ServerAPIClient,
300300
defer ticker.Stop()
301301

302302
currentStart := request.StartDate
303+
originalEndDate := request.EndDate
303304
for {
304-
endValue := request.EndDate
305+
endValue := originalEndDate
305306
if endValue == nil {
306307
now := time.Now().UnixMilli()
307308
endValue = &now

0 commit comments

Comments
 (0)