-
Notifications
You must be signed in to change notification settings - Fork 3
feat: getProjectList, insertProjectItem api 추가 #22
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
Changes from 3 commits
7448603
8b9e1c8
14d81dd
0809a85
42361f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 async function getProjectList(): Promise<ProjectListRes[]> { | ||
| 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 []; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<ProjectListRes[]> => { | ||
| return useQuery({ | ||
| queryKey: ["project-list"], | ||
| queryFn: getProjectList, | ||
| }); | ||
| }; | ||
|
|
||
| export default useProjectList; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 async function insertProjectItem( | ||
| 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 async function updateProjectItem(): Promise<void> { | ||
| return; | ||
| const docRef = doc(db, "coments", "test"); | ||
| await setDoc(docRef, { title: "" }, { merge: true }); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { insertProjectItem } from "@features/projects/api/projdectsApi"; | ||
|
|
||
| import type { ProjectItemInsertReq } from "@entities/projects/types/projects"; | ||
|
|
||
| const useProjectInsert = (): { submit: () => Promise<void> } => { | ||
| const submit = async (): Promise<void> => { | ||
| const res = await insertProjectItem(TestData); | ||
|
|
||
| if (res.success) { | ||
| alert(res.message); | ||
| } else { | ||
| alert(res.message); | ||
| } | ||
| }; | ||
|
Comment on lines
+9
to
+14
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 성공하거나 안하거나 같은 로직인걸로 보이는데 혹시 어떤 이유가 있으실까요??
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 이 훅에 대해 더이상 건들지 않고 민영님께 인계 할 생각이었으므로
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 답변 감사합니다 다빈님 👍👍👍 |
||
|
|
||
| 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년 이상", | ||
| }, | ||
| ], | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <div>ProjectInsertPage</div>; | ||
| const { submit } = useProjectInsert(); | ||
|
|
||
| return ( | ||
| <div> | ||
| ProjectInsertPage | ||
| <button onClick={submit}>Firebase 임시 등록버튼</button> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default ProjectInsertPage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
요고 컨벤션에 맞게 export const getProjectList = async() => {};
방식으로 부탁드리겠습니다 🙇