Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: connect front back #9

Merged
merged 31 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fd3b117
feat: error config Array to hash Object
raipen Mar 2, 2024
c9fd0f7
feat: separate watching servers
raipen Mar 2, 2024
a123ad0
feat: change onError hook to setErrorHandler
raipen Mar 2, 2024
e4ef19b
feat: use csr when dev
raipen Mar 2, 2024
7bb37be
feat: add static name of error classes
raipen Mar 2, 2024
f0645e8
feat: delete front/utils/errors
raipen Mar 2, 2024
03b4f74
feat: cleaning errors
raipen Mar 2, 2024
2ddbe7d
feat: add sign up, in, out error schema
raipen Mar 2, 2024
659bb7f
feat: add NoAuth in Cookie error
raipen Mar 2, 2024
58cab00
feat: handling refresh error
raipen Mar 2, 2024
64164f2
feat: change front wordbookmock api to wordbook
raipen Mar 2, 2024
5bf61f9
chore: remove console log
raipen Mar 2, 2024
719af6a
feat: change wordbook return type from tuple to object
raipen Mar 3, 2024
0476f28
feat: edit wordbook api route
raipen Mar 3, 2024
31ca197
feat: update wordbook.name to wordbook.title
raipen Mar 3, 2024
4784499
feat: extract api Error Catch logic
raipen Mar 3, 2024
7ca89c6
feat: add @utils alias
raipen Mar 3, 2024
0453b93
feat: use wordbook apis at front
raipen Mar 3, 2024
8b7fb52
feat: update voca list apis' router according to rules
raipen Mar 3, 2024
d78d580
feat: impl voca apis at front
raipen Mar 3, 2024
76fcd2a
fix: save vocalist with meaning
raipen Mar 3, 2024
b20825f
feat: update front voca apis from mock to real
raipen Mar 3, 2024
e106d92
feat: get wordbook list orderby createdAt
raipen Mar 4, 2024
65114aa
feat: impl get profile api
raipen Mar 4, 2024
bec7633
feat: impl login front page
raipen Mar 4, 2024
5f48997
feat: impl front signUp page
raipen Mar 5, 2024
9c09696
feat: update loginedRoute
raipen Mar 5, 2024
f141ac1
feat: extract sign in, sign up hooks
raipen Mar 6, 2024
f6fdfc2
feat: throw TokenExpiedError
raipen Mar 9, 2024
0b07ea4
refactor: wordbookmock use awaitOneSecond function
raipen Mar 9, 2024
481e447
refactor: front error page
raipen Mar 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"build": "npm-run-all --parallel build:client build:server",
"build:client": "vite build --ssrManifest --outDir dist/client",
"build:server": "vite build --ssr entry-server.tsx --outDir dist/server",
"dev": "tsx watch --ignore node_modules src/back/index.ts",
"dev:back": "tsx watch --ignore ./ src/back/index.ts",
"dev:csr": "vite",
"dev:ssr": "tsx src/back/frontDevServer.ts",
"dev": "npm-run-all --parallel dev:back dev:csr",
"production:back": "cross-env NODE_ENV=production tsx src/back/index.ts",
"preview": "npm-run-all --serial build production:back",
"deploy": "npm-run-all --serial prisma:generate prisma:deploy preview",
Expand Down
9 changes: 3 additions & 6 deletions src/DTO/index.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,29 @@ export const AuthorizationHeader = {
type ErrorSchema = {
type: 'object',
description: string,
required: ['error','message','toast'],
required: ['error','message'],
properties: {
error: { type: 'string', enum: string[] },
message: { type: 'string'},
toast: { type: 'string', enum: string[] }
}
};

export const errorSchema = (...errors: Array<new (message:string,...any:any) => ErrorWithToast>) => {
const errorConfigs = ErrorConfig.filter((errorConfig) => errors.some((error) => errorConfig.error === error));
const errorConfigs = errors.map((error) => ErrorConfig[error.name]);
return errorConfigs.reduce((acc, cur) => {
const errorInstance = new cur.error("");
if(acc[cur.code]) {
acc[cur.code].properties.error.enum.push(errorInstance.name);
acc[cur.code].description += `\n${cur.describtion}`;
acc[cur.code].properties.toast.enum.push(cur.toast(errorInstance));
return acc;
}
acc[cur.code] = {
type: 'object',
description: cur.describtion,
required: ['error','message','toast'],
required: ['error','message'],
properties: {
error: { type: 'string', enum: [errorInstance.name] },
message: { type: 'string'},
toast: { type: 'string', enum: [cur.toast(errorInstance)] }
}
}
return acc;
Expand Down
7 changes: 7 additions & 0 deletions src/DTO/user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export const signUpSchema = {
},
},
...errorSchema(
E.ValidationError,
E.NotCorrectTypeError,
E.ExistError,
)
},
} as const;
Expand All @@ -51,6 +54,7 @@ export const signInSchema = {
},
},
...errorSchema(
E.ValidationError,
E.NotFoundError
)
},
Expand Down Expand Up @@ -82,6 +86,8 @@ export const refreshSchema = {
},
},
...errorSchema(
E.NoAuthorizationInCookieError,
E.UserAuthorizationError
)
},
} as const;
Expand Down Expand Up @@ -121,3 +127,4 @@ export type signUpInterface = SchemaToInterface<typeof signUpSchema>;
export type signInInterface = SchemaToInterface<typeof signInSchema>;
export type signOutInterface = SchemaToInterface<typeof signOutSchema>;
export type refreshInterface = SchemaToInterface<typeof refreshSchema> & { Body: { userId: string } };
export type profileInterface = SchemaToInterface<typeof profileSchema> & { Body: { userId: string } };
4 changes: 2 additions & 2 deletions src/DTO/vocaList.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const getVocaListSchema = {
tags: ['Voca'],
summary: '단어 목록 조회',
headers: AuthorizationHeader,
querystring: {
params: {
type: 'object',
required: ['bookId'],
properties: {
Expand Down Expand Up @@ -129,7 +129,7 @@ export const deleteVocaSchema = {
tags: ['Voca'],
summary: '단어 삭제',
headers: AuthorizationHeader,
body: {
params: {
type: 'object',
required: ['vocaId'],
properties: {
Expand Down
157 changes: 71 additions & 86 deletions src/DTO/wordbook.dto.ts
Original file line number Diff line number Diff line change
@@ -1,110 +1,95 @@
import {
AuthorizationHeader,
errorSchema,
} from '@DTO/index.dto';
AuthorizationHeader,
errorSchema,
} from '@DTO/index.dto';
import * as E from '@errors';
import { SchemaToInterface } from 'fastify-schema-to-ts';

//getWordbookList, addWordbook, hideWordbook, showWordbook

const wordbookType = {
type: 'array',
items: {
type: 'object',
required: ['id', 'title', 'createdAt', 'isHidden', 'vocaCount'],
properties: {
id: { type: 'number' },
title: { type: 'string' },
createdAt: { type: 'string' },
isHidden: { type: 'boolean' },
vocaCount: { type: 'number' },
},
type: 'array',
items: {
type: 'object',
required: ['id', 'title', 'createdAt', 'isHidden', 'vocaCount'],
properties: {
id: { type: 'number' },
title: { type: 'string' },
createdAt: { type: 'string' },
isHidden: { type: 'boolean' },
vocaCount: { type: 'number' },
},
},
} as const;

const returnType = {
type: "object",
required: ['wordbookList', 'hiddenWordbookList'],
properties: {
wordbookList: wordbookType,
hiddenWordbookList: wordbookType,
},
} as const;

export const getWordbookListSchema = {
tags: ['Wordbook'],
summary: '단어장 목록 조회',
headers: AuthorizationHeader,
response: {
200: {
type: "array",
items: [wordbookType,wordbookType],
minItems: 2,
maxItems: 2,
},
...errorSchema(
)
},
tags: ['Wordbook'],
summary: '단어장 목록 조회',
headers: AuthorizationHeader,
response: {
200: returnType,
},
} as const;

export const createWordbookSchema = {
tags: ['Wordbook'],
summary: '단어장 목록 조회',
headers: AuthorizationHeader,
body: {
type: 'object',
required: ['title'],
properties: {
title: { type: 'string' },
},
tags: ['Wordbook'],
summary: '단어장 목록 조회',
headers: AuthorizationHeader,
body: {
type: 'object',
required: ['title'],
properties: {
title: { type: 'string' },
},
response: {
201: {
type: "array",
items: [wordbookType,wordbookType],
minItems: 2,
maxItems: 2,
},
...errorSchema(
)
},
},
response: {
201: returnType,
...errorSchema(
)
},
} as const;

export const hideWordbookSchema = {
tags: ['Wordbook'],
summary: '단어장 숨기기',
headers: AuthorizationHeader,
body: {
type: 'object',
required: ['bookId'],
properties: {
bookId: { type: 'number' },
},
tags: ['Wordbook'],
summary: '단어장 숨기기',
headers: AuthorizationHeader,
body: {
type: 'object',
required: ['bookId'],
properties: {
bookId: { type: 'number' },
},
response: {
200: {
type: "array",
items: [wordbookType,wordbookType],
minItems: 2,
maxItems: 2,
},
...errorSchema(
)
},
},
response: {
200: returnType,
...errorSchema(
)
},
} as const;

export const showWordbookSchema = {
tags: ['Wordbook'],
summary: '단어장 보이기',
headers: AuthorizationHeader,
body: {
type: 'object',
required: ['bookId'],
properties: {
bookId: { type: 'number' },
},
tags: ['Wordbook'],
summary: '단어장 보이기',
headers: AuthorizationHeader,
body: {
type: 'object',
required: ['bookId'],
properties: {
bookId: { type: 'number' },
},
response: {
200: {
type: "array",
items: [wordbookType,wordbookType],
minItems: 2,
maxItems: 2,
},
...errorSchema(
)
},
},
response: {
200: returnType,
...errorSchema(
)
},
} as const;

export type getWordbookListInterface = SchemaToInterface<typeof getWordbookListSchema> & { Body: { userId: string } };
Expand Down
4 changes: 2 additions & 2 deletions src/back/api/hooks/checkRefreshToken.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LoginToken } from '@serverUtils/jwt';
import { FastifyRequest, FastifyReply, FastifyError } from 'fastify';
import { UserAuthorizationError, NoAuthorizationInHeaderError } from '@errors/index';
import { NoAuthorizationInCookieError } from '@errors/index';

export default async (
request: FastifyRequest<{ Body: { userId: string } }>,
Expand All @@ -9,7 +9,7 @@ export default async (
) => {
const authorization = request.cookies.authorization;
if (!authorization) {
throw new NoAuthorizationInHeaderError('쿠키에 Authorization이 없습니다');
throw new NoAuthorizationInCookieError('쿠키에 Authorization이 없습니다');
}

if(!request.body)
Expand Down
2 changes: 1 addition & 1 deletion src/back/api/hooks/checkUser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LoginToken } from '@serverUtils/jwt';
import { FastifyRequest, FastifyReply, FastifyError } from 'fastify';
import { UserAuthorizationError, NoAuthorizationInHeaderError } from '@errors/index';
import { NoAuthorizationInHeaderError } from '@errors/index';

export default async (
request: FastifyRequest<{ Body: { userId: string } }>,
Expand Down
39 changes: 0 additions & 39 deletions src/back/api/hooks/onError.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/back/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import wordbook from './routes/wordbook';
const api: FastifyPluginAsync = async (server: FastifyInstance) => {
server.register(test, { prefix: '/' });
server.register(user, { prefix: '/user' });
server.register(vocaList, { prefix: '/vocaList' });
server.register(vocaList, { prefix: '/voca' });
server.register(wordbook, { prefix: '/wordbook' });
};

Expand Down
5 changes: 2 additions & 3 deletions src/back/api/routes/apiTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { FastifyInstance, FastifyPluginAsync, FastifySchema } from 'fastify';
import onError from '@fastifyHooks/onError';
import { NotDefinedOnConfigError } from '@errors/index';

const test: FastifyPluginAsync = async (server: FastifyInstance) => {
Expand All @@ -16,10 +15,10 @@ const test: FastifyPluginAsync = async (server: FastifyInstance) => {
server.get('/ping', { schema: testSchema }, async (req, rep) => {
return { data: 'pong' };
});
server.post('/notDefinedOnConfigerror', { onError }, async (req, rep) => {
server.post('/notDefinedOnConfigerror', async (req, rep) => {
throw new NotDefinedOnConfigError('notDefinedOnConfigerror');
});
server.post('/notDefinederror', { onError }, async (req, rep) => {
server.post('/notDefinederror', async (req, rep) => {
throw new Error('notDefinederror');
});
};
Expand Down
Loading