Skip to content

Commit

Permalink
Merge pull request #362 from TripInfoWeb/dev_refactoring
Browse files Browse the repository at this point in the history
Fix: 여행일기 오류 수정
  • Loading branch information
HyunJinNo authored Sep 22, 2024
2 parents d4336f1 + f6984d6 commit cd30838
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 46 deletions.
18 changes: 5 additions & 13 deletions src/app/api/categories/route.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
// 카테고리 목록 조회
export async function GET() {
try {
const response = await fetch(`${process.env.BACKEND_URL}/api/categories`, {
method: "GET",
next: { revalidate: 60, tags: ["getCategoryList"] },
});
const response = await fetch(`${process.env.BACKEND_URL}/api/categories`, {
method: "GET",
next: { revalidate: 60, tags: ["getCategoryList"] },
});

if (!response.ok) {
throw new Error(response.statusText);
}

return response;
} catch (err) {
return new Response("Internal Server Error", { status: 500 });
}
return response;
}
4 changes: 0 additions & 4 deletions src/app/api/diary/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ export async function PUT(
},
);

if (!response.ok) {
throw new Error(response.statusText);
}

revalidateTag("getDiaryList");
revalidateTag(`getDiary/${params.id}`);
return response;
Expand Down
4 changes: 3 additions & 1 deletion src/app/api/informations/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UpdateInformationRequestDto } from "@/types/InformationDto";
import { revalidatePath } from "next/cache";
import { revalidatePath, revalidateTag } from "next/cache";
import { NextRequest } from "next/server";

