Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ニュースのエンドポイント変更 #153

Merged
merged 1 commit into from
Feb 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions backend/src/controllers/News/newsTankaHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { z, type RouteHandler } from '@hono/zod-openapi';
import type { Context } from 'hono';
import { newsTankaSchema } from '../../schema/News/newsTankaSchema.js';
import type { newsTankaRoute } from '../../routes/News/newsTankaRoute.js';
import postNews from '../../lib/postNews.js';

type newsTankaSchema = z.infer<typeof newsTankaSchema>;

const newsTankaHandler: RouteHandler<typeof newsTankaRoute, {}> = async (c: Context) => {
const { apiKey } = await c.req.json<newsTankaSchema>();

/* --- 色々処理 --- */

const response = await postNews(apiKey);
console.log(response);

// レスポンス
return c.json(response, 200);
};

export default newsTankaHandler;
23 changes: 0 additions & 23 deletions backend/src/controllers/Sample/sampleNewsTankaHandler.ts

This file was deleted.

38 changes: 38 additions & 0 deletions backend/src/routes/News/newsTankaRoute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { z } from '@hono/zod-openapi';
import { createRoute } from '@hono/zod-openapi';
import { newsTankaResponseSchema, newsTankaSchema } from '../../schema/News/newsTankaSchema.js';
import { errorResponseSchema } from '../../middleware/errorHandler.js';

type newsTankaSchema = z.infer<typeof newsTankaSchema>;

export const newsTankaRoute = createRoute({
method: 'post',
path: '/news',
tags: ['news'],
request: {
body: {
required: true,
content: {
'application/json': {
schema: newsTankaSchema,
},
},
},
},
responses: {
200: {
content: {
'application/json': {
schema: newsTankaResponseSchema,
},
},
description: 'Successful response',
},
},
});

export type NewsTankaRouteResponse200 = z.infer<
(typeof newsTankaRoute.responses)['200']['content']['application/json']['schema']
>;

export type NewsTankaRouteResponseError = z.infer<typeof errorResponseSchema>;
41 changes: 0 additions & 41 deletions backend/src/routes/Sample/sampleNewsTankaRoute.ts

This file was deleted.

6 changes: 3 additions & 3 deletions backend/src/routes/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import { sampleS3DownloadRoute } from './sampleS3Route.js';
import sampleS3DownloadHandler from '../controllers/sampleS3DownloadHandler.js';
import { sampleGeminiRoute } from './Sample/sampleGeminiRoute.js';
import sampleGeminiHandler from '../controllers/Sample/sampleGeminiHandler.js';
import { sampleNewsTankaRoute } from './Sample/sampleNewsTankaRoute.js';
import sampleNewsTankaHandler from '../controllers/Sample/sampleNewsTankaHandler.js';
import { newsTankaRoute } from './News/newsTankaRoute.js';
import newsTankaHandler from '../controllers/News/newsTankaHandler.js';

const router = new OpenAPIHono();

Expand All @@ -50,5 +50,5 @@ export default router
.openapi(sampleS3UploadRoute, sampleS3UploadHandler)
.openapi(sampleS3DownloadRoute, sampleS3DownloadHandler)
.openapi(sampleGeminiRoute, sampleGeminiHandler)
.openapi(sampleNewsTankaRoute, sampleNewsTankaHandler);
.openapi(newsTankaRoute, newsTankaHandler);
// .openapi(helloRoute, helloWorldHandler); //こういう感じで足していく
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { z } from '@hono/zod-openapi';

export const sampleNewsTankaSchema = z.object({
export const newsTankaSchema = z.object({
apiKey: z.string().openapi({
example: 'abc123',
description: 'APIキー',
}),
});

export const sampleNewsTankaResponseSchema = z.object({
export const newsTankaResponseSchema = z.object({
isSuccess: z.boolean().openapi({
example: true,
description: '短歌の生成に成功したかどうか',
Expand Down
Loading