Skip to content

Commit

Permalink
refactor(src): template 조회시 로그인 여부에 따라 설정하던 /login endpoint 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
Hain-tain committed Oct 17, 2024
1 parent 162fce2 commit 06dd488
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
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 }),
});
};

0 comments on commit 06dd488

Please sign in to comment.