diff --git a/src/entities/project/project.ts b/src/entities/project/project.ts deleted file mode 100644 index 7dd5175..0000000 --- a/src/entities/project/project.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { - addDoc, - collection, - doc, - getDoc, - setDoc, -} from "firebase/firestore/lite"; - -import { db } from "@shared/firebase/firebase"; - -export async function getComments(): Promise { - const docRef = doc(db, "coments", "test"); - const docSnap = await getDoc(docRef); - - if (!docSnap.exists()) { - console.log("No such document!"); - return null; - } - - return docSnap.data(); -} - -export async function updateTitle(newTitle: string): Promise { - const docRef = doc(db, "coments", "test"); - await setDoc(docRef, { title: newTitle }, { merge: true }); - console.log("문서가 새로 작성되거나 덮어쓰기 됐어요."); -} - -export async function addPost(title: string): Promise { - const postsRef = collection(db, "posts"); - const docRef = await addDoc(postsRef, { - title, - }); - return docRef.id; -} diff --git a/src/entities/projects/api/projectsAPi.ts b/src/entities/projects/api/projectsAPi.ts new file mode 100644 index 0000000..b768db4 --- /dev/null +++ b/src/entities/projects/api/projectsAPi.ts @@ -0,0 +1,23 @@ +import { collection, getDocs } from "firebase/firestore/lite"; + +import type { ProjectListRes } from "@entities/projects/types/projects"; + +import { db } from "@shared/firebase/firebase"; + +/** firebase project 목록 불러오기 */ +export const getProjectList = async (): Promise => { + try { + const listRef = collection(db, "projects"); + const querySnapshot = await getDocs(listRef); + + const posts = querySnapshot.docs.map((doc) => ({ + id: doc.id, + ...doc.data(), + })); + + return posts as ProjectListRes[]; + } catch (err) { + console.log(err); + return []; + } +}; diff --git a/src/entities/projects/queries/useProjectList.ts b/src/entities/projects/queries/useProjectList.ts new file mode 100644 index 0000000..c72600d --- /dev/null +++ b/src/entities/projects/queries/useProjectList.ts @@ -0,0 +1,13 @@ +import { useQuery, type UseQueryResult } from "@tanstack/react-query"; + +import { getProjectList } from "@entities/projects/api/projectsAPi"; +import type { ProjectListRes } from "@entities/projects/types/projects"; + +const useProjectList = (): UseQueryResult => { + return useQuery({ + queryKey: ["project-list"], + queryFn: getProjectList, + }); +}; + +export default useProjectList; diff --git a/src/entities/projects/types/projects.ts b/src/entities/projects/types/projects.ts new file mode 100644 index 0000000..b2b10ac --- /dev/null +++ b/src/entities/projects/types/projects.ts @@ -0,0 +1,26 @@ +export interface ProjectItemInsertReq { + userId: string; // 작성자 id + userName: string; // 작성사 이름 + status: "모집중" | "모집완료"; + title: string; // 프로젝트 제목 + oneLineInfo: string; // 프로젝트 한줄 소개 + simpleInfo: string; // 프로젝트 간단 소개 + techStack: string[]; // 기술 스택 + teamSize: number; // 팀 규모 + expectedPeriod: string; // 예상기간 + description: string; // 상세 설명 + workflow: string; // 진행방식 + requirements: string[]; // 지원 요구사항 + preferentialTreatment: string[]; // 우대사항 + positions: Positions[]; // 모집 포지션 +} + +interface Positions { + position: string; + count: number; + experience: string; // 경력 +} + +export interface ProjectListRes extends ProjectItemInsertReq { + id: string; // firebase 문서 id +} diff --git a/src/features/projects/api/projdectsApi.ts b/src/features/projects/api/projdectsApi.ts new file mode 100644 index 0000000..82ba6d3 --- /dev/null +++ b/src/features/projects/api/projdectsApi.ts @@ -0,0 +1,34 @@ +import { addDoc, collection, doc, setDoc } from "firebase/firestore/lite"; + +import type { ProjectItemInsertReq } from "@entities/projects/types/projects"; + +import { db } from "@shared/firebase/firebase"; + +/** firebase projects에 item 등록 */ +export const insertProjectItem = async ( + projectItem: ProjectItemInsertReq +): Promise<{ success: boolean; message: string; id?: string }> => { + try { + const postsRef = collection(db, "projects"); + const docRef = await addDoc(postsRef, projectItem); + + return { + success: true, + message: "프로젝트가 성공적으로 등록되었습니다.", + id: docRef.id, + }; + } catch (err) { + console.log(err); + return { + success: false, + message: "프로젝트 등록에 실패하였습니다.", + }; + } +}; + +/** firebase projects에 item 수정 */ +export const updateProjectItem = async (): Promise => { + return; + const docRef = doc(db, "coments", "test"); + await setDoc(docRef, { title: "" }, { merge: true }); +}; diff --git a/src/features/projects/hook/useProjectInsert.ts b/src/features/projects/hook/useProjectInsert.ts new file mode 100644 index 0000000..07521d7 --- /dev/null +++ b/src/features/projects/hook/useProjectInsert.ts @@ -0,0 +1,62 @@ +import { insertProjectItem } from "@features/projects/api/projdectsApi"; + +import type { ProjectItemInsertReq } from "@entities/projects/types/projects"; + +const useProjectInsert = (): { submit: () => Promise } => { + const submit = async (): Promise => { + const res = await insertProjectItem(TestData); + + if (res.success) { + alert(res.message); + } else { + alert(res.message); + } + }; + + return { submit }; +}; + +export default useProjectInsert; + +// 테스트용 form 입니다. +const TestData: ProjectItemInsertReq = { + userId: "user1234", + userName: "홍길동", + status: "모집중", + title: "AI 기반 음악 추천 서비스 개발", + oneLineInfo: "AI로 사용자 취향을 분석하는 음악 추천 프로젝트입니다.", + simpleInfo: "음악 취향 데이터를 기반으로 개인화 추천 시스템을 구현합니다.", + techStack: ["React", "Node.js", "Python", "TensorFlow", "MongoDB"], + teamSize: 5, + expectedPeriod: "3개월", + description: + "이 프로젝트는 사용자의 음악 청취 데이터를 수집하여, AI 알고리즘을 통해 개인화된 추천 서비스를 제공하는 웹 앱을 개발하는 것이 목표입니다.", + workflow: "온라인 협업 (Zoom, GitHub, Notion 사용)", + requirements: [ + "주 2회 이상 정기 미팅 참석 가능", + "기본적인 Git 사용 경험", + "성실한 커뮤니케이션", + ], + preferentialTreatment: [ + "음악 도메인에 관심 있는 분", + "TensorFlow 사용 경험", + "UX/UI에 관심 있는 프론트엔드 개발자", + ], + positions: [ + { + position: "Frontend Developer", + count: 2, + experience: "1년 이상", + }, + { + position: "Backend Developer", + count: 1, + experience: "3년 이상", + }, + { + position: "AI Engineer", + count: 1, + experience: "1년 이상", + }, + ], +}; diff --git a/src/pages/home/ui/HomePage.tsx b/src/pages/home/ui/HomePage.tsx index e24b775..66f3e7e 100644 --- a/src/pages/home/ui/HomePage.tsx +++ b/src/pages/home/ui/HomePage.tsx @@ -1,6 +1,11 @@ import type { JSX } from "react"; +import useProjectList from "@entities/projects/queries/useProjectList"; + const HomePage = (): JSX.Element => { + const { data } = useProjectList(); + + console.log(data); console.log("API_KEY: ", import.meta.env.VITE_API_KEY); return ( diff --git a/src/pages/project-insert/ui/ProjectInsertPage.tsx b/src/pages/project-insert/ui/ProjectInsertPage.tsx index 58aab27..7942792 100644 --- a/src/pages/project-insert/ui/ProjectInsertPage.tsx +++ b/src/pages/project-insert/ui/ProjectInsertPage.tsx @@ -1,7 +1,16 @@ -import type { JSX } from "react"; +import { type JSX } from "react"; + +import useProjectInsert from "@features/projects/hook/useProjectInsert"; const ProjectInsertPage = (): JSX.Element => { - return
ProjectInsertPage
; + const { submit } = useProjectInsert(); + + return ( +
+ ProjectInsertPage + +
+ ); }; export default ProjectInsertPage;