|
| 1 | +import { initContract } from '@ts-rest/core'; |
| 2 | +import { |
| 3 | + searchAllBooksQuerySchema, |
| 4 | + searchAllBooksResponseSchema, |
| 5 | + searchBookByIdResponseSchema, |
| 6 | + pubdateFormatErrorSchema, |
| 7 | + updateBookBodySchema, |
| 8 | + updateBookResponseSchema, |
| 9 | + unknownPatchErrorSchema, |
| 10 | + nonDataErrorSchema, |
| 11 | + searchBookInfoByIdResponseSchema, |
| 12 | + searchBookInfoByIdPathSchema, |
| 13 | + searchBookByIdParamSchema, |
| 14 | +} from './schema'; |
| 15 | +import { badRequestSchema, bookInfoNotFoundSchema, bookNotFoundSchema } from '../shared'; |
| 16 | + |
| 17 | +const c = initContract(); |
| 18 | + |
| 19 | +export const bookMetasContracts = c.router( |
| 20 | + { |
| 21 | + getById: { |
| 22 | + method: 'GET', |
| 23 | + path: '/info/:id', |
| 24 | + pathParams: searchBookInfoByIdPathSchema, |
| 25 | + summary: '도서 정보를 조회합니다.', |
| 26 | + responses: { |
| 27 | + 200: searchBookInfoByIdResponseSchema, |
| 28 | + 404: bookInfoNotFoundSchema, |
| 29 | + }, |
| 30 | + }, |
| 31 | + }, |
| 32 | + { pathPrefix: '/bookmetas' }, |
| 33 | +); |
| 34 | + |
| 35 | +export const booksContract = c.router( |
| 36 | + { |
| 37 | + getById: { |
| 38 | + method: 'GET', |
| 39 | + path: '/:id', |
| 40 | + summary: 'book테이블의 ID기준으로 책 한 종류의 정보를 가져온다.', |
| 41 | + pathParams: searchBookByIdParamSchema, |
| 42 | + responses: { |
| 43 | + 200: searchBookByIdResponseSchema, |
| 44 | + 404: bookNotFoundSchema, |
| 45 | + }, |
| 46 | + }, |
| 47 | + get: { |
| 48 | + method: 'GET', |
| 49 | + path: '/', |
| 50 | + summary: '개별 책 정보(book)를 검색하여 가져온다. 책이 대출할 수 있는지 확인 할 수 있음', |
| 51 | + query: searchAllBooksQuerySchema, |
| 52 | + responses: { |
| 53 | + 200: searchAllBooksResponseSchema, |
| 54 | + 400: badRequestSchema, |
| 55 | + }, |
| 56 | + }, |
| 57 | + patch: { |
| 58 | + method: 'PATCH', |
| 59 | + path: '/update', |
| 60 | + summary: '책 정보 하나를 수정합니다.', |
| 61 | + body: updateBookBodySchema, |
| 62 | + responses: { |
| 63 | + 204: updateBookResponseSchema, |
| 64 | + 312: unknownPatchErrorSchema, |
| 65 | + 313: nonDataErrorSchema, |
| 66 | + 311: pubdateFormatErrorSchema, |
| 67 | + }, |
| 68 | + }, |
| 69 | + }, |
| 70 | + { pathPrefix: '/books' }, |
| 71 | +); |
0 commit comments