Skip to content

Commit

Permalink
Merge pull request #195 from kakao-tech-campus-2nd-step3/Refactor/iss…
Browse files Browse the repository at this point in the history
…ue-#194

[리팩토링] api, hooks, types 폴더 분리
  • Loading branch information
Diwoni authored Nov 12, 2024
2 parents 54cb46a + 4188dd1 commit 74497c7
Show file tree
Hide file tree
Showing 62 changed files with 141 additions and 138 deletions.
8 changes: 1 addition & 7 deletions src/pages/guard/guide-line/api/add-guideline.api.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { AddGuidelineRequest } from '../types';
import { fetchInstance } from '@/shared/api/instance';

export type AddGuidelineRequest = {
seniorId: number;
type: string;
title: string;
content: string;
};

const addGuidelinePath = () => '/api/guardguidelines';

export const addGuidelineQueryKey = () => [addGuidelinePath()];
Expand Down
8 changes: 1 addition & 7 deletions src/pages/guard/guide-line/api/modify-guideline.api.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import { ModifyGuidelineRequest } from '../types';
import { fetchInstance } from '@/shared/api/instance';

export type ModifyGuidelineRequest = {
seniorId: number;
type: string;
title: string;
content: string;
};

export const modifyGuidelinePath = (guidelineId: number) =>
`/api/guardguidelines/${guidelineId}`;

Expand Down
18 changes: 4 additions & 14 deletions src/pages/guard/guide-line/api/view-senior-all-guideline.api.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import {
SeniorAllGuideLineRequest,
SeniorAllGuideLineResponse,
} from '../types';
import { fetchInstance } from '@/shared/api/instance';

export type SeniorAllGuideLineResponse = SeniorGuideLineData[];

export type SeniorGuideLineData = {
id: number;
type: string;
title: string;
content: string;
};

export type SeniorAllGuideLineRequest = {
seniorId: number;
guidelineType: string;
};

// 특정 시니어의 특정 가이드라인 타입(TAXI, DELIVERY)의 가이드라인 조회
const getSeniorAllGuidelinesPath = (
seniorId?: number,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { ViewSpecificGuidelineResponse } from '../types';
import { fetchInstance } from '@/shared/api/instance';

export type ViewSpecificGuidelineResponse = {
title: string;
content: string;
}[];

const getViewSpecificGuidelinePath = (guidelineId: number) =>
`/api/guideline/${guidelineId}`;

Expand Down
3 changes: 2 additions & 1 deletion src/pages/guard/guide-line/hooks/useAddGuideline.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { addGuideline, AddGuidelineRequest } from '../api/add-guideline.api';
import { addGuideline } from '../api/add-guideline.api';
import { AddGuidelineRequest } from '../types';
import { useMutation, UseMutationResult } from '@tanstack/react-query';

export const useAddGuideline = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
getSeniorAllGuidelines,
getSeniorAllGuidelinesQueryKey,
SeniorAllGuideLineResponse,
} from '../api/view-senior-all-guideline.api';
import { SeniorAllGuideLineResponse } from '../types';
import { useQuery } from '@tanstack/react-query';

export const useGetSeniorAllGuidelines = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
getViewSpecificGuideline,
getViewSpecificGuidelineQueryKey,
ViewSpecificGuidelineResponse,
} from '../api/view-specific-guideline.api';
import { ViewSpecificGuidelineResponse } from '../types';
import { useQuery } from '@tanstack/react-query';

export const useGetViewSpecificGuideline = (guidelineId: number) => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/guard/guide-line/hooks/useGuidelineInfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';

import { ModifyGuidelineRequest } from '../api/modify-guideline.api';
import { ModifyGuidelineRequest } from '../types';
import { UseMutationResult } from '@tanstack/react-query';

