Skip to content

Commit

Permalink
Merge pull request #32 from DEPthes/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jisupark123 authored Aug 18, 2023
2 parents 532a179 + a200a3e commit 629cb8e
Show file tree
Hide file tree
Showing 55 changed files with 1,898 additions and 265 deletions.
13 changes: 13 additions & 0 deletions apis/deleteAuthNumber.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import ieumAxios from './ieumAxios';

type CheckAuthNumberResponse = {
check: boolean;
information: {
message: string;
};
};

export async function deleteAuthNumber({ authNumber }: { authNumber: string }) {
const url = '/verify/check/' + authNumber;
return await ieumAxios.delete<CheckAuthNumberResponse>(url);
}
10 changes: 10 additions & 0 deletions apis/deleteUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { authToken } from '@/class/authToken';
import ieumAxios from './ieumAxios';

export function deleteUser() {
return ieumAxios.delete('/api/user/leave', {
headers: {
Authorization: `Bearer ${authToken.getToken()}`,
},
});
}
13 changes: 13 additions & 0 deletions apis/getEmailDuplicated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import ieumAxios from './ieumAxios';

export type EmailCheckResponse = {
check: boolean;
information: {
available: boolean;
};
};

export async function getEmailDuplicated(email: string) {
const url = '/auth/email/' + email;
return await ieumAxios.get<EmailCheckResponse>(url);
}
6 changes: 3 additions & 3 deletions apis/getLetters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export type LettersResponse = {
};
export type LetterType = 'read' | 'unread';

export async function getLetters(type: LetterType, accessToken: string) {
const url = type === 'read' ? '/api/mail/read' : '/api/mailbox';
export async function getLetters(type: LetterType, accessToken: string | null) {
const url = type === 'read' ? '/api/mailbox/read' : '/api/mailbox';
return await ieumAxios.get<LettersResponse>(url, {
headers: { 'Content-Type': 'application/json', accessToken },
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` },
});
}
12 changes: 12 additions & 0 deletions apis/getNickname.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ieumAxios from './ieumAxios';

export type NicknameResponse = {
check: boolean;
information: {
nickname: string[];
};
};

export async function getNickname() {
return await ieumAxios.get<NicknameResponse>('/auth/nickname');
}
13 changes: 13 additions & 0 deletions apis/getNicknameDuplicated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import ieumAxios from './ieumAxios';

export type NicknameDuplicatedResponse = {
check: boolean;
information: {
available: boolean;
};
};

export async function getNicknameDuplicated(nickname: string) {
const url = '/auth/nickname/' + nickname;
return await ieumAxios.get<NicknameDuplicatedResponse>(url);
}
21 changes: 21 additions & 0 deletions apis/getTemp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import ieumAxios from './ieumAxios';

type TempsResponse = {
check: boolean;
information: {
id: number;
title: string;
contents: string;
envelopType: number;
letterType: string;
senderId: number;
receiverId: number | null;
read: boolean;
};
};

export async function getTemp(letterId: number, accessToken: string | null) {
return await ieumAxios.get<TempsResponse>(`/api/letter/temp/${letterId}`, {
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` },
});
}
16 changes: 16 additions & 0 deletions apis/getTemps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ieumAxios from './ieumAxios';

type TempsResponse = {
check: boolean;
information: {
letterId: number;
title: string;
modifiedAt: string;
}[];
};

export async function getTemps(accessToken: string | null) {
return await ieumAxios.get<TempsResponse>('/api/letter/temp-new', {
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` },
});
}
16 changes: 16 additions & 0 deletions apis/getTempsReply.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ieumAxios from './ieumAxios';

type TempsResponse = {
check: boolean;
information: {
letterId: number;
title: string;
modifiedAt: string;
}[];
};

export async function getTempsReply(accessToken: string | null) {
return await ieumAxios.get<TempsResponse>('/api/letter/temp-reply', {
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` },
});
}
12 changes: 8 additions & 4 deletions apis/getUser.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import axios from 'axios';
import ieumAxios from './ieumAxios';

type UserResponse = {
id: string;
nickname: string;
check: boolean;
information: {
id: number;
};
};

export async function getUser(accessToken: string) {
return axios.get<UserResponse>('/api/user');
return ieumAxios.get<UserResponse>('/api/user/verify', {
headers: { Authorization: `Bearer ${accessToken}` },
});
}
5 changes: 5 additions & 0 deletions apis/logout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import ieumAxios from './ieumAxios';

export function logout() {
return ieumAxios.post('/auth/sign-out');
}
29 changes: 29 additions & 0 deletions apis/postCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import ieumAxios from './ieumAxios';
import { authToken } from '@/class/authToken';
import { IeumError } from '@/class/ieumError';
import { AxiosError } from 'axios';

type CheckResponse = {
check: boolean;
information: {
prohibition: number;
};
};

