Skip to content

Commit

Permalink
Merge pull request #46 from Team-INSERT/api/post
Browse files Browse the repository at this point in the history
게시판 API 디테일 연동
  • Loading branch information
Ubinquitous authored Aug 15, 2023
2 parents 52a6068 + 8854351 commit f8d7a99
Show file tree
Hide file tree
Showing 62 changed files with 534 additions and 195 deletions.
10 changes: 7 additions & 3 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
domains: ["bssm.kro.kr"],
},
// images: {
// domains: [
// process.env.NEXT_PUBLIC_DOMAIN,
// process.env.NEXT_PUBLIC_TEST_DOMAIN,
// process.env.NEXT_PUBLIC_AUTH_DOMAIN,
// ],
// },
};

module.exports = nextConfig;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"next": "13.4.4",
"prettier": "^2.8.8",
"react": "18.2.0",
"react-cookie": "^4.1.1",
"react-dom": "18.2.0",
"react-query": "^3.39.3",
"react-slick": "^0.29.0",
Expand Down
19 changes: 19 additions & 0 deletions src/apis/cookie/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Cookies } from "react-cookie";

const cookies = new Cookies();

export default class Cookie {
static getItem(key: string) {
return typeof window !== "undefined" ? cookies.get(key) : null;
}

static setItem(key: string, value: string) {
if (typeof window === "undefined") return;
cookies.set(key, value);
}

static delItem(key: string) {
if (typeof window === "undefined") return;
cookies.remove(key);
}
}
27 changes: 23 additions & 4 deletions src/apis/httpClient/httpClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import axios, { AxiosInstance, AxiosRequestConfig } from "axios";
import { requestInterceptors, responseInterceptors } from "@/apis/interceptor";
import { KEY } from "@/constants/";
import { KEY, STORAGE_KEY } from "@/constants/";
import { QueryClient } from "react-query";
import { IPostListQuery } from "@/interfaces";
import Storage from "../storage";

