Skip to content

Commit

Permalink
Merge pull request #21 from fastcampus-711/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
JeonYooDeok authored May 28, 2024
2 parents 1d80370 + 90a48ce commit 45e60ed
Show file tree
Hide file tree
Showing 16 changed files with 359 additions and 106 deletions.
2 changes: 1 addition & 1 deletion app/api/community/[category]/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const GET = async (
)
if (response.ok) {
const responseData = await response.json()
return Response.json(responseData)
return Response.json(responseData.data)
} else {
console.error("게시물 불러오기를 실패했습니다.")
}
Expand Down
2 changes: 1 addition & 1 deletion app/api/community/[category]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const GET = async (
if (response.ok) {
console.log(url)
const responseData = await response.json()
return Response.json(responseData)
return Response.json(responseData.data)
} else {
console.error("게시물 불러오기를 실패했습니다.")
}
Expand Down
26 changes: 26 additions & 0 deletions app/api/complaints/[category]/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { NextRequest } from "next/server"

export const GET = async (
request: NextRequest,
context: { params: { category: string; id: string } }
) => {
const { category, id } = context.params

try {
const response = await fetch(
`http://localhost:3001/${category}/${id}`,
// `https://711.ha-ving.store/boards/${category}/${id}`,
{
cache: "no-store"
}
)
if (response.ok) {
const responseData = await response.json()
return Response.json(responseData)
} else {
console.error("게시물 불러오기를 실패했습니다.")
}
} catch (error) {
console.error("에러 발생:", error)
}
}
35 changes: 35 additions & 0 deletions app/api/complaints/[category]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import type { NextRequest } from "next/server"

export const GET = async (
request: NextRequest,
context: { params: { category: string } }
) => {
const { category } = context.params
const { searchParams } = request.nextUrl
let url = `http://localhost:3001/${category}`
// let url = `https://711.ha-ving.store/boards/${category}`

// searchParams가 비어있지 않고, title이 존재하면서 값이 "undefined"가 아닌 경우에만 title을 URL에 추가합니다.
if (
searchParams &&
searchParams.get("keyowrd") !== undefined &&
searchParams.get("keyword") !== "undefined"
) {
url += `?keyword=${searchParams.get("keyword")}`
}

try {
const response = await fetch(url, {
cache: "no-store"
})
if (response.ok) {
console.log(url)
const responseData = await response.json()
return Response.json(responseData)
} else {
console.error("게시물 불러오기를 실패했습니다.")
}
} catch (error) {
console.error("에러 발생:", error)
}
}
28 changes: 28 additions & 0 deletions app/complaints/[category]/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import FreeBoardDetail from "@/components/FreeBoardDetail"
import QnaDetail from "@/components/QnaDetail"
import ShareMarketDetail from "@/components/ShareMarketDetail"

export default async function Page({
params
}: {
params: { category: string; id: string }
}) {
const { category, id } = params

const res = await fetch(
`${process.env.NEXT_PUBLIC_CLIENT_URL}/api/complaints/${category}/${id}`
)
const responseData = await res.json()
let componentProps = { responseData }
let contentComponent

if (category === "allcomplaints") {
contentComponent = <QnaDetail {...componentProps} />
} else if (category === "mycomplaints") {
contentComponent = <ShareMarketDetail {...componentProps} />
} else {
contentComponent = null
}

return <div className="max-w-[1200px] m-auto">{contentComponent}</div>
}
55 changes: 55 additions & 0 deletions app/complaints/[category]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import CommunitySearch from "@/components/CommunitySearch"
import BoardSubMenuBar from "@/components/submenu/SubMenuBar"
import SetCategory from "@/components/SetCategory"
import AllComplaints from "@/components/AllComplaints"
import MyComplaints from "@/components/MyComplaints"

export default async function Page({
params,
searchParams
}: {
params: { category: string }
searchParams: { title: string }
}) {
const { category } = params
const { title } = searchParams

const res = await fetch(
`${process.env.NEXT_PUBLIC_CLIENT_URL}/api/complaints/${category}?keyword=${title}`
)
const responseData = await res.json()
let componentProps = { responseData, category }
let contentComponent

if (category === "allcomplaints") {
contentComponent = <AllComplaints {...componentProps} />
} else if (category === "mycomplaints") {
contentComponent = <MyComplaints {...componentProps} />
} else {
contentComponent = null
}
return (
<div className="max-w-[1200px] m-auto mb-40">
<SetCategory category={category} />
<div className="py-8">
<p className="text-grey_900 text-[32px] font-semibold">민원게시판</p>
</div>
{/* <Link href={"/community/freeboard"}>자유게시판</Link>
<Link href={"/community/sharemarket"}>나눔장터</Link>
<Link href={"/community/qna"}>QnA</Link>
<CommunitySearch category={category} /> */}
<div className="flex justify-between">
<BoardSubMenuBar
option="community"
category={category}
/>
<CommunitySearch
category={category}
placeholder="게시판 내 재검색"
className="flex-1 max-w-[480px]"
/>
</div>
{contentComponent}
</div>
)
}
11 changes: 0 additions & 11 deletions app/complaints/page.tsx

This file was deleted.

101 changes: 52 additions & 49 deletions app/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,110 +9,112 @@ import { setCategory } from "@/redux/slices/categorySlice"
import { AppDispatch } from "@/redux/store"

type Options = {
value: string
value: number
name: string
}

export default function Edit() {
const category = useSelector((state: any) => state.category)
const dispatch = useDispatch<AppDispatch>()
const [selectedBoard, setSelectedBoard] = useState<string>("")
const [selectedType, setSelectedType] = useState<string>("")
const [selectedBoard, setSelectedBoard] = useState<number>(0)
const [selectedType, setSelectedType] = useState<number>(0)
const [typeOptions, setTypeOptions] = useState<Options[]>([])

const boardOptions: Options[] = [
{ value: "자유게시판", name: "자유게시판" },
{ value: "나눔장터", name: "나눔장터" },
{ value: "qna", name: "QnA" }
{ value: 11, name: "자유게시판" },
{ value: 12, name: "나눔장터" },
{ value: 13, name: "QnA" }
]

const optionsA = useMemo(
() => [
{ value: "취미・운동", name: "취미・운동" },
{ value: "생활・편의", name: "생활・편의" },
{ value: "음식・카페", name: "음식・카페" },
{ value: "병원・약국", name: "병원・약국" },
{ value: "수리・시공", name: "수리・시공" },
{ value: "투자・부동산", name: "투자・부동산" },
{ value: "교육・육아", name: "교육・육아" },
{ value: "아파트・동네소식", name: "아파트・동네소식" },
{ value: "여행", name: "여행" },
{ value: "살림정보", name: "살림정보" },
{ value: "모임・동호회", name: "모임・동호회" },
{ value: "기타", name: "기타" }
{ value: 1, name: "생활・편의" },
{ value: 2, name: "음식・카페" },
{ value: 3, name: "병원・약국" },
{ value: 4, name: "수리・시공" },
{ value: 5, name: "투자・부동산" },
{ value: 6, name: "교육・육아" },
{ value: 7, name: "아파트・동네소식" },
{ value: 8, name: "여행" },
{ value: 9, name: "살림정보" },
{ value: 10, name: "모임・동호회" },
{ value: 11, name: "기타" }
],
[]
)

const optionsB = useMemo(
() => [
{ value: "중고거래", name: "중고거래" },
{ value: "무료나눔", name: "무료나눔" }
{ value: 999, name: "중고거래" },
{ value: 999, name: "무료나눔" }
],
[]
)

useEffect(() => {
if (category.value === "frees") {
setSelectedBoard("자유게시판")
setSelectedBoard(11)
} else if (category.value === "markets") {
setSelectedBoard("나눔장터")
setSelectedBoard(12)
} else if (category.value === "qnas") {
setSelectedBoard("qna")
setSelectedBoard(13)
}
}, [category.value])

useEffect(() => {
if (selectedBoard === "자유게시판") {
if (selectedBoard === 11) {
setTypeOptions(optionsA)
} else if (selectedBoard === "나눔장터") {
} else if (selectedBoard === 12) {
setTypeOptions(optionsB)
} else {
setTypeOptions([])
}
}, [selectedBoard, optionsA, optionsB])

const handleBoardChange = (value: string) => {
const handleBoardChange = (value: number) => {
setSelectedBoard(value)
setSelectedType("")
if (value === "자유게시판") {
setSelectedType(0)
if (value === 11) {
dispatch(setCategory("frees"))
} else if (value === "나눔장터") {
} else if (value === 12) {
dispatch(setCategory("markets"))
} else if (value === "qna") {
} else if (value === 13) {
dispatch(setCategory("qnas"))
}
}

const handleTypeChange = (value: string) => {
const handleTypeChange = (value: number) => {
setSelectedType(value)
}

const handleUpdate = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
const formData = new FormData(e.currentTarget)
const issaled = "onsale"
const isnew = true
const category = formData.get("category")
const subcategory = formData.get("subcategory")
// const issaled = "onsale"
// const isnew = true
// const category = formData.get("category")
const category_id = selectedType
const title = formData.get("title")
const content = formData.get("content")
const price = formData.get("price")
const nickname = "userNickname"
const date = getToday()
const visible = true
// const price = formData.get("price")
// const nickname = "userNickname"
// const date = getToday()
const updatedItem = {
issaled: issaled,
isnew: isnew,
category: category,
subcategory: subcategory,
// issaled: issaled,
// isnew: isnew,
// category: category,
category_id: category_id,
title: title,
content: content,
price: price,
nickname: nickname,
date: date
visible: visible
// price: price,
// nickname: nickname,
// date: date
}
const url = `http://localhost:3001/${category}`
// const url = `https://711.ha-ving.store/boards/${category}`
// const url = `http://localhost:3001/${category}`
const url = `https://711.ha-ving.store/boards/${category.value}`
console.log(updatedItem)
try {
const response = await fetch(url, {
method: "POST",
Expand All @@ -132,6 +134,7 @@ export default function Edit() {
console.error("에러 발생:", error)
}
}

return (
<div className="max-w-[1200px] m-auto mb-40">
<div className="flex flex-col gap-10">
Expand All @@ -155,15 +158,15 @@ export default function Edit() {
event={handleBoardChange}
initialValue={selectedBoard}
/>
{selectedBoard !== "qna" && (
{selectedBoard !== 13 && (
<DropDown
label="타입"
options={typeOptions}
event={handleTypeChange}
/>
)}
</div>
{selectedBoard === "나눔장터" && (
{selectedBoard === 12 && (
<tr>
<td className="w-24 text-justify break-all text-grey_900 text-lg font-medium px-4 before:content-[''] before:inline-block before:w-full after:content-[''] after:inline-block after:w-full">
가 격
Expand Down
Loading

0 comments on commit 45e60ed

Please sign in to comment.