Skip to content

Commit 7cc5739

Browse files
authored
Merge pull request #9 from tkc/feat/api
Implement API skeleton
2 parents 8483abf + f5d79ac commit 7cc5739

28 files changed

Lines changed: 166 additions & 332 deletions

File tree

apis/base.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import axios, { AxiosInstance, AxiosRequestConfig } from "axios";
2+
export const baseURL = "example.com";
3+
4+
export type Response<T> = {
5+
code: number;
6+
data: T;
7+
status: string;
8+
};
9+
10+
const defaultOptions = {
11+
timeout: 60000,
12+
baseURL,
13+
headers: {},
14+
};
15+
16+
export class Api {
17+
api: AxiosInstance;
18+
constructor(options: AxiosRequestConfig = {}) {
19+
this.api = axios.create({ ...defaultOptions, ...options });
20+
}
21+
get(url: string, params?: any) {
22+
return this.api.get(url, params ? { params } : {}).catch(e => {
23+
return Promise.reject(e.response);
24+
});
25+
}
26+
post(url: string, body: any) {
27+
return this.api.post(url, body).catch(e => {
28+
return Promise.reject(e.response);
29+
});
30+
}
31+
delete(url: string, body: any) {
32+
return this.api.delete(url, body).catch(e => {
33+
return Promise.reject(e.response);
34+
});
35+
}
36+
put(url: string, body: any) {
37+
return this.api.put(url, body).catch(e => {
38+
return Promise.reject(e.response);
39+
});
40+
}
41+
patch(url: string, body: any) {
42+
return this.api.patch(url, body).catch(e => {
43+
return Promise.reject(e.response);
44+
});
45+
}
46+
}

apis/index.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { AxiosPromise } from "axios";
2+
import axios, { AxiosInstance, AxiosRequestConfig } from "axios";
3+
import * as models from "types/models";
4+
import * as payloads from "types/payloads";
5+
export const baseURL = "example.com";
6+
7+
export type Response<T> = {
8+
code: number;
9+
data: T;
10+
status: string;
11+
};
12+
13+
const defaultOptions = {
14+
timeout: 60000,
15+
baseURL,
16+
headers: {},
17+
};
18+
19+
export class Api {
20+
api: AxiosInstance;
21+
constructor(options: AxiosRequestConfig = {}) {
22+
this.api = axios.create({ ...defaultOptions, ...options });
23+
}
24+
get(url: string, params?: any) {
25+
return this.api.get(url, params ? { params } : {}).catch(e => {
26+
return Promise.reject(e.response);
27+
});
28+
}
29+
post(url: string, body: any) {
30+
return this.api.post(url, body).catch(e => {
31+
return Promise.reject(e.response);
32+
});
33+
}
34+
delete(url: string, body: any) {
35+
return this.api.delete(url, body).catch(e => {
36+
return Promise.reject(e.response);
37+
});
38+
}
39+
put(url: string, body: any) {
40+
return this.api.put(url, body).catch(e => {
41+
return Promise.reject(e.response);
42+
});
43+
}
44+
patch(url: string, body: any) {
45+
return this.api.patch(url, body).catch(e => {
46+
return Promise.reject(e.response);
47+
});
48+
}
49+
}
50+
51+
export function Login(payload: payloads.Login): AxiosPromise<models.User> {
52+
const api = new Api();
53+
return api.post(`/login`, payload);
54+
}

models/account.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

models/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

models/user.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

