Skip to content

Commit

Permalink
✨ 통합 검색 추가 (#93)
Browse files Browse the repository at this point in the history
* seminar 타입 정리

* 잘못된 번역 수정

* PostEditor에 메인-중요 안내용 제목 추가

* 공지사항 수정페이지 titleForMain 적용

* 새소식 수정페이지 titleForMain 적용

* titleForMain 마저 적용

* 세미나 리팩토링 및 버그 수정

* 검색 결과 없을 때 화면 추가

* 글 작성 버튼들 추가

* AdjPostNav에 편집 버튼 추가

* AdjPostNav에 삭제 버튼 추가

* deleteIds 마저 적용

* emptyStringtoNull 적용

* isPrivate 기본값 수정

* console.log 제거

* POST reservation api 연결

* /search 페이지 추가

* 통합검색 searchForm 적용

* SearchSubNav 추가

* SectionTitle 구현

* SectionSubtitle, MoreResultLink 구현

* 세미나 목록에서 keyword가 반영 안되는 문제 수정

* 검색 관련 api 추가

* 세미나 검색결과 row 추가

* NoticeRow 구현

* SearchSubNav에 실제 데이터 추가

* NewsRow에 본문 bold 기능 추가

* hideBorder 옵션 row들에 추가

* deploy 옵션 수정

* 변경된 페이지들 리팩토링

* suneditor 스타일 수정

* /faculty 빗금 배경색 수정

* /undergraduate/courses 학점 정렬 버그 수정

* /faculty/[id]에서 올바른 연구실로 가도록 수정

* reservation 수정

* ReservationPreview 타입 추가

* 예약 관련 수정, ReservationDetail 추가

* 대중교통으로 오는 법 표에서 스타일 제거

* 예약 삭제 api 연결

* 시설 안내 사진 적용

* 시설 안내 호버 범위 수정

* index.ts 복구

* 연락처 링크 수정
  • Loading branch information
yeolyi authored Sep 19, 2023
1 parent b390b3f commit 2977157
Show file tree
Hide file tree
Showing 84 changed files with 1,253 additions and 452 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- feat/search

jobs:
build:
Expand Down Expand Up @@ -49,7 +50,7 @@ jobs:
retry_wait_seconds: 1
retry_on: 'error'
command: |
ssh -T -i ./deploy_key -p 22 ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}
ssh -T -i ./deploy_key -p 22 waffle@${{ secrets.SSH_HOST }}
docker ps
docker stop csereal_nextjs_image
docker rm csereal_nextjs_image
Expand Down
21 changes: 19 additions & 2 deletions apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const getRequest = async <T = unknown>(
) => {
const queryString = objToQueryString(params);
const fetchUrl = `${BASE_URL}${url}${queryString}`;
console.log(fetchUrl);
const response = await fetch(fetchUrl, {
...init,
method: 'GET',
Expand All @@ -30,6 +31,9 @@ export const postRequest = async <T = unknown>(url: string, init?: RequestInit)
return responseData as T;
};

export const postRequestWithCookie: typeof postRequest = (url, init) =>
postRequest(url, { ...init, credentials: 'include' });

export const patchRequest = async <T = unknown>(url: string, init?: RequestInit) => {
const fetchUrl = `${BASE_URL}${url}`;
const response = await fetch(fetchUrl, { ...init, method: 'PATCH' });
Expand All @@ -40,15 +44,28 @@ export const patchRequest = async <T = unknown>(url: string, init?: RequestInit)
}
};

export const patchRequestWithCookie: typeof patchRequest = (url, init) =>
patchRequest(url, { ...init, credentials: 'include' });

export const deleteRequest = async (url: string, init?: RequestInit) => {
const fetchUrl = `${BASE_URL}${url}`;
const response = await fetch(fetchUrl, { ...init, method: 'DELETE' });
checkError(response);
};

export const deleteRequestWithCookie: typeof deleteRequest = async (url, init) =>
deleteRequest(url, { ...init, credentials: 'include' });

const checkError = (response: Response) => {
if (!response.ok) {
throw new Error(`네트워크 에러
status: ${response.status}`);
throw new NetworkError(response.status);
}
};

export class NetworkError extends Error {
statusCode: number;
constructor(statusCode: number) {
super(`네트워크 에러\nstatus: ${statusCode}`);
this.statusCode = statusCode;
}
}
4 changes: 2 additions & 2 deletions apis/notice.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Notice, NoticePreviewList, POSTNoticeBody, PatchNoticeBody } from '@/types/notice';
import { PostSearchQueryParams } from '@/types/post';

import { deleteRequest, getRequest, patchRequest, postRequest } from '.';
import { deleteRequest, getRequest, patchRequest, postRequest, postRequestWithCookie } from '.';

