Skip to content

Commit

Permalink
fix: positiveInt -> nonNegativeInt (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
scarf005 authored Sep 11, 2023
1 parent c88ca8d commit 1565441
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 85 deletions.
50 changes: 25 additions & 25 deletions contracts/src/books/schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
metaSchema,
positiveInt,
nonNegativeInt,
mkErrorMessageSchema,
statusSchema,
metaPaginatedSchema,
Expand All @@ -10,8 +10,8 @@ import { z } from '../zodWithOpenapi';

export const commonQuerySchema = z.object({
query: z.string().optional(),
page: positiveInt.default(0).openapi({ example: 0 }),
limit: positiveInt.default(10).openapi({ example: 10 }),
page: nonNegativeInt.default(0).openapi({ example: 0 }),
limit: nonNegativeInt.default(10).openapi({ example: 10 }),
});

export const searchAllBookInfosQuerySchema = commonQuerySchema.extend({
Expand All @@ -27,11 +27,11 @@ export const searchBookInfosByTagQuerySchema = commonQuerySchema.extend({

export const searchBookInfosSortedQuerySchema = z.object({
sort: z.enum(['new', 'popular']),
limit: positiveInt.default(10).openapi({ example: 10 }),
limit: nonNegativeInt.default(10).openapi({ example: 10 }),
});

export const searchBookInfoByIdPathSchema = z.object({
id: positiveInt,
id: nonNegativeInt,
});

export const searchAllBooksQuerySchema = commonQuerySchema;
Expand All @@ -52,29 +52,29 @@ export const createBookBodySchema = z.object({
});

export const searchBookByIdParamSchema = z.object({
id: positiveInt,
id: nonNegativeInt,
});

export const updateBookBodySchema = z.object({
bookInfoId: positiveInt.optional(),
bookInfoId: nonNegativeInt.optional(),
title: z.string().optional(),
author: z.string().optional(),
publisher: z.string().optional(),
publishedAt: z.string().optional(),
image: z.string().optional(),
categoryId: positiveInt.optional(),
bookId: positiveInt.optional(),
categoryId: nonNegativeInt.optional(),
bookId: nonNegativeInt.optional(),
callSign: z.string().optional(),
status: statusSchema.optional(),
});

export const updateDonatorBodySchema = z.object({
bookId: positiveInt,
bookId: nonNegativeInt,
nickname: z.string(),
});

export const bookInfoSchema = z.object({
id: positiveInt,
id: nonNegativeInt,
title: z.string(),
author: z.string(),
publisher: z.string(),
Expand All @@ -98,7 +98,7 @@ export const searchBookInfosResponseSchema = metaPaginatedSchema(
categories: z.array(
z.object({
name: z.string(),
count: positiveInt,
count: nonNegativeInt,
}),
),
});
Expand All @@ -107,29 +107,29 @@ export const searchBookInfosSortedResponseSchema = z.object({
items: z.array(
bookInfoSchema.extend({
publishedAt: dateLike,
lendingCnt: positiveInt,
lendingCnt: nonNegativeInt,
}),
),
});

export const searchBookInfoByIdResponseSchema = bookInfoSchema.extend({
books: z.array(
z.object({
id: positiveInt,
id: nonNegativeInt,
callSign: z.string(),
donator: z.string(),
status: statusSchema,
dueDate: dateLike,
isLendable: positiveInt,
isReserved: positiveInt,
isLendable: nonNegativeInt,
isReserved: nonNegativeInt,
}),
),
});

export const searchAllBooksResponseSchema = metaPaginatedSchema(
z.object({
bookId: positiveInt.openapi({ example: 1 }),
bookInfoId: positiveInt.openapi({ example: 1 }),
bookId: nonNegativeInt.openapi({ example: 1 }),
bookInfoId: nonNegativeInt.openapi({ example: 1 }),
title: z.string().openapi({ example: '모두의 데이터 과학 with 파이썬' }),
author: z.string().openapi({ example: '드미트리 지노비에프' }),
donator: z.string().openapi({ example: 'mingkang' }),
Expand All @@ -140,10 +140,10 @@ export const searchAllBooksResponseSchema = metaPaginatedSchema(
example: 'https://image.kyobobook.co.kr/images/book/xlarge/152/x9791160502152.jpg',
}),
status: statusSchema.openapi({ example: 3 }),
categoryId: positiveInt.openapi({ example: 8 }),
categoryId: nonNegativeInt.openapi({ example: 8 }),
callSign: z.string().openapi({ example: 'K23.17.v1.c1' }),
category: z.string().openapi({ example: '데이터 분석/AI/ML' }),
isLendable: positiveInt.openapi({ example: 0 }),
isLendable: nonNegativeInt.openapi({ example: 0 }),
}),
);

Expand All @@ -162,9 +162,9 @@ export const searchBookInfoCreateResponseSchema = z.object({
});

export const searchBookByIdResponseSchema = z.object({
id: positiveInt.openapi({ example: 3 }),
bookId: positiveInt.openapi({ example: 3 }),
bookInfoId: positiveInt.openapi({ example: 2 }),
id: nonNegativeInt.openapi({ example: 3 }),
bookId: nonNegativeInt.openapi({ example: 3 }),
bookInfoId: nonNegativeInt.openapi({ example: 2 }),
title: z
.string()
.openapi({ example: 'TCP IP 윈도우 소켓 프로그래밍(IT Cookbook 한빛 교재 시리즈 124)' }),
Expand All @@ -177,10 +177,10 @@ export const searchBookByIdResponseSchema = z.object({
example: 'https://image.kyobobook.co.kr/images/book/xlarge/444/x9788998756444.jpg',
}),
status: statusSchema.openapi({ example: 0 }),
categoryId: positiveInt.openapi({ example: 2 }),
categoryId: nonNegativeInt.openapi({ example: 2 }),
callSign: z.string().openapi({ example: 'C5.13.v1.c2' }),
category: z.string().openapi({ example: '네트워크' }),
isLendable: positiveInt.openapi({ example: 1 }),
isLendable: nonNegativeInt.openapi({ example: 1 }),
});

export const updateBookResponseSchema = z.literal('책 정보가 수정되었습니다.');
Expand Down
16 changes: 8 additions & 8 deletions contracts/src/histories/schema.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { dateLike, metaSchema, positiveInt } from '../shared';
import { dateLike, metaSchema, nonNegativeInt } from '../shared';
import { z } from '../zodWithOpenapi';

export const historiesGetMyQuerySchema = z.object({
query: z.string().optional(),
page: z.number().int().nonnegative().default(0),
limit: z.number().int().nonnegative().default(10),
page: nonNegativeInt.default(0),
limit: nonNegativeInt.default(10),
});

export const historiesGetQuerySchema = z.object({
query: z.string().optional(),
type: z.enum(['user', 'title', 'callsign']).optional(),
page: z.number().int().nonnegative().default(0),
limit: z.number().int().nonnegative().default(10),
page: nonNegativeInt.default(0),
limit: nonNegativeInt.default(10),
});

export const historiesGetResponseSchema = z.object({
items: z.array(
z.object({
id: positiveInt,
id: nonNegativeInt,
lendingCondition: z.string(),
login: z.string(),
returningCondition: z.string(),
penaltyDays: z.number().int().nonnegative(),
penaltyDays: nonNegativeInt,
callSign: z.string(),
title: z.string(),
bookInfoId: positiveInt,
bookInfoId: nonNegativeInt,
image: z.string(),
createdAt: dateLike,
returnedAt: dateLike,
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/likes/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { initContract } from '@ts-rest/core';
import { bookInfoIdSchema, bookInfoNotFoundSchema, positiveInt } from '../shared';
import { bookInfoIdSchema, bookInfoNotFoundSchema, nonNegativeInt } from '../shared';
import { z } from '../zodWithOpenapi';
import { likeNotFoundSchema, likeResponseSchema } from './schema';

Expand All @@ -15,7 +15,7 @@ export const likesContract = c.router(
body: null,
responses: {
200: z.object({
userId: positiveInt,
userId: nonNegativeInt,
bookInfoId: bookInfoIdSchema,
}),
},
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/likes/schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import z from 'zod';
import { bookInfoIdSchema, positiveInt } from '../shared';
import { bookInfoIdSchema, nonNegativeInt } from '../shared';

export const likeNotFoundSchema = z.object({
code: z.literal('LIKE_NOT_FOUND'),
Expand All @@ -10,7 +10,7 @@ export const likeResponseSchema = z
.object({
bookInfoId: bookInfoIdSchema,
isLiked: z.boolean(),
likeNum: positiveInt,
likeNum: nonNegativeInt,
})
.openapi({
examples: [
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/reviews/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mkErrorMessageSchema, positiveInt } from '../shared';
import { mkErrorMessageSchema, nonNegativeInt } from '../shared';
import { z } from '../zodWithOpenapi';

export const reviewsIdSchema = positiveInt.describe('도서 리뷰 ID');
export const reviewsIdSchema = nonNegativeInt.describe('도서 리뷰 ID');

export const contentSchema = z.object({
content: z.string().min(10).max(420).openapi({ example: '책 정말 재미있어요 10글자 넘었다' }),
Expand Down
12 changes: 6 additions & 6 deletions contracts/src/shared.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { z } from './zodWithOpenapi';

export const positiveInt = z.coerce.number().int().nonnegative();
export const nonNegativeInt = z.coerce.number().int().nonnegative();

export const dateLike = z.union([z.date(), z.string()]).transform(String);

export const bookInfoIdSchema = positiveInt.describe('개별 도서 ID');
export const bookInfoIdSchema = nonNegativeInt.describe('개별 도서 ID');

export enum enumStatus {
'ok',
Expand Down Expand Up @@ -46,8 +46,8 @@ export const badRequestSchema = mkErrorMessageSchema('BAD_REQUEST').describe('
export const forbiddenSchema = mkErrorMessageSchema('FORBIDDEN').describe('권한이 없습니다.');

export const metaSchema = z.object({
totalItems: positiveInt.describe('전체 검색 결과 수 ').openapi({ example: 42 }),
totalPages: positiveInt.describe('전체 결과 페이지 수').openapi({ example: 5 }),
totalItems: nonNegativeInt.describe('전체 검색 결과 수 ').openapi({ example: 42 }),
totalPages: nonNegativeInt.describe('전체 결과 페이지 수').openapi({ example: 5 }),
// itemCount: positiveInt.describe('현재 페이지의 검색 결과 수').openapi({ example: 3 }),
// itemsPerPage: positiveInt.describe('한 페이지당 검색 결과 수').openapi({ example: 10 }),
// currentPage: positiveInt.describe('현재 페이지').openapi({ example: 1 }),
Expand Down Expand Up @@ -80,6 +80,6 @@ export const visibility = z
.describe('공개 상태');

export const paginationQuerySchema = z.object({
page: positiveInt.default(1).optional().openapi({ example: 1 }),
limit: positiveInt.default(10).optional().openapi({ example: 10 }),
page: nonNegativeInt.default(1).optional().openapi({ example: 1 }),
limit: nonNegativeInt.default(10).optional().openapi({ example: 10 }),
});
16 changes: 8 additions & 8 deletions contracts/src/stock/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { dateLike, metaSchema, positiveInt } from '../shared';
import { dateLike, metaSchema, nonNegativeInt } from '../shared';
import { z } from '../zodWithOpenapi';

export const bookIdSchema = positiveInt.describe('업데이트 할 도서 ID');
export const bookIdSchema = nonNegativeInt.describe('업데이트 할 도서 ID');

export const stockPatchBodySchema = z.object({
id: bookIdSchema.openapi({ example: 0 }),
Expand All @@ -10,24 +10,24 @@ export const stockPatchBodySchema = z.object({
export const stockPatchResponseSchema = z.literal('재고 상태가 업데이트되었습니다.');

export const stockGetQuerySchema = z.object({
page: positiveInt.default(0),
limit: positiveInt.default(10),
page: nonNegativeInt.default(0),
limit: nonNegativeInt.default(10),
});

export const stockGetResponseSchema = z.object({
items: z.array(
z.object({
bookId: positiveInt,
bookInfoId: positiveInt,
bookId: nonNegativeInt,
bookInfoId: nonNegativeInt,
title: z.string(),
author: z.string(),
donator: z.string(),
publisher: z.string(),
publishedAt: dateLike,
isbn: z.string(),
image: z.string(),
status: positiveInt,
categoryId: positiveInt,
status: nonNegativeInt,
categoryId: nonNegativeInt,
callSign: z.string(),
category: z.string(),
updatedAt: dateLike,
Expand Down
Loading

0 comments on commit 1565441

Please sign in to comment.