export async function postCheck({ title, contents }: { title: string; contents: string }) {
const accessToken = authToken.getToken();
const response = await ieumAxios.post<CheckResponse>(
'/api/letter/check-gpt',
{
title,
contents,
},
{
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` },
},
);
if (response.data.information.prohibition === 1) {
throw new IeumError(400) as AxiosError;
}
return response;
}
51 changes: 51 additions & 0 deletions apis/postSend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import ieumAxios from './ieumAxios';
import { authToken } from '@/class/authToken';
import { IeumError } from '@/class/ieumError';
import { AxiosError } from 'axios';

type SendResponse = {
check: boolean;
information: {
id: number;
title: string;
contents: string;
envelopType: number;
letterType: string;
senderId: number;
receiverId: number | null;
read: boolean;
};
};

export async function postSend({
title,
contents,
envelopType,
originalLetterId,
letterType,
letterId,
}: {
title: string;
contents: string;
envelopType: number;
originalLetterId: number | null;
letterType: string | undefined;
letterId: number | undefined;
}) {
const accessToken = authToken.getToken();
const response = await ieumAxios.post<SendResponse>(
'/api/letter/send',
{
title,
contents,
envelopType,
originalLetterId,
letterType,
letterId,
},
{ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` } },
);
if (response.data.check === false) {
throw new IeumError(500) as AxiosError;
} else return response;
}
14 changes: 14 additions & 0 deletions apis/postSendAuthNumber.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ieumAxios from './ieumAxios';

type SendAuthNumberResponse = {
check: boolean;
information: {
message: string;
};
};

export async function postSendAuthNumber({ email }: { email: string }) {
return await ieumAxios.post<SendAuthNumberResponse>('/verify/send', {
email,
});
}
35 changes: 35 additions & 0 deletions apis/postSendGpt.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import ieumAxios from './ieumAxios';
import { authToken } from '@/class/authToken';
import { IeumError } from '@/class/ieumError';
import { AxiosError } from 'axios';

type GptResponse = {
check: boolean;
information: {
message: string;
};
};

export async function postSendGpt({
title,
contents,
envelopType,
}: {
title: string;
contents: string;
envelopType: number;
}) {
const accessToken = authToken.getToken();
const response = await ieumAxios.post<GptResponse>(
'/api/letter/send-gpt',
{
title,
contents,
envelopType,
},
{ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` } },
);
if (response.data.check === false) {
throw new IeumError(500) as AxiosError;
} else return response;
}
35 changes: 35 additions & 0 deletions apis/postSendGptReply.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import ieumAxios from './ieumAxios';
import { authToken } from '@/class/authToken';
import { IeumError } from '@/class/ieumError';
import { AxiosError } from 'axios';

type GptResponse = {
check: boolean;
information: {
message: string;
};
};

export async function postSendGptReply({
title,
contents,
envelopType,
}: {
title: string;
contents: string;
envelopType: number;
}) {
const accessToken = authToken.getToken();
const response = await ieumAxios.post<GptResponse>(
'/api/letter/reply-gpt',
{
title,
contents,
envelopType,
},
{ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` } },
);
if (response.data.check === false) {
throw new IeumError(500) as AxiosError;
} else return response;
}
17 changes: 17 additions & 0 deletions apis/postSignUp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import ieumAxios from './ieumAxios';

type SignUpResponse = {
check: boolean;
information: {
accessToken: string;
refreshToken: string;
};
};

export async function postSignUp({ nickname, email, password }: { nickname: string; email: string; password: string }) {
return await ieumAxios.post<SignUpResponse>('/auth/sign-up', {
nickname,
email,
password,
});
}
38 changes: 38 additions & 0 deletions apis/postTemp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import ieumAxios from './ieumAxios';
import { authToken } from '@/class/authToken';
import { IeumError } from '@/class/ieumError';
import { AxiosError } from 'axios';

type TempResponse = {
check: boolean;
information: {
id: number;
title: string;
contents: string;
envelopType: number;
letterType: string;
senderId: number;
receiverId: number | null;
read: boolean;
};
};

export async function postTemp({
originalLetterId,
title,
contents,
}: {
originalLetterId: number | null;
title: string;
contents: string;
}) {
const accessToken = authToken.getToken();
const response = await ieumAxios.post<TempResponse>(
'/api/letter/temp',
{ originalLetterId, title, contents },
{ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` } },
);
if (response.data.check === false) {
throw new IeumError(500) as AxiosError;
} else return response;
}
2 changes: 1 addition & 1 deletion apis/getAccessToken.ts → apis/refreshAccessToken.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ieumAxios from './ieumAxios';

// refresh 토큰으로 accessToken 재발급
export async function getAccessToken() {
export async function refreshAccessToken() {
return ieumAxios.get<{ accessToken: string }>('/api/refresh');
}
Loading

0 comments on commit 629cb8e

Please sign in to comment.