const noticePath = '/notice';

Expand All @@ -23,7 +23,7 @@ export const postNotice = async (body: POSTNoticeBody) => {
formData.append('attachments', attachment);
}

await postRequest(noticePath, {
await postRequestWithCookie(noticePath, {
body: formData,
});
};
Expand Down
30 changes: 19 additions & 11 deletions apis/reservation.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
// import { getMockWeeklyReservation, postMockReservation } from '@/data/reservation';

import { cookies } from 'next/dist/client/components/headers';

import { getMockWeeklyReservation } from '@/data/reservation';

import { Reservation, ReservationPostBody } from '@/types/reservation';
import { Reservation, ReservationPostBody, ReservationPreview } from '@/types/reservation';

import { deleteRequest, getRequest, postRequest } from '.';
import {
deleteRequest,
deleteRequestWithCookie,
getRequest,
getRequestWithCookie,
postRequestWithCookie,
} from '.';

const reservationPath = '/reservation';

export const postReservation = async (body: ReservationPostBody) => {
await postRequest(reservationPath, { body: JSON.stringify(body) });
await postRequestWithCookie(reservationPath, {
body: JSON.stringify(body),
headers: { 'Content-Type': 'application/json' },
});
};

export const getWeeklyReservation = async (params: {
Expand All @@ -26,15 +31,18 @@ export const getWeeklyReservation = async (params: {
headers: {
Cookie: `JSESSIONID=${jsessionId?.value}`,
},
})) as Reservation[];
})) as ReservationPreview[];
};

export const getReservation = async (id: number) =>
getRequestWithCookie(`${reservationPath}/${id}`) as Promise<Reservation[]>;

export const deleteSingleReservation = async (id: number) => {
await deleteRequest(`${reservationPath}/${id}`);
await deleteRequestWithCookie(`${reservationPath}/${id}`);
};

export const deleteAllRecurringReservation = async (id: number) => {
await deleteRequest(`${reservationPath}/recurring/${id}`);
export const deleteAllRecurringReservation = async (id: string) => {
await deleteRequestWithCookie(`${reservationPath}/recurring/${id}`);
};

export const roomNameToId = {
Expand Down
86 changes: 86 additions & 0 deletions apis/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { getRequest } from '.';

export const getNoticeSearch = (params: {
keyword: string;
number: number;
}): Promise<NoticeSearchResult> => getRequest('/notice/totalSearch', params);

export const getNewsSearch = (params: {
keyword: string;
number: number;
}): Promise<NewsSearchResult> => getRequest('/news/totalSearch', params);

// export const getNoticeSearch = async (params: {
// keyword: string;
// number: number;
// }): Promise<NoticeSearchResult> => ({
// total: 10,
// results: [
// {
// id: 1,
// title: 'TITLE',
// createdAt: new Date().toISOString(),
// partialDescription: '12345678912345 789',
// boldStartIndex: 3,
// boldEndIndex: 7,
// },
// {
// id: 2,
// title: 'TITLE2',
// createdAt: new Date().toISOString(),
// partialDescription: '12345678912345 789',
// boldStartIndex: 0,
// boldEndIndex: 4,
// },
// {
// id: 3,
// title: 'TITLE3',
// createdAt: new Date().toISOString(),
// partialDescription: '12345678912345 789',
// boldStartIndex: 0,
// boldEndIndex: 4,
// },
// ],
// });

// export const getNewsSearch = async (params: {
// keyword: string;
// number: number;
// }): Promise<NewsSearchResult> => ({
// total: 3,
// results: [
// {
// id: 1,
// title: 'TITLE1',
// date: new Date().toISOString(),
// partialDescription:
// "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
// boldStartIndex: 3,
// boldEndIndex: 7,
// tags: ['TAG1', 'TAG2'],
// imageUrl: null,
// },
// {
// id: 2,
// title: 'TITLE2',
// date: new Date().toISOString(),
// partialDescription:
// "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
// boldStartIndex: 3,
// boldEndIndex: 7,
// tags: ['TAG1', 'TAG2'],
// imageUrl: null,
// },
// {
// id: 3,
// title: 'TITLE3',
// date: new Date().toISOString(),
// partialDescription:
// "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",
// boldStartIndex: 3,
// boldEndIndex: 7,
// tags: ['TAG1', 'TAG2'],
// imageUrl: null,
// },
// ],
// });
48 changes: 36 additions & 12 deletions apis/seminar.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { getMockSeminarPost, getMockSeminarPosts } from '@/data/seminar';
import { PostSearchQueryParams } from '@/types/post';
import { PATCHSeminarBody, POSTSeminarBody, Seminar, SeminarList } from '@/types/seminar';

import {
GETSeminarPostsResponse,
SeminarPostResponse,
PostSearchQueryParams,
POSTSeminarBody,
} from '@/types/post';

import { getRequest, postRequest } from '.';
deleteRequest,
getRequest,
patchRequestWithCookie,
postRequest,
postRequestWithCookie,
} from '.';

const seminarPath = '/seminar';

export const getSeminarPosts = async (params: PostSearchQueryParams) => {
return (await getRequest(seminarPath, params, { cache: 'no-store' })) as GETSeminarPostsResponse;
return (await getRequest(seminarPath, params, { cache: 'no-store' })) as SeminarList;
};

export const getSeminarPost = async (id: number, params: PostSearchQueryParams) => {
return (await getRequest(`${seminarPath}/${id}`, params, {
cache: 'no-store',
})) as SeminarPostResponse;
})) as Seminar;
};

