11import { Hono } from "hono" ;
22import type { HonoContext } from "../../types/env" ;
3+ import type { BookId } from "../../types/domain" ;
34import { bookRepo , bookTagRepo } from "../db/repositories" ;
45import { authMiddleware } from "../lib/auth" ;
56import { validator , getValidated } from "../lib/validator" ;
@@ -46,10 +47,6 @@ app.get("/", validator("query", bookFilterSchema), async (c) => {
4647 return paginatedResponse ( c , items , total , filter . limit ?? 20 , filter . offset ?? 0 ) ;
4748} ) ;
4849
49- /**
50- * 書籍詳細取得
51- * GET /api/books/:id
52- */
5350/**
5451 * 書籍統計取得
5552 * GET /api/books/stats
@@ -69,8 +66,8 @@ app.get("/:id", validator("param", bookIdSchema), async (c) => {
6966 const userId = c . get ( "userId" ) ;
7067 const { id } = getValidated < { id : string } > ( c , "param" ) ;
7168
72- const book = await bookRepo . findById ( c . env . DB , id , userId ) ;
73- const tags = await bookTagRepo . findTagsByBookId ( c . env . DB , id ) ;
69+ const book = await bookRepo . findById ( c . env . DB , id as BookId , userId ) ;
70+ const tags = await bookTagRepo . findTagsByBookId ( c . env . DB , id as BookId ) ;
7471
7572 return successResponse ( c , {
7673 ...toBookResponse ( book ) ,
@@ -106,7 +103,7 @@ app.put(
106103 const data = getValidated < UpdateBookInput > ( c , "json" ) ;
107104
108105 const updateData = toBookUpdateInput ( data ) ;
109- const book = await bookRepo . update ( c . env . DB , id , userId , updateData ) ;
106+ const book = await bookRepo . update ( c . env . DB , id as BookId , userId , updateData ) ;
110107
111108 return successResponse ( c , toBookResponse ( book ) ) ;
112109 } ,
@@ -126,7 +123,7 @@ app.patch(
126123 const { currentPage } = getValidated < ProgressInput > ( c , "json" ) ;
127124
128125 // 書籍を取得してページ数を検証
129- const existingBook = await bookRepo . findById ( c . env . DB , id , userId ) ;
126+ const existingBook = await bookRepo . findById ( c . env . DB , id as BookId , userId ) ;
130127 const validation = bookDomain . validatePageProgress ( currentPage , existingBook . page_count ) ;
131128
132129 if ( ! validation . valid ) {
@@ -141,7 +138,7 @@ app.patch(
141138 ? new Date ( ) . toISOString ( )
142139 : existingBook . finished_at ;
143140
144- const book = await bookRepo . update ( c . env . DB , id , userId , {
141+ const book = await bookRepo . update ( c . env . DB , id as BookId , userId , {
145142 currentPage : currentPage ,
146143 status : newStatus ,
147144 finishedAt,
@@ -160,7 +157,7 @@ app.delete("/:id", validator("param", bookIdSchema), async (c) => {
160157 const userId = c . get ( "userId" ) ;
161158 const { id } = getValidated < { id : string } > ( c , "param" ) ;
162159
163- await bookRepo . deleteById ( c . env . DB , id , userId ) ;
160+ await bookRepo . deleteById ( c . env . DB , id as BookId , userId ) ;
164161
165162 return successResponse ( c , { deleted : true } ) ;
166163} ) ;
0 commit comments