mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-07-15 19:53:58 +03: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,
|
||||
})
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type {
|
||||
Api,
|
||||
ApiCreate,
|
||||
ApiListItem,
|
||||
ApiPermissionInput,
|
||||
ApiUpdate,
|
||||
ClientApiAccess
|
||||
@@ -12,12 +11,12 @@ import APIService from './api-service';
|
||||
export default class ApisService extends APIService {
|
||||
list = async (options?: ListRequestOptions) => {
|
||||
const res = await this.api.get('/apis', { params: options });
|
||||
return res.data as Paginated<ApiListItem>;
|
||||
return res.data as Paginated<Api>;
|
||||
};
|
||||
|
||||
listAll = async () => {
|
||||
const res = await this.api.get('/apis', { params: { pagination: { page: 1, limit: 1000 } } });
|
||||
return (res.data as Paginated<ApiListItem>).data;
|
||||
return (res.data as Paginated<Api>).data;
|
||||
};
|
||||
|
||||
get = async (id: string) => {
|
||||
|
||||
@@ -13,10 +13,6 @@ export type Api = {
|
||||
permissions: ApiPermission[];
|
||||
};
|
||||
|
||||
export type ApiListItem = Omit<Api, 'permissions'> & {
|
||||
permissionCount: number;
|
||||
};
|
||||
|
||||
export type ApiCreate = {
|
||||
name: string;
|
||||
resource: string;
|
||||
|
||||
@@ -8,26 +8,26 @@
|
||||
AdvancedTableColumn,
|
||||
CreateAdvancedTableActions
|
||||
} from '$lib/types/advanced-table.type';
|
||||
import type { ApiListItem } from '$lib/types/api.type';
|
||||
import type { Api } from '$lib/types/api.type';
|
||||
import { axiosErrorToast } from '$lib/utils/error-util';
|
||||
import { LucidePencil, LucideTrash } from '@lucide/svelte';
|
||||
import { toast } from 'svelte-sonner';
|
||||
|
||||
const apisService = new ApisService();
|
||||
let tableRef: AdvancedTable<ApiListItem>;
|
||||
let tableRef: AdvancedTable<Api>;
|
||||
|
||||
export function refresh() {
|
||||
return tableRef?.refresh();
|
||||
}
|
||||
|
||||
const columns: AdvancedTableColumn<ApiListItem>[] = [
|
||||
const columns: AdvancedTableColumn<Api>[] = [
|
||||
{ label: 'ID', column: 'id', hidden: true },
|
||||
{ label: m.name(), column: 'name', sortable: true },
|
||||
{ label: m.api_resource(), column: 'resource', sortable: true },
|
||||
{ label: m.api_permissions(), key: 'permissionCount', value: (item) => item.permissionCount }
|
||||
{ label: m.api_permissions(), key: 'permissions', value: (item) => item.permissions.length }
|
||||
];
|
||||
|
||||
const actions: CreateAdvancedTableActions<ApiListItem> = (api) => [
|
||||
const actions: CreateAdvancedTableActions<Api> = (api) => [
|
||||
{
|
||||
label: m.edit(),
|
||||
primary: true,
|
||||
@@ -43,7 +43,7 @@
|
||||
}
|
||||
];
|
||||
|
||||
async function deleteApi(api: ApiListItem) {
|
||||
async function deleteApi(api: Api) {
|
||||
openConfirmDialog({
|
||||
title: m.delete_name({ name: api.name }),
|
||||
message: m.are_you_sure_you_want_to_delete_this_api(),
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
apisService.listAll(),
|
||||
apisService.getClientAccess(clientId)
|
||||
]);
|
||||
apis = await Promise.all(list.map((a) => apisService.get(a.id)));
|
||||
apis = list;
|
||||
userSelected = new Set(access.userDelegatedPermissionIds);
|
||||
clientSelected = new Set(access.clientPermissionIds);
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user