From d75d3e220b39c8feef781a6d7b821848e34ac175 Mon Sep 17 00:00:00 2001 From: gimdogyun Date: Thu, 18 Jan 2024 19:58:42 +0900 Subject: [PATCH 1/5] refactor : merit Api querykey factor - #865 --- src/api/meritApi.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/api/meritApi.ts b/src/api/meritApi.ts index ea05b6cb..a53b9820 100644 --- a/src/api/meritApi.ts +++ b/src/api/meritApi.ts @@ -3,10 +3,11 @@ import axios from 'axios'; import { PageAndSize, MeritLog, MeritType, MembersMerit } from './dto'; const meritKeys = { - meritLog: (param: PageAndSize & { meritType?: string }) => ['meritLog', param] as const, - meritType: (param: PageAndSize) => ['meritType', param] as const, - membersMerit: (param: PageAndSize) => ['membersMerit', param] as const, - memberMerit: (param: PageAndSize & { memberId: number }) => ['memberMerit', param] as const, + base: ['merits'] as const, + meritLog: (param: PageAndSize & { meritType?: string }) => [...meritKeys.base, param] as const, + meritType: (param: PageAndSize) => [...meritKeys.base, 'types', param] as const, + membersMerit: (param: PageAndSize) => [...meritKeys.base, 'members', param] as const, + memberMerit: (memberId: number, param: PageAndSize) => [...meritKeys.base, 'members', memberId, param] as const, }; const useGetMeritLogQuery = ({ page, size = 10, meritType = 'ALL' }: PageAndSize & { meritType?: string }) => { @@ -56,7 +57,7 @@ const useGetMemberMeritQuery = ({ page, size = 10, memberId }: PageAndSize & { m }) .then(({ data }) => data); - return useQuery(meritKeys.memberMerit({ page, size, memberId }), fetcher, { + return useQuery(meritKeys.memberMerit(memberId, { page, size }), fetcher, { keepPreviousData: true, }); }; From 8a587fab3ee2953b766d2096c60b30dee257e2f2 Mon Sep 17 00:00:00 2001 From: gimdogyun Date: Thu, 18 Jan 2024 21:01:47 +0900 Subject: [PATCH 2/5] =?UTF-8?q?refactor=20:=20param=20->=20params=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - #865 --- src/api/meritApi.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/meritApi.ts b/src/api/meritApi.ts index a53b9820..d67e04a1 100644 --- a/src/api/meritApi.ts +++ b/src/api/meritApi.ts @@ -4,10 +4,10 @@ import { PageAndSize, MeritLog, MeritType, MembersMerit } from './dto'; const meritKeys = { base: ['merits'] as const, - meritLog: (param: PageAndSize & { meritType?: string }) => [...meritKeys.base, param] as const, - meritType: (param: PageAndSize) => [...meritKeys.base, 'types', param] as const, - membersMerit: (param: PageAndSize) => [...meritKeys.base, 'members', param] as const, - memberMerit: (memberId: number, param: PageAndSize) => [...meritKeys.base, 'members', memberId, param] as const, + meritLog: (params: PageAndSize & { meritType?: string }) => [...meritKeys.base, params] as const, + meritType: (params: PageAndSize) => [...meritKeys.base, 'types', params] as const, + membersMerit: (params: PageAndSize) => [...meritKeys.base, 'members', params] as const, + memberMerit: (memberId: number, params: PageAndSize) => [...meritKeys.base, 'members', memberId, params] as const, }; const useGetMeritLogQuery = ({ page, size = 10, meritType = 'ALL' }: PageAndSize & { meritType?: string }) => { From 387200fd08d93408aa57a7f86b60d23dd7073393 Mon Sep 17 00:00:00 2001 From: gimdogyun Date: Thu, 18 Jan 2024 21:14:16 +0900 Subject: [PATCH 3/5] =?UTF-8?q?refactor=20:=20members=20key=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - meritKeys 안의 members 분리 - params 묶기 - #865 --- src/api/meritApi.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/api/meritApi.ts b/src/api/meritApi.ts index d67e04a1..4edc5031 100644 --- a/src/api/meritApi.ts +++ b/src/api/meritApi.ts @@ -4,13 +4,16 @@ import { PageAndSize, MeritLog, MeritType, MembersMerit } from './dto'; const meritKeys = { base: ['merits'] as const, + members: () => [...meritKeys.base, 'members'] as const, meritLog: (params: PageAndSize & { meritType?: string }) => [...meritKeys.base, params] as const, meritType: (params: PageAndSize) => [...meritKeys.base, 'types', params] as const, - membersMerit: (params: PageAndSize) => [...meritKeys.base, 'members', params] as const, - memberMerit: (memberId: number, params: PageAndSize) => [...meritKeys.base, 'members', memberId, params] as const, + membersMerit: (params: PageAndSize) => [...meritKeys.members(), params] as const, + memberMerit: (memberId: number, params: PageAndSize) => [...meritKeys.members(), memberId, params] as const, }; const useGetMeritLogQuery = ({ page, size = 10, meritType = 'ALL' }: PageAndSize & { meritType?: string }) => { + const params = { page, size, meritType }; + const fetcher = () => axios .get('/merits', { @@ -18,12 +21,14 @@ const useGetMeritLogQuery = ({ page, size = 10, meritType = 'ALL' }: PageAndSize }) .then(({ data }) => data); - return useQuery(meritKeys.meritLog({ page, size, meritType }), fetcher, { + return useQuery(meritKeys.meritLog(params), fetcher, { keepPreviousData: true, }); }; const useGetMeritTypeQuery = ({ page, size = 10 }: PageAndSize) => { + const params = { page, size }; + const fetcher = () => axios .get('/merits/types', { @@ -31,12 +36,14 @@ const useGetMeritTypeQuery = ({ page, size = 10 }: PageAndSize) => { }) .then(({ data }) => data); - return useQuery(meritKeys.meritType({ page, size }), fetcher, { + return useQuery(meritKeys.meritType(params), fetcher, { keepPreviousData: true, }); }; const useGetMembersMeritQuery = ({ page, size = 10 }: PageAndSize) => { + const params = { page, size }; + const fetcher = () => axios .get('/merits/members', { @@ -44,12 +51,14 @@ const useGetMembersMeritQuery = ({ page, size = 10 }: PageAndSize) => { }) .then(({ data }) => data); - return useQuery(meritKeys.membersMerit({ page, size }), fetcher, { + return useQuery(meritKeys.membersMerit(params), fetcher, { keepPreviousData: true, }); }; const useGetMemberMeritQuery = ({ page, size = 10, memberId }: PageAndSize & { memberId: number }) => { + const params = { page, size }; + const fetcher = () => axios .get(`/merits/members/${memberId}`, { @@ -57,7 +66,7 @@ const useGetMemberMeritQuery = ({ page, size = 10, memberId }: PageAndSize & { m }) .then(({ data }) => data); - return useQuery(meritKeys.memberMerit(memberId, { page, size }), fetcher, { + return useQuery(meritKeys.memberMerit(memberId, params), fetcher, { keepPreviousData: true, }); }; From 0311524d5e8a104f6bc8e56626a6adf1eb4c7b5f Mon Sep 17 00:00:00 2001 From: gimdogyun Date: Thu, 18 Jan 2024 21:15:10 +0900 Subject: [PATCH 4/5] =?UTF-8?q?refactor=20:=20point=20Api=20params=20?= =?UTF-8?q?=EB=AC=B6=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #865 --- src/api/pointApi.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/api/pointApi.ts b/src/api/pointApi.ts index afca1c58..a7e658d5 100644 --- a/src/api/pointApi.ts +++ b/src/api/pointApi.ts @@ -7,9 +7,11 @@ const pointKeys = { }; const useGetPointLogQuery = ({ page, size = 10 }: PageAndSize) => { - const fetcher = () => axios.get('/points', { params: { page, size } }).then(({ data }) => data); + const params = { page, size }; - return useQuery(pointKeys.pointLog({ page, size }), fetcher, { + const fetcher = () => axios.get('/points', { params }).then(({ data }) => data); + + return useQuery(pointKeys.pointLog(params), fetcher, { keepPreviousData: true, }); }; From 074414b110fee48dc2caba5e0af14cfdaa91ec97 Mon Sep 17 00:00:00 2001 From: gimdogyun Date: Thu, 18 Jan 2024 21:17:20 +0900 Subject: [PATCH 5/5] =?UTF-8?q?refactor=20:=20merit=20Api=20fetcher=20para?= =?UTF-8?q?ms=20=EB=AC=B6=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - #865 --- src/api/meritApi.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api/meritApi.ts b/src/api/meritApi.ts index 4edc5031..0c44cf77 100644 --- a/src/api/meritApi.ts +++ b/src/api/meritApi.ts @@ -17,7 +17,7 @@ const useGetMeritLogQuery = ({ page, size = 10, meritType = 'ALL' }: PageAndSize const fetcher = () => axios .get('/merits', { - params: { page, size, meritType }, + params, }) .then(({ data }) => data); @@ -32,7 +32,7 @@ const useGetMeritTypeQuery = ({ page, size = 10 }: PageAndSize) => { const fetcher = () => axios .get('/merits/types', { - params: { page, size }, + params, }) .then(({ data }) => data); @@ -47,7 +47,7 @@ const useGetMembersMeritQuery = ({ page, size = 10 }: PageAndSize) => { const fetcher = () => axios .get('/merits/members', { - params: { page, size }, + params, }) .then(({ data }) => data); @@ -62,7 +62,7 @@ const useGetMemberMeritQuery = ({ page, size = 10, memberId }: PageAndSize & { m const fetcher = () => axios .get(`/merits/members/${memberId}`, { - params: { page, size }, + params, }) .then(({ data }) => data);