Skip to content

Commit

Permalink
๐Ÿ› ๏ธ ๊ณต์šฉ ํƒ€์ž… ์œ„์น˜ ์ด๋™ (#26)
Browse files Browse the repository at this point in the history
- API ๊ณต์šฉ ํƒ€์ž… shared๋กœ ์ด๋™
- api logging ํ•จ์ˆ˜ ์ˆ˜์ •
- Feed ๋ฌดํ•œ ์Šคํฌ๋กค hasNext -> hasNextPage ๋ณ€๊ฒฝ

Closes #24
  • Loading branch information
BangDori authored May 2, 2024
1 parent f20821a commit a5a1c14
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 82 deletions.
14 changes: 3 additions & 11 deletions src/app/mocks/consts/comment.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { Comment } from '@/shared/consts';

import { feeds } from './feed';
import { User, users } from './user';
import { users } from './user';

interface Comments {
[feedId: keyof typeof feeds]: Comment[];
}

interface Comment {
id: number;

user: User;
content: string;

createdAt: string;
updatedAt: string;
}

export const comments: Comments = {
1: [
{
Expand Down
28 changes: 3 additions & 25 deletions src/app/mocks/consts/feed.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,13 @@
import { Feed } from '@/shared/consts';

import { comments } from './comment';
import { likes } from './like';
import { User, users } from './user';
import { users } from './user';

interface Feeds {
[feedId: number]: Feed;
}

interface Feed {
id: number;

user: User;

title: string;
content: string;
images: Image[];

likeCount: number;
commentCount: number;

isLiked: boolean;
isBookmark: boolean;

createdAt: string;
updatedAt: string;
}

interface Image {
id: number;
imageUrl: string;
}

export const feeds: Feeds = {
1: {
id: 1,
Expand Down
7 changes: 2 additions & 5 deletions src/app/mocks/consts/like.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { Like } from '@/shared/consts';

import { feeds } from './feed';

interface Likes {
[feedId: keyof typeof feeds]: Like;
}

interface Like {
totalCount: number;
isLiked: boolean;
}

export const likes: Likes = {
1: { totalCount: 10, isLiked: false },
2: { totalCount: 2, isLiked: true },
Expand Down
9 changes: 2 additions & 7 deletions src/app/mocks/consts/user.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { User } from '@/shared/consts';

interface Users {
[userId: number]: User;
}

export interface User {
id: number;
profileImage: string;
name: string;
content: string;
}

export const users: Users = {
1: {
id: 1,
Expand Down
4 changes: 2 additions & 2 deletions src/app/mocks/handler/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ export const feedHandlers = [

const totalFeeds = Object.values(feeds).length;
const endOfPageRange = formattedPage * pageCount;
const hasNext = endOfPageRange < totalFeeds;
const hasNextPage = endOfPageRange < totalFeeds;

return createHttpSuccessResponse({
feeds: feedsData,
currentPageNumber: pageCount,
pageSize: formattedPage,
numberOfElements: feedsData.length,
hasNext,
hasNextPage,
});
}),

Expand Down
15 changes: 4 additions & 11 deletions src/shared/axios/dir/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ export function logApiRequestOnDev(config: InternalAxiosRequestConfig) {
if (import.meta.env.DEV) {
const { method, url, data } = config;

const title = `${method?.toUpperCase()} ${url}`;

console.group(`๐Ÿ›ซ [API ์š”์ฒญ] ${title}`);
console.groupCollapsed(`๐Ÿ›ซ [API ์š”์ฒญ] ${method?.toUpperCase()} ${url}`);
console.log(`ํ˜„์žฌ ์‹œ๊ฐ: ${getCurrentDate()}`);
console.log(`์š”์ฒญ ๋ฐ์ดํ„ฐ: ${JSON.stringify(data, null, 2) || 'X'}`);
console.groupEnd();
Expand All @@ -28,12 +26,9 @@ export function logApiResponseOnDev(response: AxiosResponse) {
const { method, url } = config;
const { code, data } = response.data;

const title = `${method?.toUpperCase()} ${url}`;
const httpStatus = `${status} ${statusText}`;

console.group(`๐Ÿ›ฌ [API ์‘๋‹ต] ${title}`);
console.groupCollapsed(`๐Ÿ›ฌ [API ์‘๋‹ต] ${method?.toUpperCase()} ${url}`);
console.log(`ํ˜„์žฌ ์‹œ๊ฐ: ${getCurrentDate()}`);
console.log(`HTTP ์‘๋‹ต ์ฝ”๋“œ: ${httpStatus}`);
console.log(`HTTP ์‘๋‹ต ์ฝ”๋“œ: ${status} ${statusText}`);
console.log(`์„œ๋ฒ„ ์‘๋‹ต ์ฝ”๋“œ: ${code}`);
console.log(`์„œ๋ฒ„ ์‘๋‹ต ๋ฐ์ดํ„ฐ: ${JSON.stringify(data, null, 2)}`);
console.groupEnd();
Expand All @@ -45,9 +40,7 @@ export function logApiErrorOnDev(error: AxiosError) {
const { code } = error;
const { method, url } = error.config as AxiosRequestConfig;

const title = `${method?.toUpperCase()} ${url}`;

console.group(`๐Ÿšจ [API ์—๋Ÿฌ] ${title}`);
console.groupCollapsed(`๐Ÿšจ [API ์—๋Ÿฌ] ${method?.toUpperCase()} ${url}`);
console.log(`ํ˜„์žฌ ์‹œ๊ฐ: ${getCurrentDate()}`);
console.log(`์—๋Ÿฌ ์ฝ”๋“œ: ${code}`);
console.log(`์—๋Ÿฌ๋ช…: ${error.message}`);
Expand Down
1 change: 1 addition & 0 deletions src/shared/consts/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { QUERY_KEYS } from './query-key/queryKeys';
export type * from './types';
9 changes: 9 additions & 0 deletions src/shared/consts/types/comment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface Comment {
id: number;

user: User;
content: string;

createdAt: string;
updatedAt: string;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
export interface FeedProps {
feed: Feed;
}

export type FeedList = Feed[];

export interface Feed {
id: number;

Expand All @@ -23,14 +17,7 @@ export interface Feed {
updatedAt: string;
}

interface Image {
export interface Image {
id: number;
imageUrl: string;
}

interface User {
id: number;
profileImage: string;
name: string;
content: string;
}
4 changes: 4 additions & 0 deletions src/shared/consts/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type { Feed, Image } from './feed';
export type { Comment } from './comment';
export type { Like } from './like';
export type { User } from './user';
4 changes: 4 additions & 0 deletions src/shared/consts/types/like.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Like {
totalCount: number;
isLiked: boolean;
}
6 changes: 6 additions & 0 deletions src/shared/consts/types/user.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface User {
id: number;
profileImage: string;
name: string;
content: string;
}
9 changes: 4 additions & 5 deletions src/widgets/feed-main-list/api/useInfinityFeeds.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { useInfiniteQuery } from '@tanstack/react-query';

import { axiosInstance } from '@/shared/axios';
import { QUERY_KEYS } from '@/shared/consts';
import { FeedList } from '@/widgets/feed/consts/type';
import { Feed, QUERY_KEYS } from '@/shared/consts';

interface FetchFeeds {
code: string;
data: {
currentPageNumber: number;
feeds: FeedList;
hasNext: boolean;
feeds: Feed[];
hasNextPage: boolean;
numberOfElements: number;
pageSize: number;
};
Expand All @@ -34,7 +33,7 @@ export const useInfinityFeeds = () => {
queryFn: ({ pageParam }) => fetchFeeds(pageParam),
initialPageParam: 1,
getNextPageParam: (currentPages, _, lastPageParam) => {
return currentPages.data.hasNext ? lastPageParam + 1 : null;
return currentPages.data.hasNextPage ? lastPageParam + 1 : null;
},
});

Expand Down
4 changes: 2 additions & 2 deletions src/widgets/feed/ui/Feed.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Feed as FeedProps } from '@/shared/consts';
import { Icon, Profile } from '@/shared/ui';
import { calculateElapsedTime } from '@/shared/utils';

import './Feed.scss';
import { FeedProps } from '../consts/type';

export const Feed: React.FC<FeedProps> = ({ feed }) => {
export const Feed: React.FC<{ feed: FeedProps }> = ({ feed }) => {
const { user, content, likeCount, commentCount, updatedAt } = feed;

return (
Expand Down

0 comments on commit a5a1c14

Please sign in to comment.