Skip to content

Commit

Permalink
fix: remove unnecessary routes (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
laminne authored Jul 27, 2024
1 parent f455e15 commit b8f3675
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 94 deletions.
44 changes: 1 addition & 43 deletions pkg/timeline/mod.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
import { OpenAPIHono } from '@hono/zod-openapi';
import { Option, Result } from '@mikuroxina/mini-fn';
import { Result } from '@mikuroxina/mini-fn';

import type { AccountID } from '../accounts/model/account.js';
import { SnowflakeIDGenerator } from '../id/mod.js';
import { accountModule } from '../intermodule/account.js';
import { Note, type NoteID } from '../notes/model/note.js';
import { TimelineController } from './adaptor/controller/timeline.js';
import {
InMemoryListRepository,
InMemoryTimelineRepository,
} from './adaptor/repository/dummy.js';
import { InMemoryTimelineCacheRepository } from './adaptor/repository/dummyCache.js';
import {
CreateListRoute,
DeleteListRoute,
GetAccountTimelineRoute,
GetListMemberRoute,
PushNoteToTimelineRoute,
} from './router.js';
import { AccountTimelineService } from './service/account.js';
import { CreateListService } from './service/createList.js';
import { DeleteListService } from './service/deleteList.js';
import { FetchListMemberService } from './service/fetchMember.js';
import { NoteVisibilityService } from './service/noteVisibility.js';
import { PushTimelineService } from './service/push.js';

const idGenerator = new SnowflakeIDGenerator(0, {
now: () => BigInt(Date.now()),
});

const timelineRepository = new InMemoryTimelineRepository();
const listRepository = new InMemoryListRepository();
const timelineNotesCacheRepository = new InMemoryTimelineCacheRepository();
const noteVisibilityService = new NoteVisibilityService(accountModule);

const controller = new TimelineController({
Expand All @@ -44,13 +38,6 @@ const controller = new TimelineController({
accountModule,
fetchMemberService: new FetchListMemberService(listRepository, accountModule),
});
const pushTimelineService = new PushTimelineService(
accountModule,
noteVisibilityService,
timelineNotesCacheRepository,
);

export type TimelineModuleHandlerType = typeof pushNoteToTimeline;

export const timeline = new OpenAPIHono().doc('/timeline/doc.json', {
openapi: '3.0.0',
Expand Down Expand Up @@ -78,35 +65,6 @@ timeline.openapi(GetAccountTimelineRoute, async (c) => {
return c.json(res[1], 200);
});

// ToDo: Require internal access token in this endpoint
// NOTE: This is internal endpoint
const pushNoteToTimeline = timeline.openapi(
PushNoteToTimelineRoute,
async (c) => {
const { id, authorId } = c.req.valid('json');
const res = await pushTimelineService.handle(
Note.new({
id: id as NoteID,
authorID: authorId as AccountID,
content: '',
contentsWarningComment: '',
createdAt: new Date(),
originalNoteID: Option.none(),
sendTo: Option.none(),
attachmentFileID: [],
visibility: 'FOLLOWERS',
}),
);
if (Result.isErr(res)) {
return c.json({ error: res[1].message, status: 400 });
}

return new Response(undefined, { status: 204 });
},
);

// ToDo: impl DropNoteFromTimelineRoute

timeline.openapi(CreateListRoute, async (c) => {
// NOTE: `public` is a reserved keyword
const req = c.req.valid('json');
Expand Down
51 changes: 0 additions & 51 deletions pkg/timeline/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,57 +62,6 @@ export const GetAccountTimelineRoute = createRoute({
},
});

export const PushNoteToTimelineRoute = createRoute({
method: 'post',
description: '',
tags: ['timeline'],
path: '/timeline/',
request: {
body: {
content: {
'application/json': {
schema: z.object({
id: z.string(),
authorId: z.string(),
}),
},
},
},
},
responses: {
204: {
description: 'OK',
},
},
});

export const DropNoteFromTimelineRoute = createRoute({
method: 'delete',
description: '',
tags: ['timeline'],
path: '/timeline/:id',
request: {
body: {
content: {
'application/json': {
schema: z.object({}),
},
},
},
params: z.object({
id: z.string().openapi('note authorID'),
}),
},
responses: {
204: {
description: 'OK',
},
500: {
description: 'Task failed',
},
},
});

export const CreateListRoute = createRoute({
method: 'post',
tags: ['timeline'],
Expand Down

0 comments on commit b8f3675

Please sign in to comment.