Skip to content

Commit fd25893

Browse files
alexluongclaude
andcommitted
chore: update handlers to use mustTenantFromContext
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 77b319b commit fd25893

File tree

4 files changed

+14
-62
lines changed

4 files changed

+14
-62
lines changed

internal/apirouter/destination_handlers.go

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,9 @@ func (h *DestinationHandlers) List(c *gin.Context) {
4545
})
4646
}
4747

48-
tenantID := mustTenantIDFromContext(c)
49-
if tenantID == "" {
50-
return
51-
}
48+
tenant := mustTenantFromContext(c)
5249

53-
destinations, err := h.tenantStore.ListDestinationByTenant(c.Request.Context(), tenantID, opts)
50+
destinations, err := h.tenantStore.ListDestinationByTenant(c.Request.Context(), tenant.ID, opts)
5451
if err != nil {
5552
AbortWithError(c, http.StatusInternalServerError, NewErrInternalServer(err))
5653
return
@@ -77,12 +74,9 @@ func (h *DestinationHandlers) Create(c *gin.Context) {
7774
return
7875
}
7976

80-
tenantID := mustTenantIDFromContext(c)
81-
if tenantID == "" {
82-
return
83-
}
77+
tenant := mustTenantFromContext(c)
8478

85-
destination := input.ToDestination(tenantID)
79+
destination := input.ToDestination(tenant.ID)
8680
if err := destination.Validate(h.topics); err != nil {
8781
AbortWithValidationError(c, err)
8882
return
@@ -112,11 +106,8 @@ func (h *DestinationHandlers) Create(c *gin.Context) {
112106
}
113107

114108
func (h *DestinationHandlers) Retrieve(c *gin.Context) {
115-
tenantID := mustTenantIDFromContext(c)
116-
if tenantID == "" {
117-
return
118-
}
119-
destination := h.mustRetrieveDestination(c, tenantID, c.Param("destinationID"))
109+
tenant := mustTenantFromContext(c)
110+
destination := h.mustRetrieveDestination(c, tenant.ID, c.Param("destinationID"))
120111
if destination == nil {
121112
return
122113
}
@@ -138,11 +129,8 @@ func (h *DestinationHandlers) Update(c *gin.Context) {
138129
}
139130

140131
// Retrieve destination.
141-
tenantID := mustTenantIDFromContext(c)
142-
if tenantID == "" {
143-
return
144-
}
145-
originalDestination := h.mustRetrieveDestination(c, tenantID, c.Param("destinationID"))
132+
tenant := mustTenantFromContext(c)
133+
originalDestination := h.mustRetrieveDestination(c, tenant.ID, c.Param("destinationID"))
146134
if originalDestination == nil {
147135
return
148136
}
@@ -211,11 +199,8 @@ func (h *DestinationHandlers) Update(c *gin.Context) {
211199
}
212200

213201
func (h *DestinationHandlers) Delete(c *gin.Context) {
214-
tenantID := mustTenantIDFromContext(c)
215-
if tenantID == "" {
216-
return
217-
}
218-
destination := h.mustRetrieveDestination(c, tenantID, c.Param("destinationID"))
202+
tenant := mustTenantFromContext(c)
203+
destination := h.mustRetrieveDestination(c, tenant.ID, c.Param("destinationID"))
219204
if destination == nil {
220205
return
221206
}
@@ -256,11 +241,8 @@ func (h *DestinationHandlers) RetrieveProviderMetadata(c *gin.Context) {
256241
}
257242

258243
func (h *DestinationHandlers) setDisabilityHandler(c *gin.Context, disabled bool) {
259-
tenantID := mustTenantIDFromContext(c)
260-
if tenantID == "" {
261-
return
262-
}
263-
destination := h.mustRetrieveDestination(c, tenantID, c.Param("destinationID"))
244+
tenant := mustTenantFromContext(c)
245+
destination := h.mustRetrieveDestination(c, tenant.ID, c.Param("destinationID"))
264246
if destination == nil {
265247
return
266248
}

internal/apirouter/log_handlers.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,13 @@ func toAPIAttempt(ar *logstore.AttemptRecord, opts IncludeOptions) APIAttempt {
197197
// Query params: event_id, destination_id, status, topic[], start, end, limit, next, prev, expand[], sort_order
198198
func (h *LogHandlers) ListAttempts(c *gin.Context) {
199199
tenant := mustTenantFromContext(c)
200-
if tenant == nil {
201-
return
202-
}
203200
h.listAttemptsInternal(c, tenant.ID, "")
204201
}
205202

206203
// ListDestinationAttempts handles GET /:tenantID/destinations/:destinationID/attempts
207204
// Same as ListAttempts but scoped to a specific destination via URL param.
208205
func (h *LogHandlers) ListDestinationAttempts(c *gin.Context) {
209206
tenant := mustTenantFromContext(c)
210-
if tenant == nil {
211-
return
212-
}
213207
destinationID := c.Param("destinationID")
214208
h.listAttemptsInternal(c, tenant.ID, destinationID)
215209
}
@@ -310,9 +304,6 @@ func (h *LogHandlers) listAttemptsInternal(c *gin.Context, tenantID string, dest
310304
// RetrieveEvent handles GET /:tenantID/events/:eventID
311305
func (h *LogHandlers) RetrieveEvent(c *gin.Context) {
312306
tenant := mustTenantFromContext(c)
313-
if tenant == nil {
314-
return
315-
}
316307
eventID := c.Param("eventID")
317308
event, err := h.logStore.RetrieveEvent(c.Request.Context(), logstore.RetrieveEventRequest{
318309
TenantID: tenant.ID,
@@ -339,9 +330,6 @@ func (h *LogHandlers) RetrieveEvent(c *gin.Context) {
339330
// RetrieveAttempt handles GET /:tenantID/attempts/:attemptID
340331
func (h *LogHandlers) RetrieveAttempt(c *gin.Context) {
341332
tenant := mustTenantFromContext(c)
342-
if tenant == nil {
343-
return
344-
}
345333
attemptID := c.Param("attemptID")
346334

347335
attemptRecord, err := h.logStore.RetrieveAttempt(c.Request.Context(), logstore.RetrieveAttemptRequest{
@@ -378,9 +366,6 @@ func (h *LogHandlers) AdminListAttempts(c *gin.Context) {
378366
// Query params: destination_id, topic[], start, end, limit, next, prev, sort_order
379367
func (h *LogHandlers) ListEvents(c *gin.Context) {
380368
tenant := mustTenantFromContext(c)
381-
if tenant == nil {
382-
return
383-
}
384369
h.listEventsInternal(c, tenant.ID)
385370
}
386371

internal/apirouter/retry_handlers.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ func NewRetryHandlers(
3939
// - Destination must exist and be enabled
4040
func (h *RetryHandlers) RetryAttempt(c *gin.Context) {
4141
tenant := mustTenantFromContext(c)
42-
if tenant == nil {
43-
return
44-
}
4542
attemptID := c.Param("attemptID")
4643

4744
// 1. Look up attempt by ID

internal/apirouter/tenant_handlers.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ func (h *TenantHandlers) Upsert(c *gin.Context) {
9393

9494
func (h *TenantHandlers) Retrieve(c *gin.Context) {
9595
tenant := mustTenantFromContext(c)
96-
if tenant == nil {
97-
return
98-
}
9996
c.JSON(http.StatusOK, tenant)
10097
}
10198

@@ -162,12 +159,9 @@ func (h *TenantHandlers) List(c *gin.Context) {
162159
}
163160

164161
func (h *TenantHandlers) Delete(c *gin.Context) {
165-
tenantID := mustTenantIDFromContext(c)
166-
if tenantID == "" {
167-
return
168-
}
162+
tenant := mustTenantFromContext(c)
169163

170-
err := h.tenantStore.DeleteTenant(c.Request.Context(), tenantID)
164+
err := h.tenantStore.DeleteTenant(c.Request.Context(), tenant.ID)
171165
if err != nil {
172166
if err == tenantstore.ErrTenantNotFound {
173167
c.Status(http.StatusNotFound)
@@ -181,9 +175,6 @@ func (h *TenantHandlers) Delete(c *gin.Context) {
181175

182176
func (h *TenantHandlers) RetrieveToken(c *gin.Context) {
183177
tenant := mustTenantFromContext(c)
184-
if tenant == nil {
185-
return
186-
}
187178
jwtToken, err := JWT.New(h.jwtSecret, JWTClaims{
188179
TenantID: tenant.ID,
189180
DeploymentID: h.deploymentID,
@@ -197,9 +188,6 @@ func (h *TenantHandlers) RetrieveToken(c *gin.Context) {
197188

198189
func (h *TenantHandlers) RetrievePortal(c *gin.Context) {
199190
tenant := mustTenantFromContext(c)
200-
if tenant == nil {
201-
return
202-
}
203191
jwtToken, err := JWT.New(h.jwtSecret, JWTClaims{
204192
TenantID: tenant.ID,
205193
DeploymentID: h.deploymentID,

0 commit comments

Comments
 (0)