Skip to content

Commit b766472

Browse files
setup axios
1 parent 7f84f29 commit b766472

File tree

16 files changed

+441
-7
lines changed

16 files changed

+441
-7
lines changed

.env.development

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VUE_APP_API_ROOT=http://localhost:8000

src/api/endpoints.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const endpoints = {
2+
users: {
3+
login: '/users/login/',
4+
tokenRefresh: '/users/token-refresh/',
5+
registerTeacher: '/users/register-teacher/'
6+
}
7+
}
8+
9+
export function replacePk (endpoint: string, pk: number): string {
10+
return endpoint.replace('<pk>', pk.toString())
11+
}

src/api/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { users } from './users'
2+
3+
export const Api = {
4+
users,
5+
}

src/api/users.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import Vue from 'vue'
2+
import { endpoints } from './endpoints'
3+
import {
4+
LoginReq, LoginRes,
5+
RegisterTeacherReq, RegisterTeacherRes, TokenRefreshReq, TokenRefreshRes
6+
} from '@/interfaces/api/user'
7+
8+
export const users = {
9+
async registerTeacher (reqBody: RegisterTeacherReq): Promise<RegisterTeacherRes> {
10+
const res = await Vue.axios.post(endpoints.users.registerTeacher, reqBody)
11+
return {
12+
name: res.data.name,
13+
email: res.data.email,
14+
phoneNumber: res.data.phone_number
15+
}
16+
},
17+
18+
async login (reqBody: LoginReq): Promise<LoginRes> {
19+
const res = await Vue.axios.post(endpoints.users.login, reqBody)
20+
return {
21+
access: res.data.access,
22+
refresh: res.data.refresh
23+
}
24+
},
25+
26+
async tokenRefresh (reqBody: TokenRefreshReq): Promise<TokenRefreshRes> {
27+
const res = await Vue.axios.post(endpoints.users.tokenRefresh, reqBody)
28+
return {
29+
access: res.data.access,
30+
refresh: res.data.refresh
31+
}
32+
},
33+
}

src/interfaces/api/user.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export declare interface LoginReq {
2+
name: string;
3+
password: string;
4+
}
5+
6+
export declare interface LoginRes {
7+
access: string;
8+
refresh: string;
9+
}
10+
11+
export declare interface TokenRefreshReq {
12+
refresh: string;
13+
}
14+
15+
export declare interface TokenRefreshRes {
16+
access: string;
17+
refresh: string;
18+
}
19+
20+
export declare interface RegisterTeacherReq {
21+
email: string;
22+
password: string;
23+
name?: string;
24+
phoneNumber?: string;
25+
}
26+
27+
export declare interface RegisterTeacherRes {
28+
email: string;
29+
name: string;
30+
phoneNumber: string;
31+
}

src/interfaces/group.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { User } from './user'
2+
3+
export declare interface Group {
4+
pk: number;
5+
name: string;
6+
owner: User;
7+
members: User[];
8+
}

src/interfaces/store/groups.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Group } from '../group'
2+
3+
export declare type GroupWithState = Group & {
4+
editing: boolean,
5+
loading: boolean,
6+
nameErrs: string[]
7+
}
8+
9+
export declare interface GroupsState {
10+
groups: GroupWithState[];
11+
currentGroup?: GroupWithState;
12+
}

src/interfaces/user.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export declare interface User {
2+
pk: number;
3+
username: string;
4+
email: string;
5+
}

src/interfaces/vuetify.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Vue from 'vue'
2+
3+
export declare type VForm = Vue & {
4+
validate: () => boolean;
5+
resetValidation: () => void;
6+
reset: () => void;
7+
}

src/plugins/axios.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Vue from 'vue'
2+
import { AxiosStatic } from 'axios'
3+
4+
declare module 'vue/types/vue' {
5+
interface VueConstructor {
6+
axios: AxiosStatic;
7+
}
8+
}

0 commit comments

Comments
 (0)