-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/107/my gathering api #117
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
Changes from all commits
8ef15db
5b7611f
d425fa7
af134ad
3db442d
bb74db0
58419d9
0140271
4de6c56
e47db68
ec16d69
b90fbb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { fetchApi } from '@/src/utils/api'; | ||
| import { GatheringCardProps } from '@/src/types/gathering-data'; | ||
|
|
||
| export function getHostedGatheringList(startDate: string): Promise<GatheringCardProps[]> { | ||
| const url = `/api/gatherings/hosted?startDate=${startDate}`; | ||
| return fetchApi<{ data: GatheringCardProps[] }>(url, { | ||
| method: 'GET', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| }, | ||
| }).then((response) => response.data); | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,12 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { fetchApi } from '@/src/utils/api'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { GatheringCardProps } from '@/src/types/gathering-data'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| export function getJoinedGatheringList(startDate: string): Promise<GatheringCardProps[]> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const url = `/api/gatherings/joined?startDate=${startDate}`; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return fetchApi<{ data: GatheringCardProps[] }>(url, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| method: 'GET', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'Content-Type': 'application/json', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| }).then((response) => response.data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+4
to
+12
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. π οΈ Refactor suggestion API ꡬνμ λν λͺ κ°μ§ κ°μ μ¬νμ΄ νμν©λλ€. λ€μ μ¬νλ€μ κ³ λ €ν΄μ£ΌμκΈ° λ°λλλ€:
λ€μκ³Ό κ°μ΄ κ°μ νλ κ²μ μ μλ립λλ€: export function getJoinedGatheringList(startDate: string): Promise<GatheringCardProps[]> {
+ if (!startDate || !/^\d{4}-\d{2}-\d{2}$/.test(startDate)) {
+ throw new Error('μ ν¨νμ§ μμ λ μ§ νμμ
λλ€.');
+ }
- const url = `/api/gatherings/joined?startDate=${startDate}`;
+ const url = `/api/gatherings/joined?startDate=${encodeURIComponent(startDate)}`;
return fetchApi<{ data: GatheringCardProps[] }>(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
- }).then((response) => response.data);
+ }).then((response) => response.data)
+ .catch((error) => {
+ console.error('λͺ¨μ λͺ©λ‘μ κ°μ Έμ€λλ° μ€ν¨νμ΅λλ€:', error);
+ throw error;
+ });
}μΆκ°λ‘, μλ΅ νμ μ μμ μ±μ μν΄ zodλ λ€λ₯Έ λ°νμ νμ κ²μ¦ λꡬμ μ¬μ©μ κ³ λ €ν΄λ³΄μκΈ° λ°λλλ€. π Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,10 @@ | ||||||||||||||||||||
| import { getHostedGatheringList } from '@/src/_apis/my-gathering/hosted-gathering-list-apis'; | ||||||||||||||||||||
| import { GatheringCardProps } from '@/src/types/gathering-data'; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export function useGetHostedGatheringListQuery(startDate: string) { | ||||||||||||||||||||
| return { | ||||||||||||||||||||
| queryKey: ['gatheringDetail', startDate], | ||||||||||||||||||||
| queryFn: () => getHostedGatheringList(startDate), | ||||||||||||||||||||
|
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. π οΈ Refactor suggestion μλ¬ μ²λ¦¬ λ‘μ§ μΆκ°λ₯Ό κ²ν ν΄μ£ΌμΈμ. API νΈμΆ μ€ν¨ μμ μλ¬ μ²λ¦¬κ° λλ½λμ΄ μμ΅λλ€. - queryFn: () => getHostedGatheringList(startDate),
+ queryFn: async () => {
+ try {
+ return await getHostedGatheringList(startDate);
+ } catch (error) {
+ console.error('λͺ¨μ λͺ©λ‘μ λΆλ¬μ€λλ° μ€ν¨νμ΅λλ€:', error);
+ throw new Error('λͺ¨μ λͺ©λ‘μ λΆλ¬μ€λλ° μ€ν¨νμ΅λλ€.');
+ }
+ },π Committable suggestion
Suggested change
|
||||||||||||||||||||
| select: (data: GatheringCardProps[]) => data, | ||||||||||||||||||||
| }; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,10 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| import { getJoinedGatheringList } from '@/src/_apis/my-gathering/joined-gathering-list-apis'; | ||||||||||||||||||||||||||||||||||||||||||||||||
| import { GatheringCardProps } from '@/src/types/gathering-data'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| export function useGetJoinedGatheringListQuery(startDate: string) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||
| queryKey: ['gatheringDetail', startDate], | ||||||||||||||||||||||||||||||||||||||||||||||||
| queryFn: () => getJoinedGatheringList(startDate), | ||||||||||||||||||||||||||||||||||||||||||||||||
| select: (data: GatheringCardProps[]) => data, | ||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+4
to
+10
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. π οΈ Refactor suggestion μλ¬ μ²λ¦¬ λ° νμ μμ μ± κ°μ μ΄ νμν©λλ€.
λ€μκ³Ό κ°μ΄ κ°μ ν΄λ³΄μΈμ: -export function useGetJoinedGatheringListQuery(startDate: string) {
+export function useGetJoinedGatheringListQuery(startDate: string) {
+ type ApiResponse = GatheringCardProps[];
+
return {
- queryKey: ['gatheringDetail', startDate],
+ queryKey: ['joinedGatheringList', startDate],
- queryFn: () => getJoinedGatheringList(startDate),
+ queryFn: async (): Promise<ApiResponse> => {
+ try {
+ return await getJoinedGatheringList(startDate);
+ } catch (error) {
+ throw new Error(`λͺ¨μ λͺ©λ‘μ κ°μ Έμ€λλ° μ€ν¨νμ΅λλ€: ${error}`);
+ }
+ },
retry: 1,
staleTime: 5 * 60 * 1000, // 5λΆ
- select: (data: GatheringCardProps[]) => data,
};
}π Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| 'use client'; | ||
|
|
||
| import { useEffect, useState } from 'react'; | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { useGetHostedGatheringListQuery } from '@/src/_queries/my-gathering/hosted-gathering-list-queries'; | ||
| import { formatDateToRequest } from '@/src/utils/format-date'; | ||
| import GatheringListWithDate from '@/src/app/(crew)/my-gathering/_component/gathering-list-with-date'; | ||
| import PopOverCalendar from '@/src/components/common/input/pop-over-calendar'; | ||
| import { GatheringCardProps } from '@/src/types/gathering-data'; | ||
|
|
||
| export default function MyGatheringHostedPage() { | ||
| const [selectedDate, setSelectedDate] = useState(new Date()); | ||
| const [hostedGatheringList, setHostedGatheringList] = useState<GatheringCardProps[]>(); | ||
|
|
||
| const { data, refetch } = useQuery( | ||
| useGetHostedGatheringListQuery(formatDateToRequest(selectedDate)), | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| setHostedGatheringList(data); | ||
| }, [data]); | ||
|
|
||
| useEffect(() => { | ||
| refetch(); | ||
| }, [selectedDate]); | ||
|
|
||
|
Comment on lines
+15
to
+26
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. π οΈ Refactor suggestion 쿼리 λ° μ΄ννΈ μ΅μ νκ° νμν©λλ€
- const { data, refetch } = useQuery(
+ const { data, error, isLoading, refetch } = useQuery(
useGetHostedGatheringListQuery(formatDateToRequest(selectedDate)),
);
- useEffect(() => {
- setHostedGatheringList(data);
- }, [data]);
useEffect(() => {
refetch();
}, [selectedDate]);λ λλ§ λΆλΆλ λ€μκ³Ό κ°μ΄ μμ μ΄ νμν©λλ€: return (
<div>
<div className="py-4 md:py-6">
<PopOverCalendar value={selectedDate} onChange={(d) => setSelectedDate(d)} />
</div>
+ {isLoading && <div>λ‘λ© μ€...</div>}
+ {error && <div>λ°μ΄ν°λ₯Ό λΆλ¬μ€λλ° μ€ν¨νμ΅λλ€</div>}
- {hostedGatheringList && <GatheringListWithDate gatheringList={hostedGatheringList} />}
+ {data && <GatheringListWithDate gatheringList={data} />}
</div>
);
|
||
| return ( | ||
| <div> | ||
| <div className="py-4 md:py-6"> | ||
| <PopOverCalendar value={selectedDate} onChange={(d) => setSelectedDate(d)} /> | ||
| </div> | ||
| {hostedGatheringList && <GatheringListWithDate gatheringList={hostedGatheringList} />} | ||
| </div> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||||||||||||
| 'use client'; | ||||||||||||||||
|
|
||||||||||||||||
| import { useEffect, useState } from 'react'; | ||||||||||||||||
| import { useQuery } from '@tanstack/react-query'; | ||||||||||||||||
| import { useGetJoinedGatheringListQuery } from '@/src/_queries/my-gathering/joined-gathering-list-queries'; | ||||||||||||||||
| import { formatDateToRequest } from '@/src/utils/format-date'; | ||||||||||||||||
| import GatheringListWithDate from '@/src/app/(crew)/my-gathering/_component/gathering-list-with-date'; | ||||||||||||||||
| import PopOverCalendar from '@/src/components/common/input/pop-over-calendar'; | ||||||||||||||||
| import { GatheringCardProps } from '@/src/types/gathering-data'; | ||||||||||||||||
|
|
||||||||||||||||
| export default function MyGatheringJoinedPage() { | ||||||||||||||||
| const [selectedDate, setSelectedDate] = useState(new Date()); | ||||||||||||||||
| const [joinedGatheringList, setJoinedGatheringList] = useState<GatheringCardProps[]>(); | ||||||||||||||||
|
|
||||||||||||||||
|
Comment on lines
+11
to
+14
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. π οΈ Refactor suggestion μλ¬ μν μ²λ¦¬ μΆκ° νμ λ°μ΄ν° λ‘λ© λ° μλ¬ μνλ₯Ό μ²λ¦¬νκΈ° μν μν λ³μλ₯Ό μΆκ°νλ κ²μ΄ μ’μ΅λλ€. λ€μκ³Ό κ°μ΄ μνλ₯Ό μΆκ°νλ κ²μ μ μλ립λλ€: const [selectedDate, setSelectedDate] = useState(new Date());
const [joinedGatheringList, setJoinedGatheringList] = useState<GatheringCardProps[]>();
+ const [error, setError] = useState<Error | null>(null);π Committable suggestion
Suggested change
|
||||||||||||||||
| const { data, refetch } = useQuery( | ||||||||||||||||
| useGetJoinedGatheringListQuery(formatDateToRequest(selectedDate)), | ||||||||||||||||
| ); | ||||||||||||||||
|
Comment on lines
+15
to
+17
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. π οΈ Refactor suggestion useQuery ν μ΅μ ν νμ νμ¬ κ΅¬νμμ μ€μν useQuery κΈ°λ₯λ€μ΄ λλ½λμ΄ μμ΅λλ€. λ€μκ³Ό κ°μ΄ κ°μ νλ κ²μ μ μλ립λλ€: - const { data, refetch } = useQuery(
+ const { data, error, isLoading, refetch } = useQuery(
useGetJoinedGatheringListQuery(formatDateToRequest(selectedDate)),
+ {
+ retry: 1,
+ onError: (error) => setError(error),
+ staleTime: 5 * 60 * 1000, // 5λΆ
+ }
);
|
||||||||||||||||
|
|
||||||||||||||||
| useEffect(() => { | ||||||||||||||||
| setJoinedGatheringList(data); | ||||||||||||||||
| }, [data]); | ||||||||||||||||
|
|
||||||||||||||||
| useEffect(() => { | ||||||||||||||||
| refetch(); | ||||||||||||||||
| }, [selectedDate]); | ||||||||||||||||
|
|
||||||||||||||||
| return ( | ||||||||||||||||
| <div> | ||||||||||||||||
| <div className="py-4 md:py-6"> | ||||||||||||||||
| <PopOverCalendar value={selectedDate} onChange={(d) => setSelectedDate(d)} /> | ||||||||||||||||
| </div> | ||||||||||||||||
| {joinedGatheringList && <GatheringListWithDate gatheringList={joinedGatheringList} />} | ||||||||||||||||
| </div> | ||||||||||||||||
| ); | ||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+27
to
+35
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. π οΈ Refactor suggestion UI μν μ²λ¦¬ λ° μ κ·Όμ± κ°μ νμ λ‘λ© μν, μλ¬ μν νμ λ° μ κ·Όμ± μμ±μ΄ λλ½λμ΄ μμ΅λλ€. λ€μκ³Ό κ°μ κ°μ μ μ μλ립λλ€: return (
- <div>
+ <div role="main" aria-label="μ°Έμ¬ν λͺ¨μ λͺ©λ‘">
<div className="py-4 md:py-6">
<PopOverCalendar value={selectedDate} onChange={(d) => setSelectedDate(d)} />
</div>
+ {isLoading && <div>λ‘λ© μ€...</div>}
+ {error && <div role="alert">λ°μ΄ν°λ₯Ό λΆλ¬μ€λ μ€ μ€λ₯κ° λ°μνμ΅λλ€: {error.message}</div>}
- {joinedGatheringList && <GatheringListWithDate gatheringList={joinedGatheringList} />}
+ {!isLoading && !error && data && <GatheringListWithDate gatheringList={data} />}
</div>
);
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import { redirect } from 'next/navigation'; | ||
|
|
||
| export default function MyGatheringPage() { | ||
| redirect('/my-gathering/participation'); | ||
| redirect('/my-gathering/joined'); | ||
| return null; | ||
| } |
This file was deleted.
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.
π οΈ Refactor suggestion
API ꡬνμ λν κ°μ μ μ
λ€μ μ¬νλ€μ κ³ λ €ν΄ μ£ΌμκΈ° λ°λλλ€:
λ€μκ³Ό κ°μ΄ κ°μ ν΄ λ³΄μλ κ²μ μ μλ립λλ€:
μΆκ°λ‘ λ μ§ μ ν¨μ± κ²μ¬λ₯Ό μν ν¬νΌ ν¨μλ νμν©λλ€: