From 84e1031f6e29572e098e6cdb0698193c6b807dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9C=A4=EB=8B=A4=EB=B9=88?= <116141225+czmcm5@users.noreply.github.com> Date: Tue, 24 Jun 2025 01:32:55 +0900 Subject: [PATCH 1/2] =?UTF-8?q?chore:=20firebase=20=EC=97=B0=EB=8F=99=20?= =?UTF-8?q?=EB=B0=8F=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/project/project.ts | 35 +++++++++++++++++++++++++++++++++ src/shared/firebase/firebase.ts | 15 ++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/entities/project/project.ts create mode 100644 src/shared/firebase/firebase.ts diff --git a/src/entities/project/project.ts b/src/entities/project/project.ts new file mode 100644 index 0000000..46a5251 --- /dev/null +++ b/src/entities/project/project.ts @@ -0,0 +1,35 @@ +import { + addDoc, + collection, + doc, + getDoc, + setDoc, +} from "firebase/firestore/lite"; + +import { db } from "@shared/firebase/firebase"; + +export async function getComments() { + 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) { + const docRef = doc(db, "coments", "test"); + await setDoc(docRef, { title: newTitle }, { merge: true }); + console.log("문서가 새로 작성되거나 덮어쓰기 됐어요."); +} + +export async function addPost(title: string) { + const postsRef = collection(db, "posts"); + const docRef = await addDoc(postsRef, { + title, + }); + return docRef.id; +} diff --git a/src/shared/firebase/firebase.ts b/src/shared/firebase/firebase.ts new file mode 100644 index 0000000..2997d57 --- /dev/null +++ b/src/shared/firebase/firebase.ts @@ -0,0 +1,15 @@ +import { initializeApp } from "firebase/app"; +import { getFirestore } from "firebase/firestore/lite"; + +const firebaseConfig = { + apiKey: process.env.REACT_APP_API_KEY, + authDomain: process.env.REACT_APP_AUTH_DOMAIN, + projectId: process.env.REACT_APP_PROJECT_ID, + storageBucket: process.env.REACT_APP_STORAGE_BUCKET, + messagingSenderId: process.env.REACT_APP_MESSAGEINGSENDER_ID, + appId: process.env.REACT_APP_APP_ID, + measurementId: process.env.REACT_APP_MEASUREMENT_ID, +}; + +const app = initializeApp(firebaseConfig); +export const db = getFirestore(app); From a61a6720ad6c4f2d34300af7a17280da4a64c040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9C=A4=EB=8B=A4=EB=B9=88?= <116141225+czmcm5@users.noreply.github.com> Date: Tue, 24 Jun 2025 01:49:25 +0900 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20=ED=95=A8=EC=88=98=20return=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/project/project.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/entities/project/project.ts b/src/entities/project/project.ts index 46a5251..7dd5175 100644 --- a/src/entities/project/project.ts +++ b/src/entities/project/project.ts @@ -8,7 +8,7 @@ import { import { db } from "@shared/firebase/firebase"; -export async function getComments() { +export async function getComments(): Promise { const docRef = doc(db, "coments", "test"); const docSnap = await getDoc(docRef); @@ -20,13 +20,13 @@ export async function getComments() { return docSnap.data(); } -export async function updateTitle(newTitle: string) { +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) { +export async function addPost(title: string): Promise { const postsRef = collection(db, "posts"); const docRef = await addDoc(postsRef, { title,