-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor/#511 프론트의 토큰 만료 검증로직을 삭제하고 Axios를 도입한다. #554
Changes from 20 commits
3ec2b5f
895be60
69605c1
89bdb5f
e10bfbe
f2c79ee
3ecd234
db04ff0
a2bbcee
c287cfe
d06887a
a4a83df
4f858e9
09cf9f3
e6bfcfe
744fbff
2166a72
8e0a22f
0fbcfde
6755702
0f87b75
dbf9655
500cae1
ea5e89b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { client, clientBasic } from '@/shared/remotes/axios'; | ||
import type { AccessTokenRes } from '../types/auth.type'; | ||
|
||
export const getAccessToken = async (platform: string, code: string) => { | ||
const { data } = await client.get<AccessTokenRes>(`/login/${platform}`, { | ||
params: { code }, | ||
}); | ||
|
||
return data; | ||
}; | ||
|
||
export const postRefreshAccessToken = async () => { | ||
const { data } = await clientBasic.post<AccessTokenRes>('/reissue'); | ||
|
||
return data; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface AccessTokenRes { | ||
accessToken: string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { client } from '@/shared/remotes/axios'; | ||
import type { Comment } from '../types/comment.type'; | ||
|
||
export const postComment = async (songId: number, partId: number, content: string) => { | ||
await client.post(`/songs/${songId}/parts/${partId}/comments`, { content }); | ||
}; | ||
|
||
export const getComments = async (songId: number, partId: number) => { | ||
const { data } = await client.get<Comment[]>(`/songs/${songId}/parts/${partId}/comments`); | ||
|
||
return data; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface Comment { | ||
id: number; | ||
content: string; | ||
createdAt: string; | ||
writerNickname: string; | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { client } from '@/shared/remotes/axios'; | ||
import type { KillingPartPostRequest } from '@/shared/types/killingPart'; | ||
import type { SongInfo } from '@/shared/types/song'; | ||
|
||
// PartCollectingPage에 존재하던 remote 함수입니다. | ||
// useFetch<SongInfo>(() => fetcher(`/songs/${songId}`, 'GET')) 로직에서 분리하였습니다. | ||
// SongInfo type에는 killingPart[] 필드가 있는데, 마이파트 수집용 `노래 1개` 조회에서 해당 타입이 사용되고 있습니다. | ||
// 추후 수정되어야 합니다. | ||
|
||
export const getSong = async (songId: number) => { | ||
const { data } = await client.get<SongInfo>(`/songs/${songId}`); | ||
|
||
return data; | ||
}; | ||
|
||
export const postKillingPart = async (songId: number, body: KillingPartPostRequest) => { | ||
await client.post(`/songs/${songId}/member-parts`, body); | ||
}; |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,8 @@ export type LikeKillingPart = Pick< | |
const MyPartList = () => { | ||
const [tab, setTab] = useState<MyPageTab>('Like'); | ||
|
||
const { data: likes } = useFetch<LikeKillingPart[]>(getLikeParts); | ||
const { data: myParts } = useFetch<LikeKillingPart[]>(getMyParts); | ||
const { data: likes } = useFetch(getLikeParts); | ||
const { data: myParts } = useFetch(getMyParts); | ||
Comment on lines
-22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💬 제네릭이 필요 없어졌다면 useFetch도 수정해야되지 않을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 어떤 식으로 수정이 되어야할까요? 생각나는 방향이 있으시면 같이 알려주세용 |
||
|
||
if (!likes || !myParts) { | ||
return null; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import fetcher from '@/shared/remotes'; | ||
import { client } from '@/shared/remotes/axios'; | ||
|
||
export const deleteMember = (memberId: number | undefined) => () => { | ||
return fetcher(`/members/${memberId}`, 'DELETE'); | ||
export const deleteMember = async (memberId: number) => { | ||
await client.delete(`/members/${memberId}`); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import fetcher from '@/shared/remotes'; | ||
import { client } from '@/shared/remotes/axios'; | ||
|
||
export const deleteMemberParts = (partId: number) => fetcher(`/member-parts/${partId}`, 'DELETE'); | ||
export const deleteMemberParts = async (partId: number) => { | ||
await client.delete(`/member-parts/${partId}`); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
import fetcher from '@/shared/remotes'; | ||
import { client } from '@/shared/remotes/axios'; | ||
import type { LikeKillingPart } from '../components/MyPartList'; | ||
|
||
export const getLikeParts = () => fetcher('/my-page/like-parts', 'GET'); | ||
export const getLikeParts = async () => { | ||
const { data } = await client.get<LikeKillingPart[]>('/my-page/like-parts'); | ||
|
||
export const getMyParts = () => fetcher('/my-page/my-parts', 'GET'); | ||
return data; | ||
}; | ||
|
||
export const getMyParts = async () => { | ||
const { data } = await client.get<LikeKillingPart[]>('/my-page/my-parts'); | ||
|
||
return data; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
import fetcher from '@/shared/remotes'; | ||
import { client } from '@/shared/remotes/axios'; | ||
import type { SingerDetail } from '../../singer/types/singer.type'; | ||
import type { SingerSearchPreview } from '../types/search.type'; | ||
|
||
export const getSingerSearchPreview = async (query: string): Promise<SingerSearchPreview[]> => { | ||
const encodedQuery = encodeURIComponent(query); | ||
return await fetcher(`/search?keyword=${encodedQuery}&type=singer`, 'GET'); | ||
export const getSingerSearchPreview = async (query: string) => { | ||
const { data } = await client.get<SingerSearchPreview[]>(`/search`, { | ||
params: { | ||
keyword: query, | ||
type: 'singer', | ||
}, | ||
}); | ||
|
||
return data; | ||
}; | ||
|
||
export const getSingerSearch = async (query: string): Promise<SingerDetail[]> => { | ||
const encodedQuery = encodeURIComponent(query); | ||
return await fetcher(`/search?keyword=${encodedQuery}&type=singer&type=song`, 'GET'); | ||
export const getSingerSearch = async (query: string) => { | ||
const params = new URLSearchParams(); | ||
params.append('keyword', query); | ||
params.append('type', 'singer'); | ||
params.append('type', 'song'); | ||
|
||
Comment on lines
+17
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. axios는 params 값으로 URLSearchParams 인스턴스도 받아용 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
💬 안되는건가요? 아래와 같은 방법으로 충분히 되는 것 같아요. // 1 string
const params = new URLSearchParams(`keyword=${query}&type=singer&type=song`);
// 2 array
const params = new URLSearchParams([
['keyword', query],
['type', 'singer'],
['type', 'song'],
]); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 바로 위에 있는 remote함수와 같은 방식으로 넣을 수 없어서 URLSearchParams 를 썻다~ 가 핵심입니다 ㅋㅋ |
||
const { data } = await client.get<SingerDetail[]>(`/search`, { params }); | ||
|
||
return data; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import fetcher from '@/shared/remotes'; | ||
import { client } from '@/shared/remotes/axios'; | ||
import type { SingerDetail } from '../types/singer.type'; | ||
|
||
export const getSingerDetail = async (singerId: number): Promise<SingerDetail> => { | ||
return await fetcher(`/singers/${singerId}`, 'GET'); | ||
export const getSingerDetail = async (singerId: number) => { | ||
const { data } = await client.get<SingerDetail>(`/singers/${singerId}`); | ||
|
||
return data; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import fetcher from '@/shared/remotes'; | ||
import { client } from '@/shared/remotes/axios'; | ||
|
||
export const putKillingPartLikes = async (songId: number, partId: number, likeStatus: boolean) => { | ||
return await fetcher(`/songs/${songId}/parts/${partId}/likes`, 'PUT', { likeStatus }); | ||
await client.put(`/songs/${songId}/parts/${partId}/likes`, { likeStatus }); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
import fetcher from '@/shared/remotes'; | ||
import { client } from '@/shared/remotes/axios'; | ||
import type { Genre, Song } from '../types/Song.type'; | ||
import type { RecentSong } from '@/shared/types/song'; | ||
|
||
// 메인 케러셀 최신순 노래 n개 조회 api - 쿼리파람 없는경우, 응답 기본값은 5개입니다. | ||
export const getRecentSongs = async (songCount?: number): Promise<RecentSong[]> => { | ||
const query = songCount ? `?size=${songCount}` : ''; | ||
export const getRecentSongs = async (songCount?: number) => { | ||
const { data } = await client.get<RecentSong[]>(`/songs/recent`, { | ||
params: { size: songCount }, | ||
}); | ||
|
||
return await fetcher(`/songs/recent${query}`, 'GET'); | ||
return data; | ||
}; | ||
|
||
export const getHighLikedSongs = async (genre: Genre): Promise<Song[]> => { | ||
const query = genre === 'ALL' ? '' : `?genre=${genre}`; | ||
export const getHighLikedSongs = async (genre: Genre) => { | ||
const { data } = await client.get<Song[]>(`/songs/high-liked`, { | ||
params: { genre: genre === 'ALL' ? null : genre }, | ||
}); | ||
|
||
return await fetcher(`/songs/high-liked${query}`, 'GET'); | ||
return data; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💬 Res가 Response인가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네 맞아요 Res, Req!