Skip to content

Commit

Permalink
Merge pull request #198 from UMC-README/dev
Browse files Browse the repository at this point in the history
dev -> main
  • Loading branch information
gs0428 authored Aug 15, 2024
2 parents 81de047 + 001c0b5 commit e09d8f0
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 7 deletions.
12 changes: 11 additions & 1 deletion domains/admin/admin.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
userProfileService,
userInviteService,
deleteUserService,
userSubmitService,
} from "./admin.service.js";

export const createRoomsController = async (req, res, next) => {
Expand Down Expand Up @@ -112,4 +113,13 @@ export const deleteUserController = async (req, res, next) => {
} catch (error) {
next(error);
}
};
};

export const userSubmitController = async (req, res, next) => {
try {
const result = await userSubmitService(req.params.roomId);
res.status(200).json(response(status.SUCCESS, result));
} catch (error) {
next(error);
}
}
25 changes: 24 additions & 1 deletion domains/admin/admin.dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import {
penaltySQL,
penaltyStateSQL,
addUserSubmitSQL,
getPostCountSQL,
userSubmitSQL,
getSubmitStateSQL,
} from "./admin.sql.js";

import schedule from "node-schedule";
Expand Down Expand Up @@ -258,7 +261,7 @@ export const userListDao = async (nickname, roomId) => {
export const userProfileDao = async (roomId, userId) => {
try {
const conn = await pool.getConnection();
const [result] = await conn.query(userProfileSQL, [roomId, userId]);
const [result] = await conn.query(userProfileSQL, [userId, roomId]);
conn.release();
return result[0];
} catch (error) {
Expand Down Expand Up @@ -320,3 +323,23 @@ export const penaltyDao = async () => {
}
});
};

export const userSubmitDao = async (roomId) => {
try{
const conn = await pool.getConnection();

const [rows] = await conn.query(getPostCountSQL);
const countPost = rows[0]?.count || 0;
if(countPost === 0) return {massage : "공지가 없습니다."};

const [userSubmissions] = await conn.query(userSubmitSQL, roomId);
const [submitStates] = await conn.query(getSubmitStateSQL, roomId);

conn.release();
return { userSubmissions, submitStates } ;

}catch(error){
console.log("확인 요청 조회 에러");
throw new BaseError(status.INTERNAL_SERVER_ERROR);
}
}
7 changes: 7 additions & 0 deletions domains/admin/admin.dto.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,10 @@ export const updatePostDTO = (updatePostData) => {
...updatePostData,
};
};

export const userSubmitDTO = (userSubmissions, submitStates) => {
const pendingStates = submitStates.filter(state => state.submit_state === 'PENDING');
const completeStates = submitStates.filter(state => state.submit_state === 'COMPLETE');

return { userSubmissions, pendingStates, completeStates };
}
17 changes: 15 additions & 2 deletions domains/admin/admin.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import {
userProfileDao,
userInviteDao,
deleteUserDao,
userSubmitDao,
} from "./admin.dao.js";
import { createShortUUID } from "./uuid.js";
import { createRoomsDTO, updateRoomsDTO, createPostDTO, updatePostDTO } from "./admin.dto.js";
import { createRoomsDTO, updateRoomsDTO, createPostDTO, updatePostDTO, userSubmitDTO } from "./admin.dto.js";

