add service
This commit is contained in:
1 parent
69fdb3a933
commit
b74faa3997
6 files changed
+64
No files matched your search
@@ -7,6 +7,7 @@
|
||||
"serve": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.21.1",
|
||||
"element-plus": "^1.1.0-beta.7",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import httpClient from '../instance';
|
||||
import { IArticle } from './types';
|
||||
|
||||
class ArticleService {
|
||||
name = 'articles';
|
||||
|
||||
getAll(): Promise<IArticle> {
|
||||
return httpClient.get(`/${this.name}`);
|
||||
}
|
||||
|
||||
get(id: number): Promise<IArticle> {
|
||||
return httpClient.get(`/${this.name}/${id}`);
|
||||
}
|
||||
|
||||
create(data: IArticle): Promise<IArticle> {
|
||||
return httpClient.post(`/${this.name}`, data);
|
||||
}
|
||||
|
||||
update(id: number, data: IArticle): Promise<IArticle> {
|
||||
return httpClient.put(`/${this.name}/${id}`, data);
|
||||
}
|
||||
|
||||
delete(id: number): Promise<IArticle> {
|
||||
return httpClient.delete(`/${this.name}/${id}`);
|
||||
}
|
||||
|
||||
deleteAll(): Promise<IArticle> {
|
||||
return httpClient.delete(`/${this.name}`);
|
||||
}
|
||||
}
|
||||
|
||||
export default new ArticleService();
|
||||
@@ -0,0 +1,4 @@
|
||||
export interface IArticle {
|
||||
id: number;
|
||||
title: string;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import ArticleService from './article/service';
|
||||
|
||||
export { ArticleService };
|
||||
@@ -0,0 +1,12 @@
|
||||
import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
||||
|
||||
const httpClient: AxiosInstance = axios.create({
|
||||
timeout: 30000,
|
||||
headers: {
|
||||
'Content-type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
// const httpClient = (options: AxiosRequestConfig): Promise<AxiosResponse> => instance.request(options);
|
||||
|
||||
export default httpClient;
|
||||
@@ -462,6 +462,13 @@ autoprefixer@^10.3.3:
|
||||
normalize-range "^0.1.2"
|
||||
postcss-value-parser "^4.1.0"
|
||||
|
||||
axios@^0.21.1:
|
||||
version "0.21.1"
|
||||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8"
|
||||
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==
|
||||
dependencies:
|
||||
follow-redirects "^1.10.0"
|
||||
|
||||
babel-walk@3.0.0-canary-5:
|
||||
version "3.0.0-canary-5"
|
||||
resolved "https://registry.yarnpkg.com/babel-walk/-/babel-walk-3.0.0-canary-5.tgz#f66ecd7298357aee44955f235a6ef54219104b11"
|
||||
@@ -1049,6 +1056,11 @@ flatted@^3.1.0:
|
||||
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.2.tgz#64bfed5cb68fe3ca78b3eb214ad97b63bedce561"
|
||||
integrity sha512-JaTY/wtrcSyvXJl4IMFHPKyFur1sE9AUqc0QnhOaJ0CxHtAoIV8pYDzeEfAaNEtGkOfq4gr3LBFmdXW5mOQFnA==
|
||||
|
||||
follow-redirects@^1.10.0:
|
||||
version "1.14.2"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.2.tgz#cecb825047c00f5e66b142f90fed4f515dec789b"
|
||||
integrity sha512-yLR6WaE2lbF0x4K2qE2p9PEXKLDjUjnR/xmjS3wHAYxtlsI9MLLBJUZirAHKzUZDGLxje7w/cXR49WOUo4rbsA==
|
||||
|
||||
fraction.js@^4.1.1:
|
||||
version "4.1.1"
|
||||
resolved "https://registry.yarnpkg.com/fraction.js/-/fraction.js-4.1.1.tgz#ac4e520473dae67012d618aab91eda09bcb400ff"
|
||||
|
||||
Reference in new issue
Block a user