-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
326 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,21 @@ | ||
const categoryProvider = require('./category.provider'); | ||
const { errResponse } = require('../../config/response'); | ||
|
||
// 전체 카테고리 가져오기 | ||
module.exports.getAllCategories = async (req, res, next) => { | ||
try { | ||
// 카테고리 서비스를 호출하여 전체 카테고리를 가져옵니다. | ||
const categories = await categoryProvider.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: "카테고리를 불러오는 데 실패했습니다." })); | ||
} | ||
}; |
This file contains 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,45 @@ | ||
const Category = require('../../models/category'); | ||
const Post = require('../../models/post'); | ||
const { Op } = require('sequelize'); | ||
|
||
|
||
|
||
|
||
exports.getAllCategories = async () => { | ||
const d = new Date(); | ||
const year = d.getFullYear(); // 년 | ||
const month = d.getMonth(); // 월 | ||
const day = d.getDate(); | ||
const seven = new Date(year, month, day - 7); | ||
|
||
const categories = await Category.findAll(); | ||
|
||
|
||
const EX_categories = await Promise.all(categories.map(async (category) => { | ||
const post = await Post.findAll({ | ||
where: { | ||
category_id: category.category_id | ||
} | ||
}); | ||
|
||
const recent = await Post.count({ | ||
where: { | ||
[Op.and]: [ | ||
{category_id: category.category_id}, | ||
{createdAt: {[Op.gte]: seven}} | ||
] | ||
} | ||
}); | ||
|
||
category.dataValues.post = post; | ||
category.dataValues.count = post.length; | ||
category.dataValues.recent = recent; | ||
return category; | ||
})); | ||
|
||
// EX_POST_LIKE를 post.like 기준으로 내림차순으로 정렬 | ||
EX_categories.sort((a, b) => b.dataValues.count - a.dataValues.count); | ||
|
||
if (EX_categories === null) return false; | ||
else return EX_categories; | ||
}; |
This file contains 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,13 @@ | ||
const categoryDto = require('./category.dto'); | ||
|
||
// 전체 카테고리 가져오기 비즈니스 로직 | ||
module.exports.getAllCategories = async () => { | ||
try { | ||
// DAO를 통해 전체 카테고리를 가져옵니다. | ||
const categories = await categoryDto.getAllCategories(); | ||
return categories; | ||
} catch (error) { | ||
throw error; | ||
} | ||
}; | ||
|
This file contains 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,10 @@ | ||
const categoryController = require('./category.controller'); | ||
const asyncHandler = require('express-async-handler'); | ||
|
||
|
||
module.exports = function (app) { | ||
app.get('/posting/category', asyncHandler(categoryController.getAllCategories)); | ||
}; | ||
|
||
|
||
|
This file contains 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
This file contains 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
This file contains 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,26 @@ | ||
const popularProvider = require('./popular.provider.js'); | ||
const status = require('../../config/response.status.js'); | ||
const { response, errResponse } = require('../../config/response.js'); | ||
|
||
exports.popularWallpaper = async (req, res, next) => { | ||
try { | ||
const getPWallpaper = await popularProvider.getPWallpaper(); | ||
|
||
console.log("getPWallpaper", getPWallpaper); | ||
return res.send(response(status.SUCCESS, getPWallpaper)); | ||
} catch (error) { | ||
console.error('Error controler popularWallpaper:', error); | ||
res.status(400).json({ success: false, message: error.message }); | ||
} | ||
}; | ||
|
||
exports.popularCategory = async (req, res, next) => { | ||
try { | ||
const getPCategory = await popularProvider.getPCategory(); | ||
|
||
return res.send(response(status.SUCCESS, getPCategory)); | ||
} catch (error) { | ||
console.error('Error controler popularCategory:', error); | ||
res.status(400).json({ success: false, message: error.message }); | ||
} | ||
}; |
This file contains 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,48 @@ | ||
const Post = require('../../models/post.js'); | ||
const Category = require('../../models/category.js'); | ||
const likePost = require('../../models/like_post.js'); | ||
const likeDto = require('../like/like.dto.js'); | ||
|
||
exports.getPopularWallpaperResponseDTO = async () => { | ||
const EX_POST = await Post.findAll(); | ||
|
||
const EX_POST_LIKE = await Promise.all(EX_POST.map(async (post) => { | ||
const like = await likePost.count({ | ||
where: { | ||
post_id: post.post_id | ||
} | ||
}); | ||
|
||
post.dataValues.like = like; | ||
|
||
return post; | ||
})); | ||
|
||
// EX_POST_LIKE를 post.like 기준으로 내림차순으로 정렬 | ||
EX_POST_LIKE.sort((a, b) => b.dataValues.like - a.dataValues.like); | ||
|
||
if (EX_POST_LIKE === null) return false; | ||
else return EX_POST_LIKE; | ||
}; | ||
|
||
exports.getPopularCategoryResponseDTO = async () => { | ||
const EX_CATEGORY = await Category.findAll(); | ||
|
||
const EX_POST_CATEGORY = await Promise.all(EX_CATEGORY.map(async (category) => { | ||
const post = await Post.findAll({ | ||
where: { | ||
category_id: category.category_id | ||
} | ||
}); | ||
|
||
category.dataValues.post = post; | ||
category.dataValues.count = post.length; | ||
return category; | ||
})); | ||
|
||
// EX_POST_LIKE를 post.like 기준으로 내림차순으로 정렬 | ||
EX_POST_CATEGORY.sort((a, b) => b.dataValues.count - a.dataValues.count); | ||
|
||
if (EX_POST_CATEGORY === null) return false; | ||
else return EX_POST_CATEGORY; | ||
}; |
This file contains 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,9 @@ | ||
const popularDto = require('./popular.dto.js'); | ||
|
||
exports.getPWallpaper = async () => { | ||
return popularDto.getPopularWallpaperResponseDTO(); | ||
}; | ||
|
||
exports.getPCategory = async () => { | ||
return popularDto.getPopularCategoryResponseDTO(); | ||
}; |
This file contains 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,9 @@ | ||
const { verifyAToken } = require('../middleware/index.js'); | ||
const popularController = require('./popular.controller.js'); | ||
|
||
module.exports = function (app) { | ||
// 1.인기 바탕화면 가져오기 | ||
app.get('/popular/wallpaper',popularController.popularWallpaper); | ||
// 2.인기 카테고리 가져오기 | ||
app.get('/popular/category',popularController.popularCategory); | ||
}; |
This file contains 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,24 @@ | ||
const postService = require('./post.service.js'); | ||
const postProvider = require('./post.provider.js'); | ||
const { response, errResponse } = require('../../config/response.js'); | ||
const baseResponse = require('../../config/response.status.js'); | ||
|
||
//게시물 업로드 | ||
exports.postUpload = async (req, res, next) => { | ||
try { | ||
const user_id = res.locals.decoded.userId; | ||
const image = req.file; | ||
console.log("image", image); | ||
if (!user_id ) { | ||
return res.send(errResponse(baseResponse.BAD_REQUEST)); | ||
} | ||
if (!image || image.length === 0) { | ||
return res.status(400).json({ success: false, message: "실패" }); | ||
} | ||
const result = await postService.createPost(user_id, typeof req.body.data === 'object' ? req.body.data : JSON.parse(req.body.data), image); | ||
return res.send(result); | ||
} catch (error) { | ||
console.error(error); | ||
return next(error); | ||
} | ||
}; |
This file contains 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,36 @@ | ||
const BaseError = require('../../config/error.js'); | ||
const status = require('../../config/response.status.js'); | ||
const Post = require('../../models/post.js'); | ||
const Link = require('../../models/link.js'); | ||
const Tag = require('../../models/tag.js'); | ||
|
||
exports.addPost = async (body) => { | ||
try{ | ||
const newPost = await Post.create(body); | ||
return newPost; | ||
}catch (err) { | ||
console.error('Error creating post:', err); | ||
throw new BaseError(status.CREATION_FAILED); | ||
} | ||
} | ||
|
||
exports.addPostLink = async (body) => { | ||
try{ | ||
const newPostLink = await Link.create(body); | ||
return newPostLink; | ||
}catch (err) { | ||
console.error('Error creating postLink:', err); | ||
throw new BaseError(status.CREATION_FAILED); | ||
} | ||
} | ||
|
||
|
||
exports.addPostTag = async (body) => { | ||
try{ | ||
const newPostTag = await Tag.create(body); | ||
return newPostTag; | ||
}catch (err) { | ||
console.error('Error creating postTag:', err); | ||
throw new BaseError(status.CREATION_FAILED); | ||
} | ||
} |
This file contains 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 @@ | ||
const User = require('../../models/user'); | ||
const Post = require('../../models/post'); |
This file contains 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 @@ | ||
const postDto = require('./post.dto.js'); |
This file contains 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,8 @@ | ||
const { verifyAToken } = require('../middleware/index.js'); | ||
const imageUploader = require('../middleware/image.uploader.js'); | ||
const postController = require('./post.controller.js'); | ||
|
||
module.exports = function (app) { | ||
// 1.게시물 업로드 | ||
app.post('/post/upload', verifyAToken, imageUploader.imageUploader.single('image'), postController.postUpload); | ||
}; |
Oops, something went wrong.