package.json

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
},
1919
"repository": {
2020
"type": "git",
21-
"url": ""
21+
"url": "https://github.com/tkc/react-admin-sandbox"
2222
},
2323
"bugs": {
24-
"url": ""
24+
"url": "https://github.com/tkc/react-admin-sandbox/issue"
2525
},
2626
"homepage": "",
2727
"dependencies": {
@@ -34,23 +34,18 @@
3434
"add": "^2.0.6",
3535
"antd": "^3.26.7",
3636
"aws-sdk": "^2.518.0",
37-
"axios": "0.19.0",
38-
"c3": "^0.7.12",
39-
"clipboard-copy": "^3.1.0",
37+
"axios": "^0.19.2",
4038
"connected-react-router": "^4.4.1",
4139
"css-modules-typescript-loader": "^4.0.0",
42-
"dicom-parser": "^1.8.1",
4340
"encoding-japanese": "^1.0.29",
4441
"faker": "^4.1.0",
4542
"formik": "1.5.8",
4643
"fp-ts": "2.3.1",
4744
"history": "^4.10.1",
48-
"jest-canvas-mock": "^2.1.1",
4945
"js-tree": "^2.0.1",
5046
"loadable-components": "2.2.3",
5147
"lodash": "^4.17.15",
5248
"monocle-ts": "^2.0.0",
53-
"newtype-ts": "^0.3.2",
5449
"nprogress": "^0.2.0",
5550
"peity-react": "^0.0.7",
5651
"query-string": "^6.2.0",
@@ -72,7 +67,7 @@
7267
"redux-thunk": "^2.3.0",
7368
"save": "^2.4.0",
7469
"store": "^2.0.12",
75-
"storybook": "^5.1.11",
70+
"storybook": "^5.3.9",
7671
"styled-components": "4.4.1",
7772
"timeago.js": "^4.0.1",
7873
"tslib": "1.10.0",
@@ -86,19 +81,11 @@
8681
"@babel/types": "7.7.4",
8782
"@emotion/core": "10.0.22",
8883
"@sentry/browser": "5.10.2",
89-
"@storybook/addon-actions": "5.2.8",
90-
"@storybook/addon-centered": "5.2.8",
91-
"@storybook/addon-knobs": "5.2.8",
92-
"@storybook/addon-links": "5.2.8",
93-
"@storybook/addon-options": "5.2.8",
94-
"@storybook/addon-storysource": "5.2.8",
9584
"@storybook/addons": "5.2.8",
9685
"@storybook/react": "5.2.8",
9786
"@storybook/theming": "5.2.8",
9887
"@svgr/webpack": "4.3.3",
9988
"@types/dom-inputevent": "1.0.5",
100-
"@types/enzyme": "3.10.4",
101-
"@types/enzyme-adapter-react-16": "1.0.5",
10289
"@types/enzyme-to-json": "1.5.3",
10390
"@types/hammerjs": "2.0.36",
10491
"@types/history": "4.7.3",
@@ -124,8 +111,6 @@
124111
"connect-history-api-fallback": "1.6.0",
125112
"cpy-cli": "3.0.0",
126113
"css-loader": "^3.4.2",
127-
"enzyme": "3.10.0",
128-
"enzyme-adapter-react-16": "1.15.1",
129114
"enzyme-to-json": "3.4.3",
130115
"glob-all": "3.1.0",
131116
"html-webpack-plugin": "^4.0.0-beta.11",
@@ -178,4 +163,4 @@
178163
"**/?(*.)+(spec|test).ts?(x)"
179164
]
180165
}
181-
}
166+
}

src/actions/auth.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { $ActionType } from ".";
2+
import * as models from "types/models";
23

34
// login
45
export const AuthLoginRequestActionType = "AUTH/LOGIN-REQUEST";
@@ -41,10 +42,10 @@ export type AuthLoginSuccessAction = $ActionType<
4142
typeof AuthLoginSuccessActionType,
4243
ReturnType<typeof AuthLoginSuccess>["payload"]
4344
>;
44-
export function AuthLoginSuccess() {
45+
export function AuthLoginSuccess(payload: models.User) {
4546
return {
4647
type: AuthLoginSuccessActionType,
47-
payload: null,
48+
payload,
4849
};
4950
}
5051

src/actions/user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { $ActionType } from ".";
2-
import * as models from "models";
2+
import * as models from "types/models";
33

44
export const UserCreateRequestActionType = "USERCREATE/REQUEST";
55
export const UserCreateSuccessActionType = "USERCREATE/SUCCESS";

src/auth/auth.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/components/molecules/top-bar/ProfileMenu/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from "react";
22
import { Menu, Dropdown, Avatar, Badge } from "antd";
33
import styles from "./style.module.scss";
4-
import * as types from "types";
4+
import * as models from "types/models";
55

66
export interface OwnState {}
77

88
export interface ProfileMenuProps {
9-
user: types.UserType;
9+
user: models.User;
1010
badgeCount: number;
1111
logout: () => void;
1212
}

0 commit comments

Comments
 (0)