export const postSeminar = async (body: POSTSeminarBody) => {
Expand All @@ -32,11 +32,35 @@ export const postSeminar = async (body: POSTSeminarBody) => {
);

if (body.image) {
formData.append('image', body.image);
formData.append('mainImage', body.image);
}

for (const attachment of body.attachments) {
formData.append('attachments', attachment);
}

return (await postRequest(seminarPath, { body: formData })) as SeminarPostResponse;
await postRequestWithCookie(seminarPath, { body: formData });
};

export const editSeminar = async (id: number, body: PATCHSeminarBody) => {
const formData = new FormData();

formData.append(
'request',
new Blob([JSON.stringify(body.request)], {
type: 'application/json',
}),
);

if (body.image) {
formData.append('mainImage', body.image);
}

for (const attachment of body.newAttachments) {
formData.append('newAttachments', attachment);
}

await patchRequestWithCookie(`${seminarPath}/${id}`, { body: formData });
};

export const deleteSeminar = async (id: number) => deleteRequest(`${seminarPath}/${id}`);
4 changes: 2 additions & 2 deletions app/[locale]/academics/undergraduate/courses/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ const sortCourses = (courses: Course[], sortOption: SortOption) => {
sortedCourses[getSortGroupIndexByClassification(course.classification)].push(course),
);
} else {
sortedCourses.push([], [], []);
courses.forEach((course) => sortedCourses[course.credit - 2].push(course));
sortedCourses.push([], [], [], []);
courses.forEach((course) => sortedCourses[course.credit - 1].push(course));
}

return sortedCourses;
Expand Down
3 changes: 2 additions & 1 deletion app/[locale]/community/news/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export default async function NewsPostPage({ params, searchParams }: NewsPostPag
<AdjPostNav
prevPost={prevPostPreview}
nextPost={nextPostPreview}
href={newsPath}
postType="news"
id={params.id}
margin="mt-12"
/>
</PageLayout>
Expand Down
4 changes: 2 additions & 2 deletions app/[locale]/community/news/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default function NewsCreatePage() {
const router = useRouter();

const handleComplete = async (content: PostEditorContent) => {
console.log(content.description);
throwIfCantSubmit(content);

const mainImage =
Expand All @@ -30,8 +29,9 @@ export default function NewsCreatePage() {
await postNews({
request: {
title: content.title,
titleForMain: content.titleForMain ? content.titleForMain : null,
description: content.description,
isPublic: content.isPublic,
isPrivate: content.isPrivate,
isSlide: content.isSlide,
isImportant: content.isImportant,
tags: content.tags,
Expand Down
5 changes: 3 additions & 2 deletions app/[locale]/community/notice/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default async function NoticePostPage({
<p>
<b>{`'${rawId}'`}</b>는 올바르지 않은 id입니다.
</p>
<AdjPostNav href={noticePath} margin="mt-12" />
<AdjPostNav postType="notice" margin="mt-12" />
</PageLayout>
);
}
Expand All @@ -53,7 +53,8 @@ export default async function NoticePostPage({
<AdjPostNav
prevPost={prevPostPreview}
nextPost={nextPostPreview}
href={noticePath}
postType="notice"
id={rawId}
margin="mt-12"
/>
</PageLayout>
Expand Down
3 changes: 2 additions & 1 deletion app/[locale]/community/notice/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ export default function NoticeCreatePage() {
await postNotice({
request: {
title: content.title,
titleForMain: content.titleForMain ? content.titleForMain : null,
description: content.description,
isPublic: content.isPublic,
isPrivate: content.isPrivate,
isPinned: content.isPinned,
isImportant: content.isImportant,
tags: content.tags,
Expand Down
Loading

0 comments on commit 2977157

Please sign in to comment.