mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-09-25 20:39:04 +02:00
perf: include permissions in api list response
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user