Skip to content

Commit

Permalink
enhance: APIの型を整備
Browse files Browse the repository at this point in the history
  • Loading branch information
kakkokari-gtyih committed Jan 16, 2025
1 parent f47a94a commit 528dfc9
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 16 deletions.
14 changes: 13 additions & 1 deletion packages/backend/src/server/api/endpoints/notes/drafts/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ export const meta = {

kind: 'write:account',

res: {
type: 'object',
optional: false, nullable: false,
properties: {
createdDraft: {
type: 'object',
optional: false, nullable: false,
ref: 'NoteDraft',
},
},
},

errors: {
noSuchRenoteTarget: {
message: 'No such renote target.',
Expand Down Expand Up @@ -329,7 +341,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
});

return {
draft,
createdDraft: draft,
};
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}

await this.noteDraftService.delete(me, draft.id);

return { message: 'success' };
});
}
}
10 changes: 10 additions & 0 deletions packages/backend/src/server/api/endpoints/notes/drafts/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ export const meta = {

kind: 'read:account',

res: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
ref: 'NoteDraft',
},
},

errors: {
},
} as const;
Expand Down
18 changes: 17 additions & 1 deletion packages/backend/src/server/api/endpoints/notes/drafts/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { isRenote, isQuote } from '@/misc/is-renote.js';
import type { MiUser } from '@/models/User.js';
import { DI } from '@/di-symbols.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { NoteDraftEntityService } from '@/core/entities/NoteDraftEntityService.js';
import { ApiError } from '../../../error.js';

