-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/e commerce #18
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
base: main
Are you sure you want to change the base?
Feat/e commerce #18
Changes from all commits
9fac462
0d4ac74
9a48903
6df6901
9233509
b05a205
9e0d513
af3e95a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ model OrderItem { | |
| order Order @relation(fields: [orderId], references: [id]) | ||
| orderId Int @map("order_id") | ||
| product Product @relation(fields: [productId], references: [id]) | ||
| productId Int @unique @map("product_id") | ||
| productId Int @map("product_id") | ||
|
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. |
||
| quantity Int | ||
| price Int | ||
| createdAt DateTime @default(now()) @map("created_at") @db.Timestamp(0) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,14 +19,53 @@ async function initTable() { | |
| } | ||
|
|
||
| async function createMockData() { | ||
| await prisma.user.create({ | ||
| data: { balance: 10000 }, | ||
| }); | ||
| await Promise.all( | ||
| Array.from({ length: 10 }, () => | ||
| prisma.user.create({ | ||
| data: { balance: 10000 }, | ||
| }), | ||
| ), | ||
| ); | ||
|
|
||
| //사용자 생성 | ||
| await Promise.all( | ||
| Array.from({ length: 10 }, () => | ||
| prisma.user.create({ | ||
| data: { balance: 10000 }, | ||
| }), | ||
| ), | ||
| ); | ||
|
Comment on lines
+30
to
+37
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. |
||
|
|
||
| //상품 생성 및 재고 생성 | ||
| for (const index of [...Array(30).keys()]) { | ||
| await prisma.product.create({ | ||
| data: { | ||
| name: `테스트상품${index + 1}`, | ||
| price: Math.floor(Math.random() * 90001) + 10000, // 10000 ~ 100000 사이 랜덤 가격 | ||
| ProductQuantity: { | ||
| create: { | ||
| quantity: 10, | ||
| remainingQuantity: 10, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| await prisma.product.create({ | ||
| //쿠폰 생성 및 재고 생성 | ||
| await prisma.coupon.create({ | ||
| data: { | ||
| name: '테스트 상품2', | ||
| price: 50000, | ||
| name: '테스트쿠폰', | ||
| discountType: 'PERCENT', | ||
| discountValue: 10, | ||
| startAt: new Date(), | ||
| endAt: new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 1), | ||
| couponQuantity: { | ||
| create: { | ||
| quantity: 10, | ||
| remainingQuantity: 10, | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { Product } from '../domain/product'; | ||
| import { GetProductsQueryDTO } from '../presentation/dto/product.request.dto'; | ||
|
|
||
| export interface ProductRepository { | ||
| getProducts(query: GetProductsQueryDTO): Promise<Product[]>; | ||
| } | ||
|
|
||
| export const PRODUCT_REPOSITORY = Symbol('PRODUCT_REPOSITORY'); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,16 @@ | ||
| import { Injectable } from '@nestjs/common'; | ||
| import { Inject, Injectable } from '@nestjs/common'; | ||
| import { PRODUCT_REPOSITORY, ProductRepository } from './product.repository'; | ||
| import { GetProductsQueryDTO } from '../presentation/dto/product.request.dto'; | ||
| import { ProductResponseDto } from '../presentation/dto/product.response.dto'; | ||
|
|
||
| @Injectable() | ||
| export class ProductService {} | ||
| export class ProductService { | ||
| constructor( | ||
| @Inject(PRODUCT_REPOSITORY) private readonly productRepository: ProductRepository, | ||
| ) {} | ||
|
|
||
| async getProducts(query: GetProductsQueryDTO): Promise<ProductResponseDto[]> { | ||
| const products = await this.productRepository.getProducts(query); | ||
| return products.map((product) => ProductResponseDto.of(product)); | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,20 @@ | ||||||
| import { PrismaService } from 'src/database/prisma/prisma.service'; | ||||||
| import { GetProductsQueryDTO } from '../presentation/dto/product.request.dto'; | ||||||
| import { Injectable } from '@nestjs/common'; | ||||||
| import { ProductRepository } from '../application/product.repository'; | ||||||
| import { Product } from '../domain/product'; | ||||||
|
|
||||||
| @Injectable() | ||||||
| export class ProductTypeOrmRepository implements ProductRepository { | ||||||
|
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. 파일명과 클래스명이
Suggested change
|
||||||
| constructor(private readonly prisma: PrismaService) {} | ||||||
|
|
||||||
| async getProducts(query: GetProductsQueryDTO): Promise<Product[]> { | ||||||
| return await this.prisma.product.findMany({ | ||||||
| include: { | ||||||
| ProductQuantity: true, | ||||||
| }, | ||||||
| skip: query.offset, | ||||||
| take: query.size, | ||||||
| }); | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { ApiProperty } from '@nestjs/swagger'; | ||
| import { Transform } from 'class-transformer'; | ||
| import { IsNumber, Min } from 'class-validator'; | ||
|
|
||
| export class GetProductsQueryDTO { | ||
| @ApiProperty({ example: 1, description: '페이지 번호' }) | ||
| @IsNumber() | ||
| @Transform(({ value }) => parseInt(value)) | ||
| @Min(1) | ||
| page: number = 1; | ||
|
|
||
| @ApiProperty({ example: 10, description: '페이지 크기' }) | ||
| @Transform(({ value }) => parseInt(value)) | ||
| @IsNumber() | ||
| @Min(10) | ||
| size: number = 10; | ||
|
|
||
| get offset() { | ||
| return (this.page - 1) * this.size; | ||
| } | ||
| } |
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.
seed:test스크립트에서dotenv -e .env.test --가 제거되었습니다.migrate:test스크립트에는 남아있는데, 이로 인해seed:test실행 시.env.test파일의 환경 변수를 읽지 못할 수 있습니다.prisma/seed.ts가DATABASE_URL같은 환경 변수에 의존한다면, 테스트 시드 데이터 생성에 실패할 수 있습니다. 일관성을 위해seed:test스크립트에도dotenv-cli를 사용하거나, Jest 설정 등 다른 방식으로 환경 변수를 주입하는 것을 고려해 보세요.