Skip to content

Commit

Permalink
Merge pull request #19 from Draw-Desktop/develop
Browse files Browse the repository at this point in the history
Feat: post 폴더 파일 추가
  • Loading branch information
rlagns1234 authored Feb 17, 2024
2 parents 0b6056a + ff4efe5 commit 443defa
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 33 deletions.
50 changes: 17 additions & 33 deletions src/popular/popular.dto.js
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;
};
1 change: 1 addition & 0 deletions src/post/post.controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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');

Expand Down
2 changes: 2 additions & 0 deletions src/post/post.dto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const User = require('../../models/user');
const Post = require('../../models/post');
1 change: 1 addition & 0 deletions src/post/post.provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const postDto = require('./post.dto.js');

0 comments on commit 443defa

Please sign in to comment.