Skip to content

Commit 2e1da22

Browse files
committed
feat: 어드민 API의 수정 심사 관련 API 추가
1 parent eed1274 commit 2e1da22

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

packages/common/src/apis/admin_api.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,29 @@ namespace BackendAdminAPIs {
7777
`v1/admin-api/cms/page/${pageId}/section/bulk-update/`,
7878
data
7979
);
80+
81+
export const approveModificationAudit = (client: BackendAPIClient, id: string) => (reason?: string | null) =>
82+
client.patch<BackendAdminAPISchemas.ModificationAuditSchema, { reason?: string | null }>(
83+
`v1/admin-api/modification-audit/modification-audit/${id}/approve/`,
84+
{ reason: reason ?? null }
85+
);
86+
87+
export const rejectModificationAudit = (client: BackendAPIClient, id: string) => (reason?: string | null) =>
88+
client.patch<BackendAdminAPISchemas.ModificationAuditSchema, { reason?: string | null }>(
89+
`v1/admin-api/modification-audit/modification-audit/${id}/reject/`,
90+
{ reason: reason ?? null }
91+
);
92+
93+
export const previewModificationAudit =
94+
<T>(client: BackendAPIClient, app: string, resource: string, instanceId: string, auditId: string) =>
95+
async () => {
96+
try {
97+
return await client.get<T>(`v1/admin-api/${app}/${resource}/${instanceId}/preview/${auditId}/`);
98+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
99+
} catch (_) {
100+
return null;
101+
}
102+
};
80103
}
81104

82105
export default BackendAdminAPIs;

packages/common/src/hooks/useAdminAPI.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ const MUTATION_KEYS = {
1919
ADMIN_CREATE: ["mutation", "admin", "create"],
2020
ADMIN_UPDATE: ["mutation", "admin", "update"],
2121
ADMIN_REMOVE: ["mutation", "admin", "remove"],
22+
ADMIN_APPROVE_MODIFICATION_AUDIT: ["mutation", "admin", "approve", "modification-audit"],
23+
ADMIN_REJECT_MODIFICATION_AUDIT: ["mutation", "admin", "reject", "modification-audit"],
2224
};
2325

2426
namespace BackendAdminAPIHooks {
@@ -122,6 +124,30 @@ namespace BackendAdminAPIHooks {
122124
mutationKey: [...MUTATION_KEYS.ADMIN_UPDATE, "cms", "page", pageId, "section"],
123125
mutationFn: BackendAdminAPIs.bulkUpdateSections(client, pageId),
124126
});
127+
128+
export const useApproveModificationAuditMutation = (client: BackendAPIClient, id: string) =>
129+
useMutation({
130+
mutationKey: MUTATION_KEYS.ADMIN_APPROVE_MODIFICATION_AUDIT,
131+
mutationFn: BackendAdminAPIs.approveModificationAudit(client, id),
132+
});
133+
134+
export const useRejectModificationAuditMutation = (client: BackendAPIClient, id: string) =>
135+
useMutation({
136+
mutationKey: MUTATION_KEYS.ADMIN_REJECT_MODIFICATION_AUDIT,
137+
mutationFn: BackendAdminAPIs.rejectModificationAudit(client, id),
138+
});
139+
140+
export const useModificationAuditPreviewRetrieveQuery = <T>(
141+
client: BackendAPIClient,
142+
app: string,
143+
resource: string,
144+
instanceId: string,
145+
auditId: string
146+
) =>
147+
useSuspenseQuery({
148+
queryKey: [...QUERY_KEYS.ADMIN_RETRIEVE, app, resource, instanceId, "preview", auditId],
149+
queryFn: BackendAdminAPIs.previewModificationAudit<T>(client, app, resource, instanceId, auditId),
150+
});
125151
}
126152

127153
export default BackendAdminAPIHooks;

packages/common/src/schemas/backendAdminAPI.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,44 @@ namespace BackendAdminAPISchemas {
8282
};
8383

8484
export type PageSectionBulkUpdateSchema = PageSectionSchema | Omit<PageSectionSchema, "id">;
85+
86+
export type PresentationSchema = {
87+
id: string; // UUID
88+
type: string; // UUID of the presentation type
89+
categories: string[]; // Array of category UUIDs
90+
title_ko: string;
91+
title_en: string;
92+
summary_ko: string;
93+
summary_en: string;
94+
description_ko: string;
95+
description_en: string;
96+
image: string | null;
97+
};
98+
99+
export type ModificationAuditSchema = {
100+
id: string; // UUID
101+
status: "requested" | "approved" | "rejected" | "cancelled"; // Status of the modification request
102+
created_at: string; // ISO 8601 timestamp
103+
updated_at: string; // ISO 8601 timestamp
104+
modification_data: string; // JSON string containing the modification data
105+
str_repr: string; // String representation of the modification audit, e.g., "Presentation Title - Status"
106+
comments: {
107+
id: string; // UUID of the comment
108+
content: string; // Content of the comment
109+
created_at: string; // ISO 8601 timestamp
110+
created_by: {
111+
id: number; // User ID of the commenter
112+
nickname: string; // Nickname of the commenter
113+
is_superuser: boolean; // Whether the commenter is a staff member
114+
};
115+
updated_at: string; // ISO 8601 timestamp
116+
}[];
117+
instance: {
118+
app: string;
119+
model: string;
120+
id: string; // UUID of the instance being modified, e.g., presentation ID
121+
};
122+
};
85123
}
86124

87125
export default BackendAdminAPISchemas;

0 commit comments

Comments
 (0)