-
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.
Merge pull request #19 from Draw-Desktop/develop
Feat: post 폴더 파일 추가
- Loading branch information
Showing
4 changed files
with
21 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,32 @@ | ||
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'); | ||
const Category = require('../../models/category'); | ||
const Post = require('../../models/post'); | ||
|
||
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.getAllCategories = async () => { | ||
const categories = await Category.findAll(); | ||
|
||
exports.getPopularCategoryResponseDTO = async () => { | ||
const EX_CATEGORY = await Category.findAll(); | ||
|
||
const EX_POST_CATEGORY = await Promise.all(EX_CATEGORY.map(async (category) => { | ||
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.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); | ||
EX_categories.sort((a, b) => b.dataValues.count - a.dataValues.count); | ||
|
||
if (EX_POST_CATEGORY === null) return false; | ||
else return EX_POST_CATEGORY; | ||
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
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'); |