perf: include permissions in api list response

This commit is contained in:
Elias Schneider
2026-07-07 11:38:59 +02:00
parent 7667377c98
commit 8035a4c8d5
6 changed files with 12 additions and 27 deletions
-9
View File
@@ -20,15 +20,6 @@ type apiPermissionResponseDto struct {
Description *string `json:"description,omitempty"`
}
// apiListItemDto is the lightweight representation used in list responses
type apiListItemDto struct {
ID string `json:"id"`
Name string `json:"name"`
Resource string `json:"resource"`
CreatedAt datatype.DateTime `json:"createdAt"`
PermissionCount int `json:"permissionCount"`
}
// apiCreateDto is the payload for creating an API
// The resource identifier is only accepted here because changing it later would invalidate every token already minted for the API
type apiCreateDto struct {
+3 -4
View File
@@ -39,19 +39,18 @@ func (h *handler) list(c *gin.Context) {
return
}
items := make([]apiListItemDto, len(apis))
items := make([]apiResponseDto, len(apis))
for i, api := range apis {
var item apiListItemDto
var item apiResponseDto
if err := dto.MapStruct(api, &item); err != nil {
_ = c.Error(err)
return
}
item.Resource = api.Audience
item.PermissionCount = len(api.Permissions)
items[i] = item
}
c.JSON(http.StatusOK, dto.Paginated[apiListItemDto]{
c.JSON(http.StatusOK, dto.Paginated[apiResponseDto]{
Data: items,
Pagination: pagination,
})