export interface HttpClientConfig {
baseURL?: string;
Expand All @@ -18,6 +20,7 @@ export class HttpClient {
this.api = axios.create({
...axiosConfig,
baseURL: `${axiosConfig.baseURL}${url}`,
withCredentials: true,
});
HttpClient.clientConfig = { headers: { Authorization: "" } };
this.setting();
Expand Down Expand Up @@ -49,7 +52,19 @@ export class HttpClient {
}

getPost(requestConfig?: AxiosRequestConfig) {
return this.api.get("", {
return this.api.get("/:postType/:id", {
...HttpClient.clientConfig,
...requestConfig,
});
}

getPostList(postConfig: IPostListQuery, requestConfig?: AxiosRequestConfig) {
const limit = Storage.getItem(STORAGE_KEY.POST_LIMIT) || 20;

const params = { limit, ...postConfig };

return this.api.get("/:postType", {
params,
...HttpClient.clientConfig,
...requestConfig,
});
Expand All @@ -62,10 +77,13 @@ export class HttpClient {
});
}

postOAuth(data: unknown, requestConfig?: AxiosRequestConfig) {
return this.api.post(`?code=${data}`, {
login(code: unknown, requestConfig?: AxiosRequestConfig) {
return this.api.post("", {
...HttpClient.clientConfig,
...requestConfig,
params: {
code,
},
});
}

Expand Down Expand Up @@ -126,4 +144,5 @@ export default {
user: new HttpClient("api/user", axiosConfig),
timetable: new HttpClient("api/timetable", axiosConfig),
post: new HttpClient("api/post/", axiosConfig),
comment: new HttpClient("api/post/", axiosConfig),
};
3 changes: 0 additions & 3 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
"use client";

import initMockAPI from "@/mocks";
import HomePage from "@/page/home";

if (process.env.NODE_ENV === "development") initMockAPI();

const Home = () => {
return <HomePage />;
};
Expand Down
11 changes: 9 additions & 2 deletions src/app/post/[postType]/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

import PostPage from "@/page/forum-post";

const Post = () => {
return <PostPage />;
interface IPostAppPageParams {
params: {
postType: string;
id: number;
};
}

const Post = ({ params }: IPostAppPageParams) => {
return <PostPage {...params} />;
};

export default Post;
8 changes: 6 additions & 2 deletions src/components/atoms/CommentBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import useEmoji from "@/hooks/useEmoji";
import { AnonymousBox } from "@/components/atoms";
import { EmojiModal } from "@/components/common";

const CommentBox = () => {
interface ICommentBoxProps {
totalComments: number;
}

const CommentBox = ({ totalComments }: ICommentBoxProps) => {
const [isAnonymous, setIsAnonymous] = React.useState(false);
const { openEmoji, closeEmoji, visible } = useEmoji();

return (
<Container>
<CommentCount>124</CommentCount>
<CommentCount>{totalComments}</CommentCount>
<CommentWriteBox>
<CommentTextArea />
<CommentToolBox>
Expand Down
15 changes: 12 additions & 3 deletions src/components/atoms/ImageWithFallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface ImageWithFallbackProps extends ImageProps {
fallbackSrc: StaticImageData | string;
alt: string;
size?: string;
rounded?: boolean;
isShouldHide?: boolean;
}

Expand All @@ -16,6 +17,7 @@ const ImageWithFallback = ({
alt,
size,
isShouldHide,
rounded,
...props
}: ImageWithFallbackProps) => {
const [imgSrc, setImgSrc] = React.useState<StaticImageData | string>(src);
Expand All @@ -27,20 +29,27 @@ const ImageWithFallback = ({
alt={alt}
isShouldHide={isShouldHide}
onError={() => setImgSrc(fallbackSrc)}
width={0}
height={0}
sizes={size}
rounded={rounded}
/>
);
};

const StyledImage = styled(Image)<{ isShouldHide?: boolean }>`
const StyledImage = styled(Image)<{
isShouldHide?: boolean;
rounded?: boolean;
}>`
height: auto;
${({ isShouldHide }) =>
isShouldHide &&
css`
display: none;
`}
${({ rounded }) =>
rounded &&
css`
border-radius: 999px;
`}
`;

export default ImageWithFallback;
24 changes: 12 additions & 12 deletions src/components/common/Aside/InfomationBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,36 @@ import { defaultProfile } from "@/assets/images";
import { USER, ROUTER } from "@/constants";
import { IUser } from "@/interfaces";
import { Row, Column } from "@/components/Flex";
import { getUserRole } from "@/helpers";
import flex from "@/styles/flex";

interface IInfomationBoxProps {
user: IUser;
isLogined: boolean;
}

const InfomationBox = ({ user, isLogined }: IInfomationBoxProps) => {
const ifLoginedStudent = isLogined && user.role === USER.STUDENT;

return (
<Container>
<ProfileImage
src={user.profile ?? defaultProfile}
src={user.profile || defaultProfile}
alt="profile"
width={50}
height={50}
/>
{isLogined && user.role === USER.STUDENT && (
{ifLoginedStudent && (
<>
<Column>
<Row>
<Row gap="4px">
<UserInfoText>{user.student.grade}학년</UserInfoText>
<UserInfoText>{user.student.classNo}</UserInfoText>
<UserInfoText>{user.student.studentNo}</UserInfoText>
</Row>
<Row gap="4px">
<UserName>{user.student.name}</UserName>
<UserType>{user.role}</UserType>
<UserType>{getUserRole(user.role)}</UserType>
</Row>
</Column>
<InfomationButton href={ROUTER.MYPAGE}>내 정보</InfomationButton>
Expand All @@ -52,11 +56,10 @@ const InfomationBox = ({ user, isLogined }: IInfomationBoxProps) => {
};

const Container = styled.main`
${flex.CENTER};
width: 100%;
height: 85px;
background-color: ${color.white};
display: flex;
align-items: center;
gap: 12px;
padding: 0px 18px;
border-radius: 5px;
Expand All @@ -72,27 +75,24 @@ const UserName = styled.span`
`;

const UserType = styled.span`
margin-top: auto;
${font.p3};
color: ${color.gray};
margin-top: auto;
`;

const InfomationButton = styled(Link)`
${flex.CENTER};
${font.btn3};
width: 76px;
height: 26px;
background-color: ${color.primary_blue};
border-radius: 5px;
display: flex;
justify-content: center;
align-items: center;
margin-left: auto;
${font.btn3};
color: ${color.white};
`;

const ProfileImage = styled(Image)`
border-radius: 50%;
background-color: black;
flex-shrink: 0;
`;

Expand Down
8 changes: 4 additions & 4 deletions src/components/common/Aside/MeisterBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const scores = [
type: SERVICE.MEISTER.TYPE,
},
{
name: SERVICE.MEISTER.NAME,
type: SERVICE.MEISTER.TYPE,
name: SERVICE.REWARD_POINTS.NAME,
type: SERVICE.REWARD_POINTS.TYPE,
},
];

Expand All @@ -21,8 +21,8 @@ const MeisterBox = () => {
<ScoreHGroup key={score.type}>
<ScoreName>{score.name}</ScoreName>
<Row gap="4px">
<Score>214.2</Score>
<Rank>48</Rank>
<Score>{score.name === SERVICE.MEISTER.NAME ? 159.8 : 26}</Score>
<Rank>{score.name === SERVICE.MEISTER.NAME ? 11 : 4}</Rank>
</Row>
</ScoreHGroup>
))}
Expand Down
2 changes: 1 addition & 1 deletion src/constants/forum.constant.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const FORUM = {
FREE: {
NAME: "자유",
TYPE: "free",
TYPE: "board",
},
STUDENT: {
NAME: "학생",
Expand Down
1 change: 1 addition & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export { default as ROUTER } from "./router.constant";
export { default as SERVICE } from "./service.constant";
export { default as TOKEN } from "./token.constant";
export { default as USER } from "./user.constant";
export { default as STORAGE_KEY } from "./storageKey.constant";
1 change: 1 addition & 0 deletions src/constants/key.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const KEY = {
USER: "useUser",
TIMETABLE: "useTimetable",
POST: "usePost",
COMMENT: "useComment",
} as const;

export default KEY;
1 change: 1 addition & 0 deletions src/constants/router.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const ROUTER = {
},
TIMETABLE: "/timetable",
MYPAGE: "/mypage",
NOTFOUND: "*",
} as const;

export default ROUTER;
6 changes: 6 additions & 0 deletions src/constants/storageKey.constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const STORAGE_KEY = {
POST_LIMIT: "postLimit",
THEME: "theme",
} as const;

export default STORAGE_KEY;
4 changes: 2 additions & 2 deletions src/constants/token.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export interface IToken {
}

const TOKEN = {
ACCESS: "access_token",
REFRESH: "refresh_token",
ACCESS: "bsm_token_v1",
REFRESH: "bsm_refresh_token_v1",
POST_RENDER_LIMIT: "post_render_limit",
} as const;

Expand Down
2 changes: 2 additions & 0 deletions src/fixture/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as post } from "./post";
export { default as postList } from "./postList";
18 changes: 18 additions & 0 deletions src/fixture/post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IPost } from "@/interfaces";

const post: IPost = {
id: 0,
user: {
code: 0,
nickname: "",
},
category: "all",
content: "",
title: "",
createdAt: "",
view: 0,
totalComments: 0,
totalLikes: 0,
};

export default post;
19 changes: 19 additions & 0 deletions src/fixture/postList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { PostListType } from "@/types";

const postList: PostListType = [
{
id: 0,
user: {
code: 0,
nickname: "",
},
category: "all",
title: "",
createdAt: "",
view: 0,
totalComments: 0,
totalLikes: 0,
},
];

export default postList;
Loading

0 comments on commit f8d7a99

Please sign in to comment.