Skip to content

Next.js 한상우 sprint12 #734

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

Open
wants to merge 3 commits into
base: Next.js-한상우
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,57 @@
{
"extends": "next/core-web-vitals"
"root": true,
"parser": "@typescript-eslint/parser",

"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module",
"project": "./tsconfig.json"
},
"env": {
// 전역객체를 eslint가 인식하는 구간
"browser": true, // document나 window 인식되게 함
"node": true,
"es6": true
},
"extends": [
"next/core-web-vitals",
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"plugins": [
"eslint-plugin-simple-import-sort",
"prettier",
"react",
"@typescript-eslint"
],

"rules": {
"react/react-in-jsx-scope": "off",
"react/prop-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"react/no-unescaped-entities": "off",
"@next/next/no-page-custom-font": "off",
"react/self-closing-comp": [
"error",
{
"component": true,
"html": true
}
],
"react/jsx-first-prop-new-line": "error",
"indent": ["error", 2, { "SwitchCase": 1 }],
"eol-last": "error",
"no-multiple-empty-lines": ["error", { "max": 1 }],
"semi": ["error", "always"],
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "off",
"comma-spacing": ["error", { "before": false, "after": true }]
}
}
16 changes: 16 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"arrowParens": "always",
"bracketSameLine": false,
"bracketSpacing": true,
"insertPragma": false,
"printWidth": 80,
"proseWrap": "preserve",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleAttributePerLine": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": false
}
18 changes: 18 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"configurations": [
{
"name": "windows-gcc-x86",
"includePath": [
"${workspaceFolder}/**"
],
"compilerPath": "C:/MinGW/bin/gcc.exe",
"cStandard": "${default}",
"cppStandard": "${default}",
"intelliSenseMode": "windows-gcc-x86",
"compilerArgs": [
""
]
}
],
"version": 4
}
24 changes: 24 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "c:/Users/hansw/과제/C언어",
"program": "c:/Users/hansw/과제/C언어/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
59 changes: 59 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
11 changes: 6 additions & 5 deletions app/apis/Axios.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import axios, { AxiosInstance } from "axios";
import { refreshAccessToken } from "./refreshToken";
import axios, { AxiosInstance } from 'axios';

import { refreshAccessToken } from './refreshToken';

const getAccessToken = () => {
if (typeof window !== "undefined") {
return localStorage.getItem("accessToken");
if (typeof window !== 'undefined') {
return localStorage.getItem('accessToken');
}
return null;
};

export const instance: AxiosInstance = axios.create({
baseURL: process.env.NEXT_PUBLIC_BASE_URL,
headers: {
"Content-Type": "application/json",
'Content-Type': 'application/json',
Authorization: `Bearer ${getAccessToken()}`,
},
});
Expand Down
15 changes: 8 additions & 7 deletions app/apis/SignUpUser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AxiosError } from "axios";
import { instance } from "./Axios";
import { AxiosError } from 'axios';

import { instance } from './Axios';

