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

feat:GET /sponsorを実装 #644

Merged
merged 5 commits into from
Oct 31, 2024
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
2 changes: 2 additions & 0 deletions packages/kcms/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { trimTrailingSlash } from 'hono/trailing-slash';
import { matchHandler } from './match/main';
import { sponsorHandler } from './sponser/main';
import { teamHandler } from './team/main.js';

const app = new Hono();
Expand All @@ -15,6 +16,7 @@ app.use('*', cors());
app.use(trimTrailingSlash());
app.route('/', teamHandler);
app.route('/', matchHandler);
app.route('/', sponsorHandler);

// ToDo: config packageのTS読み込み問題により、一時的にBunで直接TSを実行する形に変更した
export default {
Expand Down
10 changes: 10 additions & 0 deletions packages/kcms/src/sponser/adaptor/controller/sponsor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { z } from '@hono/zod-openapi';
import { Result } from '@mikuroxina/mini-fn';
import { config } from 'config';
import { GetSponsorResponseSchema } from '../validator/sponsor';

export class SponsorController {
getAll(): Result.Result<Error, z.infer<typeof GetSponsorResponseSchema>> {
return Result.ok({ sponsor: config.sponsors });
}
}
15 changes: 15 additions & 0 deletions packages/kcms/src/sponser/adaptor/validator/sponsor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { z } from '@hono/zod-openapi';

export const CommonErrorSchema = z.object({
description: z.string().openapi({ example: '存在しないカテゴリです' }),
tufusa marked this conversation as resolved.
Show resolved Hide resolved
});

const sponsorSchema = z.object({
name: z.string().openapi({ example: 'team Poporon Network' }),
class: z.string().openapi({ example: 'Gold' }),
url: z.string().url().openapi({ example: 'https://cdn.example.com/poporonnet.png' }),
});

export const GetSponsorResponseSchema = z.object({
sponsor: z.array(sponsorSchema),
});
13 changes: 13 additions & 0 deletions packages/kcms/src/sponser/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { OpenAPIHono } from '@hono/zod-openapi';
import { Result } from '@mikuroxina/mini-fn';
import { SponsorController } from './adaptor/controller/sponsor';
import { GetSponsorRoute } from './routing';

export const sponsorHandler = new OpenAPIHono();
const sponsorController = new SponsorController();

sponsorHandler.openapi(GetSponsorRoute, (c) => {
const sponsors = sponsorController.getAll();
if (Result.isErr(sponsors)) return c.json({ description: sponsors[1].message }, 400);
return c.json(Result.unwrap(sponsors), 200);
});
25 changes: 25 additions & 0 deletions packages/kcms/src/sponser/routing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { createRoute } from '@hono/zod-openapi';
import { CommonErrorSchema, GetSponsorResponseSchema } from './adaptor/validator/sponsor';

export const GetSponsorRoute = createRoute({
method: 'get',
path: '/sponsor',
responses: {
200: {
content: {
'application/json': {
schema: GetSponsorResponseSchema,
},
},
description: 'Get all sponsor inf',
},
400: {
content: {
'application/json': {
schema: CommonErrorSchema,
},
},
description: 'Common error',
},
},
});