Skip to content

Commit

Permalink
refactor: v2 라우트 정리 적용 (#771)
Browse files Browse the repository at this point in the history
* refactor: `/stock` 제거

#767 (comment)

* refactor: contracts에서 500번대 오류 제거

백엔드에서 복구 불가능한 오류일 시 반환하기 때문에, 프론트엔드에서 따로 처리하는 것이 좋을 것 같습니다.

* refactor: `/history` -> `/lendings`

#767 (comment)

Co-authored-by: jwoo <74581396+Jiwon-Woo@users.noreply.github.com>

* refactor: `/users ` 정리

#767 (comment)

Co-authored-by: honeyl3ee <ddanhopark@gmail.com>

* refactor: `/tag` 서비스 임시 제거

고도화를 하기 위해서는 내부 구현을 바꾸어야 하는 문제가 있어 우선순위를 낮추었습니다.

주석처리를 할까 고민했으나 제거 이전 커밋(1565441)으로 체크아웃시 전체 코드를 확인 가능하기 때문에 복잡도 감소를 위해 코드를 제거하였습니다.

* refactor: `/books` 경로 정리

#767 (comment)
#767 (comment)

Co-authored-by: Jeong Jihwan <47599349+JeongJiHwan@users.noreply.github.com>
Co-authored-by: jwoo <74581396+Jiwon-Woo@users.noreply.github.com>

* feat: swagger에서 1줄 요약 표시

---------

Co-authored-by: jwoo <74581396+Jiwon-Woo@users.noreply.github.com>
Co-authored-by: honeyl3ee <ddanhopark@gmail.com>
Co-authored-by: Jeong Jihwan <47599349+JeongJiHwan@users.noreply.github.com>
  • Loading branch information
4 people authored Sep 14, 2023
1 parent 1565441 commit 6cbb823
Show file tree
Hide file tree
Showing 22 changed files with 217 additions and 868 deletions.
188 changes: 91 additions & 97 deletions backend/src/v2/books/mod.ts
Original file line number Diff line number Diff line change
@@ -1,112 +1,106 @@
import { contract } from '@jiphyeonjeon-42/contracts';
import { initServer } from '@ts-rest/express';
import {
searchAllBooks,
searchBookById,
searchBookInfoById,
searchBookInfoForCreate,
searchBookInfosByTag,
searchBookInfosSorted,
updateBookDonator,
updateBookOrBookInfo,
} from './service';
import {
BookInfoNotFoundError,
BookNotFoundError,
bookInfoNotFound,
bookNotFound,
isbnNotFound,
naverBookNotFound,
pubdateFormatError,
} from '../shared';
import { IsbnNotFoundError, NaverBookNotFound, PubdateFormatError } from './errors';
import authValidate from '~/v1/auth/auth.validate';
import { roleSet } from '~/v1/auth/auth.type';
// import { contract } from '@jiphyeonjeon-42/contracts';
// import { initServer } from '@ts-rest/express';
// import {
// searchAllBooks,
// searchBookById,
// searchBookInfoById,
// searchBookInfoForCreate,
// searchBookInfosByTag,
// searchBookInfosSorted,
// updateBookDonator,
// updateBookOrBookInfo,
// } from './service';
// import {
// BookInfoNotFoundError,
// BookNotFoundError,
// bookInfoNotFound,
// bookNotFound,
// isbnNotFound,
// naverBookNotFound,
// pubdateFormatError,
// } from '../shared';
// import { IsbnNotFoundError, NaverBookNotFound, PubdateFormatError } from './errors';
// import authValidate from '~/v1/auth/auth.validate';
// import { roleSet } from '~/v1/auth/auth.type';

const s = initServer();
export const books = s.router(contract.books, {
// searchAllBookInfos: async ({ query }) => {
// const result = await searchAllBookInfos(query);
// const s = initServer();
// export const books = s.router(contract.books, {
// // searchAllBookInfos: async ({ query }) => {
// // const result = await searchAllBookInfos(query);

// return { status: 200, body: result } as const;
// },
// @ts-expect-error
searchBookInfosByTag: async ({ query }) => {
const result = await searchBookInfosByTag(query);
// // return { status: 200, body: result } as const;
// // },
// searchBookInfosByTag: async ({ query }) => {
// const result = await searchBookInfosByTag(query);

return { status: 200, body: result } as const;
},
// @ts-expect-error
searchBookInfosSorted: async ({ query }) => {
const result = await searchBookInfosSorted(query);
// return { status: 200, body: result } as const;
// },
// searchBookInfosSorted: async ({ query }) => {
// const result = await searchBookInfosSorted(query);

return { status: 200, body: result } as const;
},
// @ts-expect-error
searchBookInfoById: async ({ params: { id } }) => {
const result = await searchBookInfoById(id);
// return { status: 200, body: result } as const;
// },
// searchBookInfoById: async ({ params: { id } }) => {
// const result = await searchBookInfoById(id);

if (result instanceof BookInfoNotFoundError) return bookInfoNotFound;
// if (result instanceof BookInfoNotFoundError) return bookInfoNotFound;

return { status: 200, body: result } as const;
},
// @ts-expect-error
searchAllBooks: async ({ query }) => {
const result = await searchAllBooks(query);
// return { status: 200, body: result } as const;
// },
// searchAllBooks: async ({ query }) => {
// const result = await searchAllBooks(query);

return { status: 200, body: result } as const;
},
searchBookInfoForCreate: {
// middleware: [authValidate(roleSet.librarian)],
// @ts-expect-error
handler: async ({ query: { isbnQuery } }) => {
const result = await searchBookInfoForCreate(isbnQuery);
// return { status: 200, body: result } as const;
// },
// searchBookInfoForCreate: {
// // middleware: [authValidate(roleSet.librarian)],
// handler: async ({ query: { isbnQuery } }) => {
// const result = await searchBookInfoForCreate(isbnQuery);

if (result instanceof IsbnNotFoundError) return isbnNotFound;
// if (result instanceof IsbnNotFoundError) return isbnNotFound;

if (result instanceof NaverBookNotFound) return naverBookNotFound;
// if (result instanceof NaverBookNotFound) return naverBookNotFound;

return { status: 200, body: result } as const;
},
},
// @ts-expect-error
searchBookById: async ({ params: { id } }) => {
const result = await searchBookById({ id });
// return { status: 200, body: result } as const;
// },
// },
// searchBookById: async ({ params: { id } }) => {
// const result = await searchBookById({ id });

if (result instanceof BookNotFoundError) {
return bookNotFound;
}
// if (result instanceof BookNotFoundError) {
// return bookNotFound;
// }

return {
status: 200,
body: result,
} as const;
},
// createBook: {
// middleware: [authValidate(roleSet.librarian)],
// handler: async ({ body }) => {
// return {
// status: 200,
// body: result,
// } as const;
// },
// // createBook: {
// // middleware: [authValidate(roleSet.librarian)],
// // handler: async ({ body }) => {

// }
// },
updateBook: {
// middleware: [authValidate(roleSet.librarian)],
// @ts-expect-error
handler: async ({ body }) => {
const result = await updateBookOrBookInfo(body);
// // }
// // },
// updateBook: {
// // middleware: [authValidate(roleSet.librarian)],
// // @ts-expect-error
// handler: async ({ body }) => {
// const result = await updateBookOrBookInfo(body);

if (result instanceof PubdateFormatError) {
return pubdateFormatError;
}
return { status: 200, body: '책 정보가 수정되었습니다.' } as const;
},
},
updateDonator: {
// middleware: [authValidate(roleSet.librarian)],
// @ts-expect-error
handler: async ({ body }) => {
const result = await updateBookDonator(body);
// if (result instanceof PubdateFormatError) {
// return pubdateFormatError;
// }
// return { status: 200, body: '책 정보가 수정되었습니다.' } as const;
// },
// },
// updateDonator: {
// // middleware: [authValidate(roleSet.librarian)],
// // @ts-expect-error
// handler: async ({ body }) => {
// const result = await updateBookDonator(body);

return { status: 200, body: '기부자 정보가 수정되었습니다.' } as const;
},
},
});
// return { status: 200, body: '기부자 정보가 수정되었습니다.' } as const;
// },
// },
// });
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { getHistoriesByQuery, getHistoriesByUser } from './repository';
import { getUser } from '../shared';

const s = initServer();
export const histories = s.router(contract.histories, {
getMyHistories: {
export const lendings = s.router(contract.lendings, {
getMine: {
middleware: [authValidate(roleSet.all)],
handler: async ({ query, req: { user } }) => {
const { nickname: login } = getUser.parse(user);
Expand All @@ -27,7 +27,7 @@ export const histories = s.router(contract.histories, {
},
},

getAllHistories: {
get: {
middleware: [authValidate(roleSet.librarian)],
handler: async ({ query }) => {
const [items, count] = await getHistoriesByQuery(query);
Expand Down
File renamed without changes.
8 changes: 2 additions & 6 deletions backend/src/v2/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import { contract } from '@jiphyeonjeon-42/contracts';
import { initServer } from '@ts-rest/express';

import { reviews } from './reviews/mod.ts';
import { histories } from './histories/mod.ts';
import { stock } from './stock/mod.ts';
import { books } from './books/mod.ts';
import { lendings } from './lendings/mod.ts';

const s = initServer();
export default s.router(contract, {
reviews,
histories,
stock,
books,
lendings,
});
22 changes: 0 additions & 22 deletions backend/src/v2/stock/mod.ts

This file was deleted.

18 changes: 0 additions & 18 deletions backend/src/v2/stock/repository.ts

This file was deleted.

41 changes: 0 additions & 41 deletions backend/src/v2/stock/service.ts

This file was deleted.

Loading

0 comments on commit 6cbb823

Please sign in to comment.