Skip to content
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

api 변경에 따른 /login 엔드포인트 제거 #808

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frontend/playwright/tests/search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('검색창에 `검색테스트`를 입력하면 `검색테스트`가 내용

await searchTemplates({ page, keyword });

await waitForSuccess({ page, apiUrl: '/templates/login?keyword' });
await waitForSuccess({ page, apiUrl: '/templates?keyword' });
await expect(page.getByRole('link', { name: /검색테스트/ })).toBeVisible();
});

Expand All @@ -23,6 +23,6 @@ test('검색창에 `ㅁㅅㅌㅇ`를 입력할 경우 `검색 결과가 없습

await searchTemplates({ page, keyword });

await waitForSuccess({ page, apiUrl: '/templates/login?keyword' });
await waitForSuccess({ page, apiUrl: '/templates?keyword' });
await expect(page.locator('div').filter({ hasText: /^검색 결과가 없습니다\.$/ })).toBeVisible();
});
2 changes: 1 addition & 1 deletion frontend/playwright/tests/templates.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test('템플릿 카드를 누르면 템플릿 제목, 설명, 작성자, 생성
}) => {
await page.goto('/my-templates');
// 템플릿 목록
await waitForSuccess({ page, apiUrl: '/templates/login?keyword' });
await waitForSuccess({ page, apiUrl: '/templates?keyword' });

const templateCard = page.getByRole('link', { name: '상세조회테스트' });

Expand Down
9 changes: 4 additions & 5 deletions frontend/src/api/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const getTemplateList = async ({
queryParams.append('keyword', keyword);
}

const url = `${TEMPLATE_API_URL}${memberId ? '/login' : ''}?${queryParams.toString()}`;
const url = `${TEMPLATE_API_URL}?${queryParams.toString()}`;

const response = await customFetch<TemplateListResponse>({
url,
Expand All @@ -83,7 +83,6 @@ export const getTemplateExplore = async ({
sort = DEFAULT_SORTING_OPTION.key,
page = 1,
size = PAGE_SIZE,
memberId,
keyword,
}: TemplateListRequest) => {
const queryParams = new URLSearchParams({
Expand All @@ -96,7 +95,7 @@ export const getTemplateExplore = async ({
queryParams.append('keyword', keyword);
}

const url = `${TEMPLATE_API_URL}${memberId ? '/login' : ''}?${queryParams.toString()}`;
const url = `${TEMPLATE_API_URL}?${queryParams.toString()}`;

const response = await customFetch<TemplateListResponse>({
url,
Expand All @@ -109,9 +108,9 @@ export const getTemplateExplore = async ({
throw new Error(response.detail);
};

export const getTemplate = async ({ id, memberId }: TemplateRequest) => {
export const getTemplate = async ({ id }: TemplateRequest) => {
const response = await customFetch<Template>({
url: `${TEMPLATE_API_URL}/${id}${memberId ? '/login' : ''}`,
url: `${TEMPLATE_API_URL}/${id}`,
});

if ('sourceCodes' in response) {
Expand Down
15 changes: 4 additions & 11 deletions frontend/src/queries/templates/useTemplateExploreQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { keepPreviousData, useQuery } from '@tanstack/react-query';
import { PAGE_SIZE, QUERY_KEY, DEFAULT_SORTING_OPTION, getTemplateExplore } from '@/api';
import type { TemplateListResponse, SortingKey } from '@/types';

import { useAuth } from '../../hooks/authentication/useAuth';

interface Props {
sort?: SortingKey;
page?: number;
Expand All @@ -17,15 +15,10 @@ export const useTemplateExploreQuery = ({
page = 1,
size = PAGE_SIZE,
keyword,
}: Props) => {
const {
memberInfo: { memberId },
} = useAuth();

return useQuery<TemplateListResponse, Error>({
queryKey: [QUERY_KEY.TEMPLATE_LIST, sort, page, size, keyword, memberId],
queryFn: () => getTemplateExplore({ sort, page, size, keyword, memberId }),
}: Props) =>
useQuery<TemplateListResponse, Error>({
queryKey: [QUERY_KEY.TEMPLATE_LIST, sort, page, size, keyword],
queryFn: () => getTemplateExplore({ sort, page, size, keyword }),
throwOnError: true,
placeholderData: keepPreviousData,
});
};
15 changes: 4 additions & 11 deletions frontend/src/queries/templates/useTemplateQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,8 @@ import { UseQueryResult, useQuery } from '@tanstack/react-query';
import { QUERY_KEY, getTemplate } from '@/api';
import type { Template } from '@/types';

import { useAuth } from '../../hooks/authentication/useAuth';

export const useTemplateQuery = (id: number): UseQueryResult<Template, Error> => {
const {
memberInfo: { memberId },
} = useAuth();

return useQuery<Template, Error>({
queryKey: [QUERY_KEY.TEMPLATE, id, memberId],
queryFn: () => getTemplate({ id, memberId }),
export const useTemplateQuery = (id: number): UseQueryResult<Template, Error> =>
useQuery<Template, Error>({
queryKey: [QUERY_KEY.TEMPLATE, id],
queryFn: () => getTemplate({ id }),
});
};