type GuidelineInfo = {
Expand Down
6 changes: 2 additions & 4 deletions src/pages/guard/guide-line/hooks/useModifyGuideline.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {
modifyGuideline,
ModifyGuidelineRequest,
} from '../api/modify-guideline.api';
import { modifyGuideline } from '../api/modify-guideline.api';
import { ModifyGuidelineRequest } from '../types';
import { useMutation, UseMutationResult } from '@tanstack/react-query';

export const useModifyGuideline = (
Expand Down
1 change: 1 addition & 0 deletions src/pages/guard/guide-line/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './api';
export * from './components';
export * from './data';
export * from './hooks';
export * from './types';
18 changes: 18 additions & 0 deletions src/pages/guard/guide-line/types/guideline.request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export type AddGuidelineRequest = {
seniorId: number;
type: string;
title: string;
content: string;
};

export type ModifyGuidelineRequest = {
seniorId: number;
type: string;
title: string;
content: string;
};

export type SeniorAllGuideLineRequest = {
seniorId: number;
guidelineType: string;
};
8 changes: 8 additions & 0 deletions src/pages/guard/guide-line/types/guideline.response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { SeniorGuideLineData } from './guidelineData';

export type SeniorAllGuideLineResponse = SeniorGuideLineData[];

export type ViewSpecificGuidelineResponse = {
title: string;
content: string;
}[];
6 changes: 6 additions & 0 deletions src/pages/guard/guide-line/types/guidelineData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type SeniorGuideLineData = {
id: number;
type: string;
title: string;
content: string;
};
3 changes: 3 additions & 0 deletions src/pages/guard/guide-line/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './guideline.request';
export * from './guideline.response';
export * from './guidelineData';
2 changes: 1 addition & 1 deletion src/pages/guard/guide-line/ui/GuideLinePage.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useParams } from 'react-router-dom';

import { SeniorGuideLineData } from '../api/view-senior-all-guideline.api';
import { GuideLineInfo, GuidelineRegisterBox } from '../components';
import { useGetSeniorAllGuidelines } from '../hooks';
import { SeniorGuideLineData } from '../types';
import { PageLayout } from '@/shared';
import { Box, Flex, Text } from '@chakra-ui/react';

Expand Down
2 changes: 1 addition & 1 deletion src/pages/guard/mypage/api/all-senior-info.api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AllSeniorInfoResponse } from './types';
import { AllSeniorInfoResponse } from '../types';
import { fetchInstance } from '@/shared/api/instance';

export const allSeniorInfoPath = () => `/api/guards/senior`;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/guard/mypage/api/guard-information.api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GuardInformationResponse, GuardInformationRequest } from './types';
import { GuardInformationResponse, GuardInformationRequest } from '../types';
import { fetchInstance } from '@/shared/api/instance';

export const guardInformationPath = () => '/api/guards';
Expand Down
2 changes: 0 additions & 2 deletions src/pages/guard/mypage/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ export {
modifyGuardInformation,
} from './guard-information.api';
export { getAllSeniorInfo } from './all-senior-info.api';

export * from './types';
9 changes: 0 additions & 9 deletions src/pages/guard/mypage/api/types/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/pages/guard/mypage/hooks/useGetAllSeniorInfo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AllSeniorInfoResponse } from '../api';
import {
allSeniorInfoPath,
getAllSeniorInfo,
} from '../api/all-senior-info.api';
import { AllSeniorInfoResponse } from '../types';
import { useQuery } from '@tanstack/react-query';

export const allSeniorInfoQueryKey = [allSeniorInfoPath()];
Expand Down
3 changes: 2 additions & 1 deletion src/pages/guard/mypage/hooks/useGetGuardInformation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GuardInformationResponse, getGuardInformation } from '../api';
import { getGuardInformation } from '../api';
import { guardInformationPath } from '../api/guard-information.api';
import { GuardInformationResponse } from '../types';
import { useQuery } from '@tanstack/react-query';

export const getGuardInformationQueryKey = [guardInformationPath()];
Expand Down
1 change: 1 addition & 0 deletions src/pages/guard/mypage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './ui';
export * from './components';
export * from './api';
export * from './hooks';
export * from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,3 @@ export type GuardInformationResponse = {
email: string;
phoneNumber: string;
};

export type GuardInformationRequest = {
name: string;
phoneNumber: string;
};
4 changes: 4 additions & 0 deletions src/pages/guard/mypage/types/guard-information.request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type GuardInformationRequest = {
name: string;
phoneNumber: string;
};
3 changes: 3 additions & 0 deletions src/pages/guard/mypage/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './all-senior-info.response';
export * from './guard-infomation.response';
export * from './guard-information.request';
2 changes: 0 additions & 2 deletions src/pages/guard/register/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ export {
deleteSeniorInfo,
editSeniorInfo,
} from './senior-info.api';

export * from './types';
2 changes: 1 addition & 1 deletion src/pages/guard/register/api/senior-info.api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SeniorRegisterValues as SeniorRegisterRequest } from './types/senior-register.type';
import { SeniorRegisterRequest } from '../types';
import { fetchInstance } from '@/shared/api/instance';