export const meta = {
Expand All @@ -26,6 +27,18 @@ export const meta = {

kind: 'write:account',

res: {
type: 'object',
optional: false, nullable: false,
properties: {
updatedDraft: {
type: 'object',
optional: false, nullable: false,
ref: 'NoteDraft',
},
},
},

errors: {
noSuchRenoteTarget: {
message: 'No such renote target.',
Expand Down Expand Up @@ -202,6 +215,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-

private noteEntityService: NoteEntityService,
private noteDraftService: NoteDraftService,
private noteDraftEntityService: NoteDraftEntityService,
) {
super(meta, paramDef, async (ps, me) => {
const draft = await this.noteDraftService.get(me, ps.draftId);
Expand Down Expand Up @@ -353,8 +367,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
channel,
});

const updatedDraft = await this.noteDraftEntityService.pack(draft, me);

return {
draft,
updatedDraft,
};
});
}
Expand Down
12 changes: 12 additions & 0 deletions packages/misskey-js/etc/misskey-js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1691,8 +1691,11 @@ declare namespace entities {
NotesUserListTimelineRequest,
NotesUserListTimelineResponse,
NotesDraftsRequest,
NotesDraftsResponse,
NotesDraftsCreateRequest,
NotesDraftsCreateResponse,
NotesDraftsUpdateRequest,
NotesDraftsUpdateResponse,
NotesDraftsDeleteRequest,
NotificationsCreateRequest,
PagePushRequest,
Expand Down Expand Up @@ -2701,15 +2704,24 @@ type NotesDeleteRequest = operations['notes___delete']['requestBody']['content']
// @public (undocumented)
type NotesDraftsCreateRequest = operations['notes___drafts___create']['requestBody']['content']['application/json'];

// @public (undocumented)
type NotesDraftsCreateResponse = operations['notes___drafts___create']['responses']['200']['content']['application/json'];

// @public (undocumented)
type NotesDraftsDeleteRequest = operations['notes___drafts___delete']['requestBody']['content']['application/json'];

// @public (undocumented)
type NotesDraftsRequest = operations['notes___drafts']['requestBody']['content']['application/json'];

// @public (undocumented)
type NotesDraftsResponse = operations['notes___drafts']['responses']['200']['content']['application/json'];

// @public (undocumented)
type NotesDraftsUpdateRequest = operations['notes___drafts___update']['requestBody']['content']['application/json'];

// @public (undocumented)
type NotesDraftsUpdateResponse = operations['notes___drafts___update']['responses']['200']['content']['application/json'];

// @public (undocumented)
type NotesFavoritesCreateRequest = operations['notes___favorites___create']['requestBody']['content']['application/json'];

Expand Down
9 changes: 6 additions & 3 deletions packages/misskey-js/src/autogen/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,11 @@ import type {
NotesUserListTimelineRequest,
NotesUserListTimelineResponse,
NotesDraftsRequest,
NotesDraftsResponse,
NotesDraftsCreateRequest,
NotesDraftsCreateResponse,
NotesDraftsUpdateRequest,
NotesDraftsUpdateResponse,
NotesDraftsDeleteRequest,
NotificationsCreateRequest,
PagePushRequest,
Expand Down Expand Up @@ -892,9 +895,9 @@ export type Endpoints = {
'notes/translate': { req: NotesTranslateRequest; res: NotesTranslateResponse };
'notes/unrenote': { req: NotesUnrenoteRequest; res: EmptyResponse };
'notes/user-list-timeline': { req: NotesUserListTimelineRequest; res: NotesUserListTimelineResponse };
'notes/drafts': { req: NotesDraftsRequest; res: EmptyResponse };
'notes/drafts/create': { req: NotesDraftsCreateRequest; res: EmptyResponse };
'notes/drafts/update': { req: NotesDraftsUpdateRequest; res: EmptyResponse };
'notes/drafts': { req: NotesDraftsRequest; res: NotesDraftsResponse };
'notes/drafts/create': { req: NotesDraftsCreateRequest; res: NotesDraftsCreateResponse };
'notes/drafts/update': { req: NotesDraftsUpdateRequest; res: NotesDraftsUpdateResponse };
'notes/drafts/delete': { req: NotesDraftsDeleteRequest; res: EmptyResponse };
'notifications/create': { req: NotificationsCreateRequest; res: EmptyResponse };
'notifications/flush': { req: EmptyRequest; res: EmptyResponse };
Expand Down
3 changes: 3 additions & 0 deletions packages/misskey-js/src/autogen/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,11 @@ export type NotesUnrenoteRequest = operations['notes___unrenote']['requestBody']
export type NotesUserListTimelineRequest = operations['notes___user-list-timeline']['requestBody']['content']['application/json'];
export type NotesUserListTimelineResponse = operations['notes___user-list-timeline']['responses']['200']['content']['application/json'];
export type NotesDraftsRequest = operations['notes___drafts']['requestBody']['content']['application/json'];
export type NotesDraftsResponse = operations['notes___drafts']['responses']['200']['content']['application/json'];
export type NotesDraftsCreateRequest = operations['notes___drafts___create']['requestBody']['content']['application/json'];
export type NotesDraftsCreateResponse = operations['notes___drafts___create']['responses']['200']['content']['application/json'];
export type NotesDraftsUpdateRequest = operations['notes___drafts___update']['requestBody']['content']['application/json'];
export type NotesDraftsUpdateResponse = operations['notes___drafts___update']['responses']['200']['content']['application/json'];
export type NotesDraftsDeleteRequest = operations['notes___drafts___delete']['requestBody']['content']['application/json'];
export type NotificationsCreateRequest = operations['notifications___create']['requestBody']['content']['application/json'];
export type PagePushRequest = operations['page-push']['requestBody']['content']['application/json'];
Expand Down
28 changes: 19 additions & 9 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23486,9 +23486,11 @@ export type operations = {
};
};
responses: {
/** @description OK (without any results) */
204: {
content: never;
/** @description OK (with results) */
200: {
content: {
'application/json': components['schemas']['NoteDraft'][];
};
};
/** @description Client error */
400: {
Expand Down Expand Up @@ -23565,9 +23567,13 @@ export type operations = {
};
};
responses: {
/** @description OK (without any results) */
204: {
content: never;
/** @description OK (with results) */
200: {
content: {
'application/json': {
createdDraft: components['schemas']['NoteDraft'];
};
};
};
/** @description Client error */
400: {
Expand Down Expand Up @@ -23652,9 +23658,13 @@ export type operations = {
};
};
responses: {
/** @description OK (without any results) */
204: {
content: never;
/** @description OK (with results) */
200: {
content: {
'application/json': {
updatedDraft: components['schemas']['NoteDraft'];
};
};
};
/** @description Client error */
400: {
Expand Down

0 comments on commit 528dfc9

Please sign in to comment.