export const createRoomsService = async (body, userId) => {
try {
Expand Down Expand Up @@ -101,7 +102,7 @@ export const userListService = async (nickname, roomId) => {
throw new Error("조회할 공지방의 ID가 필요합니다.");
}
const result = await userListDao(nickname, roomId);

if (!result.length) return [];
return result.map(user => ({
userId : user.user_id,
Expand Down Expand Up @@ -147,3 +148,15 @@ export const deleteUserService = async (body) => {
throw error;
}
};

export const userSubmitService = async (roomId) => {
try{
if(!roomId) throw new Error("요청 내역 조회를 위한 roomId가 필요합니다.");

const { userSubmissions, submitStates } = await userSubmitDao(roomId);
const result = userSubmitDTO(userSubmissions, submitStates);
return result;
}catch(error){
throw error;
}
};
28 changes: 27 additions & 1 deletion domains/admin/admin.sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const updatePostSQL = `
WHERE id = ?;
`;
export const deletePostImgSQL = `
UPDATE \`post-image\` SET state = 'DELETED' WHERE post_id = ? AND URL = ?;
UPDATE \`post-image\` SET state = 'DELETED' WHERE post_id = ? AND URL = ?;
`;

// 공지글 삭제
Expand Down Expand Up @@ -150,3 +150,29 @@ export const addUserSubmitSQL = `
)
AND NOW() > DATE_ADD(p.end_date, INTERVAL 1 SECOND);
`;

// 확인 요청 내역 조회
export const getPostCountSQL = `
SELECT COUNT(*) AS count FROM post;
`;

export const userSubmitSQL = `
SELECT
p.title, p.start_date, p.end_date, p.content, r.room_image
, COUNT(s.id) AS pending_count
FROM post p
JOIN submit s ON p.id = s.post_id AND s.submit_state = 'PENDING'
JOIN room r ON p.room_id = r.id
WHERE p.room_id = ?
GROUP BY p.id;
`;

export const getSubmitStateSQL = `
SELECT u.profile_image, u.nickname, si.URL, s.submit_state
FROM post p
JOIN submit s ON p.id = s.post_id
JOIN user u ON s.user_id = u.id
LEFT JOIN \`submit-image\` si ON s.id = si.id
WHERE p.room_id = ? AND s.submit_state IN ('PENDING', 'COMPLETE');
`;

4 changes: 3 additions & 1 deletion routes/admin.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
userProfileController,
userInviteController,
deleteUserController,
userSubmitController
} from "../domains/admin/admin.controller.js";

export const adminRouter = express.Router();
Expand All @@ -27,4 +28,5 @@ adminRouter.get("/post/:postId/unread", tokenAuth, expressAsyncHandler(unreadUse
adminRouter.get("/users", tokenAuth, expressAsyncHandler(userListController));
adminRouter.get("/profile", tokenAuth, expressAsyncHandler(userProfileController));
adminRouter.get("/invitation/:roomId", tokenAuth, expressAsyncHandler(userInviteController));
adminRouter.delete("/user-ban", tokenAuth, expressAsyncHandler(deleteUserController));
adminRouter.delete("/user-ban", tokenAuth, expressAsyncHandler(deleteUserController));
adminRouter.get("/submit/:roomId", tokenAuth, expressAsyncHandler(userSubmitController));
102 changes: 101 additions & 1 deletion swagger/admin.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ paths:
result:
type: object
properties:
postId :
roomId :
type : number
description : 생성된 공지방ID
roomImage:
Expand Down Expand Up @@ -690,5 +690,105 @@ paths:
message :
type: string
example : 유저 강퇴에 성공하였습니다.

/admin/submit/{roomId} :
get:
tags:
- admin
summary: 확인 요청 내역 조회(대기 or 승인 완료)
description: 확인 요청 내역 조회
operationId: userInvite
consumes:
- application/json
security:
- bearerAuth: []
parameters:
- name: roomId
in: path
schema:
type: integer
required: true
responses:
"200":
description: 확인 요청 내역 조회 성공!
content:
application/json:
schema:
type: object
properties:
isSuccess:
type: boolean
example: true
code:
type: integer
example: 200
message:
type: string
example: "success!"
result:
type: object
properties:
userSubmissions:
type: array
items:
type: object
properties:
title:
type: string
example: "test9"
start_date:
type: string
format: date-time
example: "2024-08-11T02:24:00.000Z"
end_date:
type: string
format: date-time
example: "2024-08-10T02:24:03.000Z"
content:
type: string
example: "penaltytestcontent"
room_image:
type: string
nullable: true
example: null
pending_count:
type: integer
example: 2
pendingStates:
type: array
items:
type: object
properties:
profile_image:
type: string
nullable: true
example: null
nickname:
type: string
example: "제이"
URL:
type: string
example: "https://s3.ap-northeast-2.amazonaws.com/read.me-bucket/43dbd401a34c7be69c9be7b123a13e67_exampleimage.png"
submit_state:
type: string
example: "PENDING"
completeStates:
type: array
items:
type: object
properties:
profile_image:
type: string
nullable: true
example: null
nickname:
type: string
example: "제이"
URL:
type: string
example: "https://s3.ap-northeast-2.amazonaws.com/read.me-bucket/45425843b018b4ac8d235ad195b35a54_exampleimage.png"
submit_state:
type: string
example: "COMPLETE"


0 comments on commit e09d8f0

Please sign in to comment.