상품 API 구조 만들기 실습
// cash.js 파일
export class CashService {
checkValue = () =>{
// 1. 가진 돈 검증하는 코드 ( 대략 10줄 정도 )
// ...
// ...
// ...
// ...
}
}
// product.js 파일
export class ProductService {
checkSoldout = () =>{
// 2. 판매여부 검증하는 코드 ( 대략 10줄 정도 )
// ...
// ...
// ...
// ...
// ...
}
}
// index.js 파일
import {CashService} from './cash.js'
import {ProductService} from "./product.js"
// 상품 구매하기 API
app.post('/products/buy', (req,res)=>{
// 1. 가진 돈 검증하는 코드 ( 대략 10줄 정도 )
const cashService = new CashService()
const hasMoney = cashService.checkValue()
// 2. 판매여부 검증하는 코드 ( 대략 10줄 정도 )
const productService = new ProductService()
const isSoldout = productService.checkSoldout()
// 3. 상품 구매하는 코드
// if(hasMoney && !isSoldout) {
// res.send(" 상품 구매 완료 ")
// }
})
728x90
'Backend 백엔드' 카테고리의 다른 글
[ 36 ] DI ( Dependency Injection ) , IoC ( Inversion of Control ) (1) | 2024.08.28 |
---|---|
[ 35 ] MVC 패턴 실습 (0) | 2024.08.22 |
[ 33 ] Class 실습 ! const 안붙이네? (1) | 2024.08.22 |
[ 32 ] 오픈그래프 스크랩핑 (0) | 2024.08.21 |
[ 31 ] 스크래핑과 브라우저 주소창의 원리 (0) | 2024.08.21 |