Skip to content

Commit a825027

Browse files
authored
Merge pull request #58 from boostcampwm-2022/chore/#57-K
Chore/#57-K: API νŒŒλΌλ―Έν„° νƒ€μž… μ •μ˜
2 parents ffa7bc9 + f93f9b2 commit a825027

File tree

15 files changed

+38
-16
lines changed

15 files changed

+38
-16
lines changed

β€Žclient/src/apis/auth.tsβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { PostLoginParams } from 'params/auth';
2+
13
import { http } from './http';
24
import { OK, CREATED } from './http-status';
35

@@ -9,7 +11,7 @@ export const getAuth = async () => {
911
return res.data;
1012
};
1113

12-
export const postAuthLogin = async (code: string) => {
14+
export const postAuthLogin = async ({ code }: PostLoginParams) => {
1315
const res = await http.post(`/auth/login`, { code });
1416

1517
if (res.status !== CREATED) throw new Error();

β€Žclient/src/apis/user.tsβ€Ž

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { GetWorkspaceParams } from 'params/user';
2+
13
import { http } from './http';
24
import { OK } from './http-status';
35

4-
export const getWorkspaces = async (userId: number) => {
5-
const res = await http.get(`/user/${userId}/workspace`);
6+
export const getWorkspaces = async ({ id }: GetWorkspaceParams) => {
7+
const res = await http.get(`/user/${id}/workspace`);
68

79
if (res.status !== OK) throw new Error();
810

β€Žclient/src/components/WorkspaceList/index.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function WorkspaceList({ onSelectModalOpen }: WorkspaceListProps) {
1616
const userContext = useContext(UserContext);
1717

1818
const updateWorkspaces = async (userId: number) => {
19-
const { workspaces } = await getWorkspaces(userId);
19+
const { workspaces } = await getWorkspaces({ id: userId });
2020
setWorkspaces(workspaces);
2121
};
2222

β€Žclient/src/pages/OAuth/index.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function OAuthPage() {
1818

1919
const login = async (code: string) => {
2020
try {
21-
const authorizedUser = await postAuthLogin(code);
21+
const authorizedUser = await postAuthLogin({ code });
2222

2323
userContext.setUser(authorizedUser);
2424

β€Žclient/tsconfig.jsonβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"src/*": ["./src/*"],
66
"components/*": ["./src/components/*"],
77
"config": ["./src/config"],
8-
"styles/*": ["./src/styles/*"]
8+
"styles/*": ["./src/styles/*"],
9+
"params/*": ["../types/params/*"]
910
},
1011
"target": "ESNext",
1112
"useDefineForClassFields": true,

β€Žclient/vite.config.tsβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default defineConfig({
1515
},
1616
{ find: 'config', replacement: resolve(__dirname, './src/config') },
1717
{ find: 'styles', replacement: resolve(__dirname, './src/styles') },
18+
{ find: 'params', replacement: resolve(__dirname, '../types/params') },
1819
],
1920
},
2021
});

β€Žserver/apis/auth/controller.tsβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import asyncWrapper from '@utils/async-wrapper';
33
import jwtAuthenticator from '@middlewares/jwt-authenticator';
44
import * as authService from './service';
55
import { OK, CREATED } from '@constants/http-status';
6+
import { PostLoginParams } from '@params/auth';
67

78
interface CookieOptions {
89
httpOnly: boolean;
@@ -23,7 +24,7 @@ router.get(
2324

2425
router.post(
2526
'/login',
26-
asyncWrapper(async (req: Request, res: Response) => {
27+
asyncWrapper(async (req: Request<PostLoginParams>, res: Response) => {
2728
const { code } = req.body;
2829

2930
const { user, loginToken, refreshToken } = await authService.login(code);

β€Žserver/apis/auth/service.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const login = async (code: string) => {
1717
avatar_url: avatarUrl,
1818
} = await getGithubUser(accessToken, tokenType);
1919

20-
const isSignedUp = userModel.exists({ id });
20+
const isSignedUp = await userModel.exists({ id });
2121

2222
if (!isSignedUp) {
2323
await userModel.create({

β€Žserver/apis/user/controller.tsβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import express, { Request, Response } from 'express';
22
import asyncWrapper from '@utils/async-wrapper';
33
import * as userService from './service';
44
import jwtAuthenticator from '@middlewares/jwt-authenticator';
5+
import { GetWorkspaceParams } from '@params/user';
56

67
const router = express.Router();
78

89
router.get(
910
'/:id/workspace',
1011
jwtAuthenticator,
11-
asyncWrapper(async (req: Request, res: Response) => {
12+
asyncWrapper(async (req: Request<GetWorkspaceParams>, res: Response) => {
1213
const { id: userId } = req.user;
1314
const { id: targetUserId } = req.params;
1415

β€Žserver/apis/workspace/controller.tsβ€Ž

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,31 @@ import express, { Request, Response } from 'express';
22
import asyncWrapper from '@utils/async-wrapper';
33
import jwtAuthenticator from '@middlewares/jwt-authenticator';
44
import * as workspaceService from './service';
5-
import { OK } from '@constants/http-status';
5+
import { CREATED } from '@constants/http-status';
6+
import { PostParams, PostJoinParams } from '@params/workspace';
67

78
const router = express.Router();
89

910
router.post(
1011
'/',
11-
asyncWrapper(async (req: Request, res: Response) => {
12+
asyncWrapper(async (req: Request<PostParams>, res: Response) => {
1213
const { name } = req.body;
1314

1415
const workspace = await workspaceService.create(name);
1516

16-
res.status(OK).send({ ...workspace });
17+
res.status(CREATED).send({ ...workspace });
1718
}),
1819
);
1920

2021
router.post(
2122
'/join',
2223
jwtAuthenticator,
23-
asyncWrapper(async (req: Request, res: Response) => {
24+
asyncWrapper(async (req: Request<PostJoinParams>, res: Response) => {
2425
const { code } = req.body;
2526

2627
const joinedWorkspace = await workspaceService.join(req.user.id, code);
2728

28-
res.status(OK).send(joinedWorkspace);
29+
res.status(CREATED).send(joinedWorkspace);
2930
}),
3031
);
3132

0 commit comments

Comments
Β (0)