Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | // hono instance
import honoFactory from '../factory/hono';
// validator
import { getUserProfileResponseSchema, updateUserProfileRequestSchema } from 'validator';
// error schema
import { route } from '../share/error';
// application layer use cases
import { getUserProfileUseCase, updateUserProfileUseCase } from '../../application/userProfile';
const hono = honoFactory();
// NOTE: userProfileの取得
const getUserProfileSchema = route.createSchema(
{
path: '/api/profile',
method: 'get',
description: 'ログインユーザーのプロフィール情報を取得するエンドポイント',
security: [{ SessionCookie: [] }],
request: {},
responses: {
200: {
description: 'OK',
content: {
'application/json': {
schema: getUserProfileResponseSchema,
},
},
},
},
},
[401, 404, 500] as const
);
hono.openapi(getUserProfileSchema, async (c) => {
const loginUser = c.get('user');
// ビジネスロジック呼び出し
const response = await getUserProfileUseCase(c.env, loginUser.id);
// レスポンス
return c.json(response, 200);
});
// NOTE: userProfileの更新
const updateUserProfileSchema = route.createSchema(
{
path: '/api/profile',
method: 'patch',
description: 'ログインユーザーのプロフィール情報を更新するエンドポイント',
security: [{ SessionCookie: [] }],
request: {
body: {
required: true,
content: {
'application/json': {
schema: updateUserProfileRequestSchema,
},
},
},
},
responses: {
204: {
description: 'No Content',
},
},
},
[400, 401, 500] as const
);
hono.openapi(updateUserProfileSchema, async (c) => {
const loginUser = c.get('user');
const body = c.req.valid('json');
// ビジネスロジック呼び出し
await updateUserProfileUseCase(c.env, loginUser.id, body.display_name);
// レスポンス
return c.body(null, 204);
});
export default hono;
|