-
Notifications
You must be signed in to change notification settings - Fork 22
[이지수A] Sprint11 #48
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
Merged
loquemedalagana
merged 1 commit into
codeit-sprint-fullstack:main
from
afafmmm:express-이지수A
Jun 21, 2025
The head ref may contain hidden characters: "express-\uC774\uC9C0\uC218A"
Merged
[이지수A] Sprint11 #48
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| .env | ||
| node_modules |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| { | ||
| "name": "express-user-system", | ||
| "version": "1.0.0", | ||
| "description": "", | ||
| "license": "ISC", | ||
| "author": "", | ||
| "main": "src/index.js", | ||
| "scripts": { | ||
| "build": "tsc", | ||
| "start": "node dist/app.js", | ||
| "dev": "ts-node-dev --respawn src/app.ts", | ||
| "migrate": "prisma migrate dev", | ||
| "studio": "prisma studio" | ||
| }, | ||
| "dependencies": { | ||
| "@prisma/client": "^5.17.0", | ||
| "bcrypt": "^5.1.1", | ||
| "cookie-parser": "^1.4.7", | ||
| "cors": "^2.8.5", | ||
| "dotenv": "^16.4.5", | ||
| "express": "^4.19.2", | ||
| "express-jwt": "^8.5.1", | ||
| "express-session": "^1.18.1", | ||
| "jsonwebtoken": "^9.0.2", | ||
| "multer": "^1.4.5-lts.2", | ||
| "passport": "^0.7.0", | ||
| "passport-google-oauth20": "^2.0.0", | ||
| "passport-jwt": "^4.0.1", | ||
| "passport-local": "^1.0.0", | ||
| "prisma": "^5.17.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/bcrypt": "^5.0.2", | ||
| "@types/cookie-parser": "^1.4.9", | ||
| "@types/cors": "^2.8.19", | ||
| "@types/express": "^5.0.3", | ||
| "@types/express-session": "^1.18.2", | ||
| "@types/jsonwebtoken": "^9.0.9", | ||
| "@types/multer": "^1.4.13", | ||
| "@types/node": "^24.0.1", | ||
| "@types/passport": "^1.0.17", | ||
| "@types/passport-google-oauth20": "^2.0.16", | ||
| "@types/passport-jwt": "^4.0.1", | ||
| "@types/passport-local": "^1.0.38", | ||
| "nodemon": "^3.1.0", | ||
| "ts-node": "^10.9.2", | ||
| "ts-node-dev": "^2.0.0", | ||
| "typescript": "^5.8.3" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| -- CreateTable | ||
| CREATE TABLE "User" ( | ||
| "id" SERIAL NOT NULL, | ||
| "nickname" VARCHAR(20) NOT NULL, | ||
| "email" TEXT NOT NULL, | ||
| "password" TEXT NOT NULL, | ||
| "image" TEXT, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
|
||
| CONSTRAINT "User_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "Product" ( | ||
| "id" SERIAL NOT NULL, | ||
| "name" VARCHAR(30) NOT NULL, | ||
| "description" TEXT NOT NULL, | ||
| "price" INTEGER NOT NULL, | ||
| "tags" TEXT[], | ||
| "images" TEXT[], | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updatedAt" TIMESTAMP(3) NOT NULL, | ||
| "ownerId" INTEGER NOT NULL, | ||
|
|
||
| CONSTRAINT "Product_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "Article" ( | ||
| "id" SERIAL NOT NULL, | ||
| "title" VARCHAR(50) NOT NULL, | ||
| "content" TEXT NOT NULL, | ||
| "image" TEXT, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updatedAt" TIMESTAMP(3) NOT NULL, | ||
| "writerId" INTEGER NOT NULL, | ||
|
|
||
| CONSTRAINT "Article_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "Comment" ( | ||
| "id" SERIAL NOT NULL, | ||
| "content" TEXT NOT NULL, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updatedAt" TIMESTAMP(3) NOT NULL, | ||
| "writerId" INTEGER NOT NULL, | ||
| "productId" INTEGER, | ||
| "articleId" INTEGER, | ||
|
|
||
| CONSTRAINT "Comment_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "ProductLike" ( | ||
| "userId" INTEGER NOT NULL, | ||
| "productId" INTEGER NOT NULL, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
|
||
| CONSTRAINT "ProductLike_pkey" PRIMARY KEY ("userId","productId") | ||
| ); | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE "ArticleLike" ( | ||
| "userId" INTEGER NOT NULL, | ||
| "articleId" INTEGER NOT NULL, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
|
||
| CONSTRAINT "ArticleLike_pkey" PRIMARY KEY ("userId","articleId") | ||
| ); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX "User_nickname_key" ON "User"("nickname"); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "Product" ADD CONSTRAINT "Product_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "Article" ADD CONSTRAINT "Article_writerId_fkey" FOREIGN KEY ("writerId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "Comment" ADD CONSTRAINT "Comment_writerId_fkey" FOREIGN KEY ("writerId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "Comment" ADD CONSTRAINT "Comment_productId_fkey" FOREIGN KEY ("productId") REFERENCES "Product"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "Comment" ADD CONSTRAINT "Comment_articleId_fkey" FOREIGN KEY ("articleId") REFERENCES "Article"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "ProductLike" ADD CONSTRAINT "ProductLike_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "ProductLike" ADD CONSTRAINT "ProductLike_productId_fkey" FOREIGN KEY ("productId") REFERENCES "Product"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "ArticleLike" ADD CONSTRAINT "ArticleLike_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "ArticleLike" ADD CONSTRAINT "ArticleLike_articleId_fkey" FOREIGN KEY ("articleId") REFERENCES "Article"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Please do not edit this file manually | ||
| # It should be added in your version-control system (i.e. Git) | ||
| provider = "postgresql" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| generator client { | ||
| provider = "prisma-client-js" | ||
| } | ||
|
|
||
| datasource db { | ||
| provider = "postgresql" | ||
| url = env("DATABASE_URL") | ||
| } | ||
|
|
||
| model User { | ||
| id Int @id @default(autoincrement()) | ||
| nickname String @unique @db.VarChar(20) | ||
| email String @unique | ||
| password String // 해시된 비밀번호 저장 | ||
| image String? // 사용자 이미지 URL, null 가능 | ||
| createdAt DateTime @default(now()) | ||
| updatedAt DateTime @updatedAt | ||
|
|
||
| // 관계 | ||
| products Product[] // 이 사용자가 생성한 상품 | ||
| articles Article[] // 이 사용자가 작성한 게시글 | ||
| comments Comment[] // 이 사용자가 작성한 댓글 | ||
| likedProducts ProductLike[] // 이 사용자가 좋아요한 상품 | ||
| likedArticles ArticleLike[] // 이 사용자가 좋아요한 게시글 | ||
| } | ||
|
|
||
| model Product { | ||
| id Int @id @default(autoincrement()) | ||
| name String @db.VarChar(30) | ||
| description String | ||
| price Int // `minimum: 0`은 애플리케이션 레벨 유효성 검사 | ||
| tags String[] // 태그 문자열 배열 | ||
| images String[] // 이미지 URL 배열. 배열의 `minLength: 1`은 앱 레벨 유효성 검사. | ||
| createdAt DateTime @default(now()) | ||
| updatedAt DateTime @updatedAt | ||
|
|
||
| // 사용자와의 관계 (소유자) | ||
| ownerId Int | ||
| owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade) | ||
|
|
||
| // 관계 | ||
| comments Comment[] // 이 상품에 대한 댓글 | ||
| likedBy ProductLike[] // 사용자와의 다대다 관계 (좋아요)를 위한 조인 테이블 | ||
| } | ||
|
|
||
| model Article { | ||
| id Int @id @default(autoincrement()) | ||
| title String @db.VarChar(50) | ||
| content String // `minLength: 1`은 애플리케이션 레벨 유효성 검사 | ||
| image String? // 게시글 이미지 URL, null 가능 | ||
| createdAt DateTime @default(now()) | ||
| updatedAt DateTime @updatedAt | ||
|
|
||
| // 사용자와의 관계 (작성자) | ||
| writerId Int | ||
| writer User @relation(fields: [writerId], references: [id], onDelete: Cascade) | ||
|
|
||
| // 관계 | ||
| comments Comment[] // 이 게시글에 대한 댓글 | ||
| likedBy ArticleLike[] // 사용자와의 다대다 관계 (좋아요)를 위한 조인 테이블 | ||
| } | ||
|
|
||
| model Comment { | ||
| id Int @id @default(autoincrement()) | ||
| content String // `minLength: 1`은 애플리케이션 레벨 유효성 검사 | ||
| createdAt DateTime @default(now()) | ||
| updatedAt DateTime @updatedAt | ||
|
|
||
| // 사용자와의 관계 (작성자) | ||
| writerId Int | ||
| writer User @relation(fields: [writerId], references: [id], onDelete: Cascade) | ||
|
|
||
| // 상품과의 관계 (선택 사항) | ||
| product Product? @relation(fields: [productId], references: [id], onDelete: Cascade) | ||
| productId Int? | ||
|
|
||
| // 게시글과의 관계 (선택 사항) | ||
| article Article? @relation(fields: [articleId], references: [id], onDelete: Cascade) | ||
| articleId Int? | ||
| } | ||
|
|
||
| // 사용자-상품 좋아요를 위한 조인 테이블 (다대다) (변경) | ||
| model ProductLike { | ||
| userId Int | ||
| productId Int | ||
| createdAt DateTime @default(now()) | ||
|
|
||
| user User @relation(fields: [userId], references: [id], onDelete: Cascade) | ||
| product Product @relation(fields: [productId], references: [id], onDelete: Cascade) | ||
|
|
||
| @@id([userId, productId]) // 복합 기본 키 | ||
| } | ||
|
|
||
| // 사용자-게시글 좋아요를 위한 조인 테이블 (다대다) | ||
| model ArticleLike { | ||
| userId Int | ||
| articleId Int | ||
| createdAt DateTime @default(now()) | ||
|
|
||
| user User @relation(fields: [userId], references: [id], onDelete: Cascade) | ||
| article Article @relation(fields: [articleId], references: [id], onDelete: Cascade) | ||
|
|
||
| @@id([userId, articleId]) // 복합 기본 키 | ||
| } |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import "dotenv/config"; | ||
| import express, { Express, Request, Response, NextFunction } from "express"; | ||
| import cors from "cors"; | ||
| import cookieParser from "cookie-parser"; | ||
| import passport from "./config/passport"; | ||
| import authController from "./controllers/authController"; | ||
| import userController from "./controllers/userController"; | ||
| import imageController from "./controllers/imageController"; | ||
| import productController from "./controllers/productController"; | ||
| import articleController from "./controllers/articleController"; | ||
| import commentController from "./controllers/commentController"; | ||
| import errorHandler from "./middlewares/errorHandler"; | ||
|
|
||
| const app: Express = express(); | ||
|
|
||
| app.use( | ||
| cors({ | ||
| origin: "http://localhost:3001", // 프론트엔드 주소 | ||
| credentials: true, | ||
| }) | ||
| ); | ||
| app.use(express.json()); | ||
| app.use(cookieParser()); | ||
|
|
||
| app.use(passport.initialize()); | ||
|
|
||
| app.use("/auth", authController); | ||
| app.use("/users", userController); | ||
| app.use("/products", productController); | ||
| app.use("/articles", articleController); | ||
| app.use("/uploads", express.static("uploads")); | ||
| app.use("/images", imageController); | ||
| app.use(commentController); | ||
| app.use(errorHandler); | ||
|
|
||
| const port = process.env.PORT ?? 3000; | ||
| app.listen(port, () => { | ||
| console.log(`Server is running on port ${port}`); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import passport from "passport"; | ||
| import jwt from "../middlewares/passport/jwtStrategy"; | ||
|
|
||
| passport.use("access-token", jwt.accessTokenStrategy); | ||
| passport.use("refresh-token", jwt.refreshTokenStrategy); | ||
|
|
||
| export default passport; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { PrismaClient } from '@prisma/client'; | ||
|
|
||
| const prisma = new PrismaClient(); | ||
|
|
||
| export default prisma; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
요 부분도 환경변수로 바꿔주세요!