/**
Expand Down Expand Up @@ -57,6 +57,7 @@ export async function PUT(
);

// Revalidate the cache
revalidateTag("getBestInformationList");
revalidatePath("/informations", "layout");
return response;
}
Expand All @@ -80,6 +81,7 @@ export async function DELETE(
},
);

revalidateTag("getBestInformationList");
revalidatePath("/informations", "layout");
return response;
}
3 changes: 2 additions & 1 deletion src/app/api/informations/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CreateInformationRequestDto } from "@/types/InformationDto";
import { revalidatePath } from "next/cache";
import { revalidatePath, revalidateTag } from "next/cache";
import { NextRequest } from "next/server";

// 정보 글 작성
Expand All @@ -19,6 +19,7 @@ export async function POST(request: NextRequest) {
});

// Revalidate the cache
revalidateTag("getBestInformationList");
revalidatePath("/informations", "layout");
return response;
}
2 changes: 1 addition & 1 deletion src/components/diary/detail/DiaryViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const DiaryViewer = ({ data, modalVisible, openModal, closeModal }: Props) => {
>
{data.diaryContentResponse.title}
</motion.h1>
<div className="mt-6 flex w-full flex-row items-center justify-between text-lg text-gray1">
<div className="mt-6 flex w-full flex-row flex-wrap items-center justify-between gap-x-12 gap-y-4 text-lg text-gray1">
<motion.p initial={{ opacity: 0 }} animate={{ opacity: 1 }}>
{new Date(
new Date(data.diaryContentResponse.startDatetime).getTime() +
Expand Down
6 changes: 1 addition & 5 deletions src/containers/diary/edit/DiaryEditorContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import DiaryEditor from "@/components/diary/write/DiaryEditor";
import sanitizeOption from "@/constants/common/sanitizeOption";
import { FEELING_STATUS } from "@/constants/diary/feelingStatus";
import { DiaryUpdateFormSchema } from "@/lib/zod/schema/DiaryUpdateFormSchema";
import useAuthStore from "@/store/authStore";
import { GetDiaryResponseDto, UpdateDiaryRequestDto } from "@/types/DiaryDto";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";
Expand All @@ -13,16 +12,15 @@ import { parse } from "node-html-parser";
import { FormProvider, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import usePreventBodyScroll from "@/hooks/usePreventBodyScroll";
import { fetchWithAuth } from "@/utils/fetchWithAuth";
import useModalBackHandler from "@/hooks/useModalBackHandler";
import { fetchWithAuth } from "@/utils/fetchWithAuth";

interface Props {
diaryData: GetDiaryResponseDto;
}

const DiaryEditorContainer = ({ diaryData }: Props) => {
const router = useRouter();
const authStore = useAuthStore();
const [dateRangeModal, setDateRangeModal] = useState<boolean>(false);
const [addressModal, setAddressModal] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(false);
Expand All @@ -35,7 +33,6 @@ const DiaryEditorContainer = ({ diaryData }: Props) => {
useModalBackHandler(addressModal, () => setAddressModal(false));

const methods = useForm<{
userId: number;
title: string;
startDate: Date | null;
endDate: Date | null;
Expand All @@ -46,7 +43,6 @@ const DiaryEditorContainer = ({ diaryData }: Props) => {
}>({
resolver: zodResolver(DiaryUpdateFormSchema),
defaultValues: {
userId: authStore.id,
title: "",
startDate: null,
endDate: null,
Expand Down
4 changes: 0 additions & 4 deletions src/containers/diary/write/DiaryEditorContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import DiaryEditor from "@/components/diary/write/DiaryEditor";
import sanitizeOption from "@/constants/common/sanitizeOption";
import { FEELING_STATUS } from "@/constants/diary/feelingStatus";
import { DiaryCreateFormSchema } from "@/lib/zod/schema/DiaryCreateFormSchema";
import useAuthStore from "@/store/authStore";
import { CreateDiaryRequestDto } from "@/types/DiaryDto";
import { useRouter } from "next/navigation";
import { useState } from "react";
Expand All @@ -18,7 +17,6 @@ import useModalBackHandler from "@/hooks/useModalBackHandler";

const DiaryEditorContainer = () => {
const router = useRouter();
const authStore = useAuthStore();
const [datePickerModal, setDatePickerModal] = useState<boolean>(false);
const [addressModal, setAddressModal] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(false);
Expand All @@ -29,7 +27,6 @@ const DiaryEditorContainer = () => {
useModalBackHandler(addressModal, () => setAddressModal(false));

const methods = useForm<{
userId: number;
title: string;
startDate: Date | null;
endDate: Date | null;
Expand All @@ -40,7 +37,6 @@ const DiaryEditorContainer = () => {
}>({
resolver: zodResolver(DiaryCreateFormSchema),
defaultValues: {
userId: authStore.id,
title: "",
startDate: null,
endDate: null,
Expand Down
3 changes: 0 additions & 3 deletions src/containers/diary/write/QuillEditorContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,8 @@ const QuillEditorContainer = () => {
// https://quilljs.com/docs/modules/toolbar
toolbar: {
container: [
[{ size: ["small", false, "large", "huge"] }, { font: [] }],
[{ color: [] }, { background: [] }],
[{ list: "ordered" }, { list: "bullet" }, { list: "check" }],
["bold", "italic", "underline", "strike"],
[{ indent: "-1" }, { indent: "+1" }, { align: [] }],
["link", "image", "video"],
],
handlers: { image: imageHandler },
Expand Down
7 changes: 0 additions & 7 deletions src/lib/zod/schema/DiaryCreateFormSchema.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { z } from "zod";

export const DiaryCreateFormSchema = z.object({
userId: z
.number({
required_error: "로그인을 해야 일기 작성이 가능합니다.",
invalid_type_error: "UserId must be a integer.",
})
.int()
.positive(),
title: z
.string({
required_error: "제목을 입력해 주세요.",
Expand Down
7 changes: 0 additions & 7 deletions src/lib/zod/schema/DiaryUpdateFormSchema.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { z } from "zod";

export const DiaryUpdateFormSchema = z.object({
userId: z
.number({
required_error: "로그인을 해야 일기 작성이 가능합니다.",
invalid_type_error: "UserId must be a integer.",
})
.int()
.positive(),
title: z
.string({
required_error: "제목을 입력해 주세요.",
Expand Down

0 comments on commit cd30838

Please sign in to comment.