Skip to content

Commit

Permalink
Merge pull request #18 from hyein0514/category
Browse files Browse the repository at this point in the history
Category
  • Loading branch information
hyein0514 committed Feb 17, 2024
2 parents 0b6056a + 1626095 commit 83ac2ec
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/category/category.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const categoryService = require('./category.service');
const { errResponse } = require('../../config/response');

// 전체 카테고리 가져오기
exports.getAllCategories = async (req, res, next) => {
try {
// 카테고리 서비스를 호출하여 전체 카테고리를 가져옵니다.
const categories = await categoryService.getAllCategories();

// 성공적으로 카테고리를 가져온 경우 응답을 보냅니다.
res.status(200).json({
success: true,
message: "전체 카테고리를 성공적으로 불러왔습니다.",
data: categories
});
} catch (error) {
// 오류가 발생한 경우 오류 응답을 보냅니다.
console.error('Error fetching categories:', error);
res.status(500).json(errResponse({ code: 500, message: "카테고리를 불러오는 데 실패했습니다." }));
}
};
14 changes: 14 additions & 0 deletions src/category/category.dao.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const Category = require('../../models/category');

// 데이터베이스에서 전체 카테고리 가져오기
exports.getAllCategories = async () => {
try {
// 데이터베이스에서 모든 카테고리를 조회합니다.
const categories = await Category.find();
return categories;
} catch (error) {
throw error;
}
};

// 다른 DAO 메서드들도 추가할 수 있습니다.
Empty file.
Empty file added src/category/category.route.js
Empty file.
14 changes: 14 additions & 0 deletions src/category/category.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const categoryDao = require('./category.dao');

// 전체 카테고리 가져오기 비즈니스 로직
exports.getAllCategories = async () => {
try {
// DAO를 통해 전체 카테고리를 가져옵니다.
const categories = await categoryDao.getAllCategories();
return categories;
} catch (error) {
throw error;
}
};

// 다른 서비스 메서드들도 추가할 수 있습니다.

0 comments on commit 83ac2ec

Please sign in to comment.