export const seniorInfoPath = () => '/api/guards/senior';
Expand Down
1 change: 0 additions & 1 deletion src/pages/guard/register/api/types/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { SeniorInfoType } from '../../types';
import {
useDeleteSeniorInfo,
useEditSeniorInfo,
Expand All @@ -8,12 +9,6 @@ import { deleteIcon, editIcon } from '@/shared/assets';
import { Box, Flex, Text, Image, Input } from '@chakra-ui/react';
import styled from '@emotion/styled';

type SeniorInfoType = {
seniorName: string;
seniorPhoneNumber: string;
seniorId: number;
};

const SeniorInfo = ({
senior,
refetch,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UseFormRegister } from 'react-hook-form';

import { SeniorRegisterValues } from '../../api';
import { SeniorRegisterRequest as SeniorRegisterValues } from '../../types';
import { Box, Input, Text } from '@chakra-ui/react';
import styled from '@emotion/styled';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useForm } from 'react-hook-form';

import { SeniorRegisterValues } from '../../api';
import { useAddSeniorInfo } from '../../hooks';
import { SeniorRegisterRequest as SeniorRegisterValues } from '../../types';
import SeniorFormField from './SeniorFormField';
import { parsePhoneNumber, BasicButton } from '@/shared';
import { Flex } from '@chakra-ui/react';
Expand Down
2 changes: 1 addition & 1 deletion src/pages/guard/register/hooks/useAddSeniorInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addSeniorInfo } from '../api';
import { SeniorRegisterValues as SeniorRegisterRequest } from '../api/types/senior-register.type';
import { SeniorRegisterRequest } from '../types';
import { useMutation, UseMutationResult } from '@tanstack/react-query';

// 시니어 추가 훅
Expand Down
2 changes: 1 addition & 1 deletion src/pages/guard/register/hooks/useEditSeniorInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { editSeniorInfo } from '../api';
import { SeniorRegisterValues as SeniorRegisterRequest } from '../api/types/senior-register.type';
import { SeniorRegisterRequest } from '../types';
import { useMutation, UseMutationResult } from '@tanstack/react-query';

// 시니어 수정 훅
Expand Down
2 changes: 1 addition & 1 deletion src/pages/guard/register/hooks/useSeniorInfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';

import { SeniorRegisterValues as SeniorRegisterRequest } from '../api/types/senior-register.type';
import { SeniorRegisterRequest } from '../types';
import {
formatPhoneNumber,
parsePhoneNumber,
Expand Down
2 changes: 2 additions & 0 deletions src/pages/guard/register/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './senior-register.request';
export * from './senior-info';
5 changes: 5 additions & 0 deletions src/pages/guard/register/types/senior-info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type SeniorInfoType = {
seniorName: string;
seniorPhoneNumber: string;
seniorId: number;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type SeniorRegisterValues = {
export type SeniorRegisterRequest = {
seniorName: string;
seniorPhoneNumber: string;
};
3 changes: 2 additions & 1 deletion src/pages/guard/register/ui/SeniorRegisterPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useGetAllSeniorInfo } from '../../mypage';
import SeniorInfo from '../components/senior-info/SeniorInfo';
import SeniorRegisterBox from '../components/senior-register-box/SeniorRegisterBox';
import { SeniorInfoType } from '../types';
import { PageLayout } from '@/shared';
import { Box, Flex, Text } from '@chakra-ui/react';
import styled from '@emotion/styled';
Expand Down Expand Up @@ -36,7 +37,7 @@ export const SeniorRegisterPage = () => {
</Box>

<Flex w='full' flexDir='column' gap='var(--space-sm)'>
{seniors?.map((senior) => (
{seniors?.map((senior: SeniorInfoType) => (
<SeniorInfo
key={senior.seniorId}
senior={senior}
Expand Down
1 change: 0 additions & 1 deletion src/pages/guard/review/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './types';
export * from './review.api';
2 changes: 1 addition & 1 deletion src/pages/guard/review/api/review.api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReviewRequest } from './types';
import { ReviewRequest } from '../types';
import { fetchInstance } from '@/shared/api/instance';

export const reviewPath = './api/reviews';
Expand Down
3 changes: 2 additions & 1 deletion src/pages/guard/review/hooks/usePostReview.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { postReview, ReviewRequest } from '../api';
import { postReview } from '../api';
import { ReviewRequest } from '../types';
import { useMutation, UseMutationResult } from '@tanstack/react-query';

export const usePostReview = (): UseMutationResult<
Expand Down
2 changes: 1 addition & 1 deletion src/pages/guard/review/hooks/useReview.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';
import { useNavigate } from 'react-router-dom';

import { ReviewRequest } from '../api';
import { ReviewRequest } from '../types';
import { UseMutationResult } from '@tanstack/react-query';

type Props = {
Expand Down
File renamed without changes.
27 changes: 4 additions & 23 deletions src/pages/guard/service-history/api/get-callback-history.api.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
import {
CallbackHistoryRequestParams,
CallbackHistoryResponse,
} from '../types';
import { fetchInstance } from '@/shared';

export type CallbackHistoryRequestParams = {
page: number;
size: number;
};

export type CallbackHistoryResponse = {
totalElements: number;
totalPages: number;
first: boolean;
last: boolean;
size: number;
content: CallbackHistory[];
number: number;
empty: boolean;
};

export type CallbackHistory = {
callbackId: number;
seniorName: string;
postTime: string;
status: string;
};

const getCallbackHistoryPath = '/api/callbacks/guard/requested';

export const getCallbackHistoryQueryKey = (page: number) => [
Expand Down
Loading

0 comments on commit 74497c7

Please sign in to comment.