Skip to content

Commit 4a6c1a9

Browse files
committed
refac: sponsor-api code
1 parent 5e7c4f7 commit 4a6c1a9

File tree

6 files changed

+29
-76
lines changed

6 files changed

+29
-76
lines changed

frontend/pages/api/sponsor.ts

Lines changed: 19 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,26 @@
11
import axios from 'axios'
22
import { IContents } from '../../interfaces/IContents'
33
import { IApiContents } from '../../interfaces/api/IApiContents'
4-
5-
export const getSponsorProspectus = async (): Promise<IContents> => {
6-
const response = await axios.get(
7-
`https://api.2022.pycon.kr/api/content/prospectus`
8-
)
9-
const data: IApiContents = response.data
10-
11-
return {
12-
content: {
13-
ko: data.content,
14-
en: data.eng_content
4+
import { API_SERVER } from '../../data/constants/config';
5+
6+
type GetSponsorDataProps = 'prospectus' | 'sporsor-benefit' | 'sponsor-join' | 'sponsor-faq' | 'terms-of-sponsor';
7+
8+
export const getSponsorData = async (endPoint: GetSponsorDataProps): Promise<IContents> => {
9+
try {
10+
const response = await axios.get(
11+
`${API_SERVER}/content/${endPoint}`
12+
)
13+
const data: IApiContents = response.data
14+
15+
return {
16+
content: {
17+
ko: data.content,
18+
en: data.eng_content
19+
}
1520
}
21+
} catch (error) {
22+
window?.alert('일시적인 오류가 발생하였습니다. 잠시 후 다시 시도해 주세요.')
1623
}
24+
1725
}
1826

19-
export const getSponsorBenefit = async (): Promise<IContents> => {
20-
const response = await axios.get(
21-
`https://api.2022.pycon.kr/api/content/sporsor-benefit`
22-
)
23-
const data: IApiContents = response.data
24-
25-
return {
26-
content: {
27-
ko: data.content,
28-
en: data.eng_content
29-
}
30-
}
31-
}
32-
33-
export const getSponsorJoin = async (): Promise<IContents> => {
34-
const response = await axios.get(
35-
`https://api.2022.pycon.kr/api/content/sponsor-join`
36-
)
37-
const data: IApiContents = response.data
38-
39-
return {
40-
content: {
41-
ko: data.content,
42-
en: data.eng_content
43-
}
44-
}
45-
}
46-
47-
export const getSponsorFaq = async (): Promise<IContents> => {
48-
const response = await axios.get(
49-
`https://api.2022.pycon.kr/api/content/sponsor-faq`
50-
)
51-
const data: IApiContents = response.data
52-
53-
return {
54-
content: {
55-
ko: data.content,
56-
en: data.eng_content
57-
}
58-
}
59-
}
60-
61-
export const getSponsorTerms = async (): Promise<IContents> => {
62-
const response = await axios.get(
63-
`https://api.2022.pycon.kr/api/content/terms-of-sponsor`
64-
)
65-
const data: IApiContents = response.data
66-
67-
return {
68-
content: {
69-
ko: data.content,
70-
en: data.eng_content
71-
}
72-
}
73-
}

frontend/pages/sponsor/benefit.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { NextPage, GetServerSideProps } from 'next'
33
import { PageName } from '../../data/enums/PageName'
44
import { SponsorPage } from '../../interfaces/PageProps'
55
import { GetServerSidePropsContext } from 'next'
6-
import { getSponsorBenefit } from '../api/sponsor'
6+
import { getSponsorData } from '../api/sponsor'
77
import ReactMarkdown from 'react-markdown'
88
import HeadingComponents from '../../components/core/MarkdownHeadings'
99
import MarkdownStyle from '../../assets/styles/markdown'
@@ -32,7 +32,7 @@ export const getServerSideProps: GetServerSideProps = async (
3232
context: GetServerSidePropsContext
3333
) => {
3434
const { locale } = context
35-
const content = await getSponsorBenefit()
35+
const content = await getSponsorData('sporsor-benefit')
3636

3737
return {
3838
props: {

frontend/pages/sponsor/faq.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { NextPage, GetServerSideProps } from 'next'
33
import { PageName } from '../../data/enums/PageName'
44
import { SponsorPage } from '../../interfaces/PageProps'
55
import { GetServerSidePropsContext } from 'next'
6-
import { getSponsorFaq } from '../api/sponsor'
6+
import { getSponsorData } from '../api/sponsor'
77
import ReactMarkdown from 'react-markdown'
88
import HeadingComponents from '../../components/core/MarkdownHeadings'
99
import MarkdownStyle from '../../assets/styles/markdown'
@@ -34,7 +34,7 @@ export const getServerSideProps: GetServerSideProps = async (
3434
context: GetServerSidePropsContext
3535
) => {
3636
const { locale } = context
37-
const content = await getSponsorFaq()
37+
const content = await getSponsorData('sponsor-faq')
3838

3939
return {
4040
props: {

frontend/pages/sponsor/join.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ReactMarkdown from 'react-markdown'
77
import HeadingComponents from '../../components/core/MarkdownHeadings'
88
import MarkdownStyle from '../../assets/styles/markdown'
99
import PageTitle from '../../components/core/PageTitle'
10-
import { getSponsorJoin } from '../api/sponsor'
10+
import { getSponsorData } from '../api/sponsor'
1111
import remarkGfm from 'remark-gfm'
1212

1313
interface SponsorSponsorJoinPage extends SponsorPage {
@@ -34,7 +34,7 @@ export const getServerSideProps: GetServerSideProps = async (
3434
context: GetServerSidePropsContext
3535
) => {
3636
const { locale } = context
37-
const content = await getSponsorJoin()
37+
const content = await getSponsorData('sponsor-join')
3838

3939
return {
4040
props: {

frontend/pages/sponsor/prospectus.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { GetServerSideProps, GetServerSidePropsContext, NextPage } from 'next'
33
import { SponsorPage } from '../../interfaces/PageProps'
44
import { PageName } from '../../data/enums/PageName'
55
import PageTitle from '../../components/core/PageTitle'
6-
import { getSponsorProspectus } from '../api/sponsor'
6+
import { getSponsorData } from '../api/sponsor'
77
import MarkdownStyle from '../../assets/styles/markdown'
88
import ReactMarkdown from 'react-markdown'
99
import HeadingComponents from '../../components/core/MarkdownHeadings'
@@ -33,7 +33,7 @@ export const getServerSideProps: GetServerSideProps = async (
3333
context: GetServerSidePropsContext
3434
) => {
3535
const { locale } = context
36-
const content = await getSponsorProspectus()
36+
const content = await getSponsorData('prospectus')
3737

3838
return {
3939
props: {

frontend/pages/sponsor/terms-of-sponsor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { GetServerSideProps, GetServerSidePropsContext, NextPage } from 'next'
33
import { SponsorPage } from '../../interfaces/PageProps'
44
import { useTranslation } from 'react-i18next'
55
import { PageName } from '../../data/enums/PageName'
6-
import { getSponsorTerms } from '../api/sponsor'
6+
import { getSponsorData } from '../api/sponsor'
77
import MarkdownStyle from '../../assets/styles/markdown'
88
import ReactMarkdown from 'react-markdown'
99
import HeadingComponents from '../../components/core/MarkdownHeadings'
@@ -35,7 +35,7 @@ const SponsorTerms: NextPage = (props: TermsOfSponsorPage) => {
3535
export const getServerSideProps: GetServerSideProps = async (
3636
context: GetServerSidePropsContext
3737
) => {
38-
const content = await getSponsorTerms()
38+
const content = await getSponsorData('terms-of-sponsor')
3939
const { locale } = context
4040

4141
return {

0 commit comments

Comments
 (0)