Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions src/entities/project/project.ts

This file was deleted.

23 changes: 23 additions & 0 deletions src/entities/projects/api/projectsAPi.ts
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 [];
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요고 컨벤션에 맞게 export const getProjectList = async() => {};
방식으로 부탁드리겠습니다 🙇

13 changes: 13 additions & 0 deletions src/entities/projects/queries/useProjectList.ts
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;
26 changes: 26 additions & 0 deletions src/entities/projects/types/projects.ts
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
}
34 changes: 34 additions & 0 deletions src/features/projects/api/projdectsApi.ts
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: "프로젝트 등록에 실패하였습니다.",
};
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요기도 마찬가지로 부탁드리겠습니다 🙇


/** firebase projects에 item 수정 */
export async function updateProjectItem(): Promise<void> {
return;
const docRef = doc(db, "coments", "test");
await setDoc(docRef, { title: "" }, { merge: true });
}
62 changes: 62 additions & 0 deletions src/features/projects/hook/useProjectInsert.ts
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
Copy link
Contributor

@tkyoun0421 tkyoun0421 Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

성공하거나 안하거나 같은 로직인걸로 보이는데 혹시 어떤 이유가 있으실까요??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 이 훅에 대해 더이상 건들지 않고 민영님께 인계 할 생각이었으므로
이후에 성공 실패에 따라 다른 처리가 들어갈 수 도 있으니 그저 가시성을 위해 나눠놓았습니다.

Copy link
Contributor

Choose a reason for hiding this comment

The 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년 이상",
},
],
};
5 changes: 5 additions & 0 deletions src/pages/home/ui/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
13 changes: 11 additions & 2 deletions src/pages/project-insert/ui/ProjectInsertPage.tsx
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;