type SignUpData = {
email: string;
Expand All @@ -14,23 +15,23 @@ type SignUpResponse = {

const fetchData = async <T>(
url: string,
data?: SignUpData
data?: SignUpData,
): Promise<T | undefined> => {
try {
const response = await instance.post<T>(url, JSON.stringify(data));
return response.data;
} catch (error) {
if (error instanceof AxiosError) {
console.error("요청 실패 (Axios error):", error.message);
console.error('요청 실패 (Axios error):', error.message);
} else {
console.error("요청 실패 (Unknown error):", error);
console.error('요청 실패 (Unknown error):', error);
}
return undefined;
}
};

export const signUpUser = (
data: SignUpData
data: SignUpData,
): Promise<SignUpResponse | undefined> => {
return fetchData<SignUpResponse>("/auth/signup", data);
return fetchData<SignUpResponse>('/auth/signup', data);
};
4 changes: 2 additions & 2 deletions app/apis/getArticleDetail.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { instance } from "./Axios";
import { instance } from './Axios';

export interface RootObject {
id: number;
Expand Down Expand Up @@ -27,6 +27,6 @@ export async function getArticleDetail(articleId: number): Promise<RootObject> {
const data = res.data;
return data;
} catch (error) {
throw error;
throw new Error('게시글 조회 중 오류 발생');
}
}
54 changes: 54 additions & 0 deletions app/apis/getProducts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { AxiosError } from 'axios';

import { instance } from './Axios';

export interface Product {
id: string;
name: string;
description: string;
price: number;
tags: string[];
images: string[];
favoriteCount: number;
createdAt: string;
ownerId: string;
}

export interface ProductResponse {
totalCount: number;
list: Product[];
}

export interface GetProductsParams {
page?: number;
pageSize?: number;
orderBy?: 'favorite' | 'recent';
keyword?: string;
}

const handleAxiosError = (error: unknown) => {
if (error instanceof AxiosError) {
console.error('Axios error:', error.message);
} else {
console.error('Unknown error:', error);
}
};

export const getProducts = async (
params: GetProductsParams = {},
): Promise<ProductResponse | undefined> => {
try {
const response = await instance.get<ProductResponse>('/products', {
params: {
page: params.page || 1,
pageSize: params.pageSize || 10,
orderBy: params.orderBy,
keyword: params.keyword,
},
});
return response.data;
} catch (error) {
handleAxiosError(error);
return undefined;
}
};
19 changes: 10 additions & 9 deletions app/apis/loginUser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AxiosError } from "axios";
import { instance } from "./Axios";
import { AxiosError } from 'axios';

import { instance } from './Axios';

type LoginData = {
email: string;
Expand All @@ -12,23 +13,23 @@ type LoginResponse = {
};

const loginUser = async (
data: LoginData
data: LoginData,
): Promise<LoginResponse | undefined> => {
try {
const response = await instance.post<LoginResponse>("/auth/signIn", data);
const response = await instance.post<LoginResponse>('/auth/signIn', data);
const { accessToken, refreshToken } = response.data;

if (typeof window !== "undefined") {
localStorage.setItem("accessToken", accessToken);
localStorage.setItem("refreshToken", refreshToken);
if (typeof window !== 'undefined') {
localStorage.setItem('accessToken', accessToken);
localStorage.setItem('refreshToken', refreshToken);
}

return response.data;
} catch (error) {
if (error instanceof AxiosError) {
console.error("요청 실패 (Axios error):", error.message);
console.error('요청 실패 (Axios error):', error.message);
} else {
console.error("요청 실패 (Unknown error):", error);
console.error('요청 실패 (Unknown error):', error);
}
return undefined;
}
Expand Down
1 change: 0 additions & 1 deletion app/apis/postArticle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// postArticle.ts
import { instance } from "./Axios";

export const uploadImage = async (
Expand Down
19 changes: 10 additions & 9 deletions app/boards/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import BoardDetail from "@/components/BoardDetail/BoardDetail";
import CommentInput from "@/components/BoardDetail/CommentInput";
import CommentsList from "@/components/BoardDetail/CommentsList";
import { getComments } from "@/app/apis/getComments";
import { getArticleDetail, RootObject } from "@/app/apis/getArticleDetail";
import styles from "@/app/boards/[id]/Page.module.css";
import backIcon from "@/app/assets/images/ic_back.png";
import Link from "next/link";
import Image from "next/image";
import Image from 'next/image';
import Link from 'next/link';

import { getArticleDetail, RootObject } from '@/app/apis/getArticleDetail';
import { getComments } from '@/app/apis/getComments';
import backIcon from '@/app/assets/images/ic_back.png';
import styles from '@/app/boards/[id]/Page.module.css';
import BoardDetail from '@/components/BoardDetail/BoardDetail';
import CommentInput from '@/components/BoardDetail/CommentInput';
import CommentsList from '@/components/BoardDetail/CommentsList';

interface BoardDetailProps {
params: {
Expand Down
Loading