From b9ff171a4eccba20691f136fa177ccb7fca7db21 Mon Sep 17 00:00:00 2001 From: gs0428 Date: Tue, 20 Aug 2024 03:21:31 +0900 Subject: [PATCH 1/6] =?UTF-8?q?style:=20=EC=A3=BC=EC=84=9D=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/kakao.js | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/kakao.js b/utils/kakao.js index 12cc075..95546b1 100644 --- a/utils/kakao.js +++ b/utils/kakao.js @@ -20,7 +20,6 @@ export const getKakaoUser = async (token) => { const response = await fetch("https://kapi.kakao.com/v2/user/me", { method: "GET", headers: { - // Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`, "Content-type": "application/x-www-form-urlencoded;charset=utf-8", }, From 182ad5da3d58d99b138e7974389d7dacc3b83dac Mon Sep 17 00:00:00 2001 From: gs0428 Date: Tue, 20 Aug 2024 03:22:08 +0900 Subject: [PATCH 2/6] =?UTF-8?q?feat:=20admin=20=EA=B3=B5=EC=A7=80=EA=B8=80?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EB=9D=BC=EC=9A=B0=ED=8C=85=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/admin.route.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/routes/admin.route.js b/routes/admin.route.js index 488a496..690a88d 100644 --- a/routes/admin.route.js +++ b/routes/admin.route.js @@ -17,6 +17,7 @@ import { getRoomsController, getPostListController, getSubmitListController, + getPostController, } from "../domains/admin/admin.controller.js"; export const adminRouter = express.Router(); @@ -26,6 +27,7 @@ adminRouter.patch("/rooms/:roomId", tokenAuth, expressAsyncHandler(updateRoomsCo adminRouter.get("/rooms/:roomId", tokenAuth, expressAsyncHandler(getRoomsController)); adminRouter.delete("/rooms/:roomId", tokenAuth, expressAsyncHandler(deleteRoomsController)); adminRouter.post("/post", tokenAuth, expressAsyncHandler(createPostController)); +adminRouter.get("/post/:postId", tokenAuth, expressAsyncHandler(getPostController)); adminRouter.patch("/post/:postId", tokenAuth, expressAsyncHandler(updatePostController)); adminRouter.delete("/post/:postId", tokenAuth, expressAsyncHandler(deletePostController)); adminRouter.get("/post/:postId/unread", tokenAuth, expressAsyncHandler(unreadUserListController)); From c956c345a30c520493c060b089367a1a7d609b68 Mon Sep 17 00:00:00 2001 From: gs0428 Date: Tue, 20 Aug 2024 03:22:40 +0900 Subject: [PATCH 3/6] =?UTF-8?q?feat:=20=EC=98=88=EC=99=B8=20=EC=83=81?= =?UTF-8?q?=ED=99=A9=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/response.status.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/config/response.status.js b/config/response.status.js index acda1a5..cd47a10 100644 --- a/config/response.status.js +++ b/config/response.status.js @@ -101,4 +101,16 @@ export const status = { code: "COMMON011", message: "이미지를 삭제하는데 실패했습니다.", }, + NOT_MY_POST: { + status: StatusCodes.BAD_REQUEST, + isSuccess: false, + code: "COMMON012", + message: "본인의 공지글에 대해서만 조회가 가능합니다.", + }, + NOT_FOUND_POST: { + status: StatusCodes.NOT_FOUND, + isSuccess: false, + code: "COMMON013", + message: "존재하지 않는 공지글 ID 입니다.", + }, }; From bd23fbeddf0d2761e5a1f84ea2d004c709b1da1d Mon Sep 17 00:00:00 2001 From: gs0428 Date: Tue, 20 Aug 2024 03:22:52 +0900 Subject: [PATCH 4/6] =?UTF-8?q?feat:=20admin=20=EA=B3=B5=EC=A7=80=EA=B8=80?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20API=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domains/admin/admin.controller.js | 15 +++++++++++++++ domains/admin/admin.dao.js | 20 ++++++++++++++++++-- domains/admin/admin.dto.js | 11 +++++++++++ domains/admin/admin.service.js | 17 ++++++++++++++++- domains/admin/admin.sql.js | 9 +++++++++ 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/domains/admin/admin.controller.js b/domains/admin/admin.controller.js index d590b48..853a937 100644 --- a/domains/admin/admin.controller.js +++ b/domains/admin/admin.controller.js @@ -17,6 +17,7 @@ import { userRequestService, getRoomsService, getPostListService, + getPostService, } from "./admin.service.js"; export const createRoomsController = async (req, res, next) => { @@ -67,6 +68,20 @@ export const createPostController = async (req, res, next) => { } }; +export const getPostController = async (req, res, next) => { + try { + const result = await getPostService(req.params.postId, req.user.userId); + if (result === -1) { + return res.status(404).json(response(status.NOT_FOUND_POST)); + } else if (result === -2) { + return res.status(400).json(response(status.NOT_MY_POST)); + } + res.status(200).json(response(status.SUCCESS, result)); + } catch (error) { + next(error); + } +}; + export const updatePostController = async (req, res, next) => { try { const result = await updatePostService(req.body, req.params.postId); diff --git a/domains/admin/admin.dao.js b/domains/admin/admin.dao.js index 8c59857..516b778 100644 --- a/domains/admin/admin.dao.js +++ b/domains/admin/admin.dao.js @@ -32,6 +32,7 @@ import { getRoomSQL, getAlluserRoomSQL, decreaseUnreadCountOneBySubmitId, + getPostSQL, } from "./admin.sql.js"; import { updateUnreadCountByRoom } from "../room/room.sql.js"; @@ -57,8 +58,8 @@ export const createRoomsDao = async (body, userId, roomInviteUrl) => { await conn.query(userRoomSQL, [userId, roomId, body.admin_nickname]); conn.release(); - return{ - roomId: roomId, + return { + roomId: roomId, roomImage: body.room_image, adminNickname: body.admin_nickname, roomName: body.room_name, @@ -181,6 +182,21 @@ export const createPostDao = async (body, userId) => { } }; +export const getPostDAO = async (postId, userId) => { + const conn = await pool.getConnection(); + try { + const [post] = await conn.query(getPostSQL, postId); + if (!post.length) return -1; + if (post[0].admin_id !== userId) return -2; + conn.release(); + return post[0]; + } catch (error) { + conn.release(); + console.error("admin 공지글 조회하기 에러:", error); + throw new BaseError(status.INTERNAL_SERVER_ERROR); + } +}; + export const updatePostDao = async ({ postData, imgURLs, imgToDelete }, postId) => { const conn = await pool.getConnection(); try { diff --git a/domains/admin/admin.dto.js b/domains/admin/admin.dto.js index 0275050..ef288bb 100644 --- a/domains/admin/admin.dto.js +++ b/domains/admin/admin.dto.js @@ -12,6 +12,17 @@ export const createPostDTO = (createPostData) => { }; }; +export const getPostDTO = (postData) => ({ + type: postData.type, + title: postData.title, + content: postData.content, + imgURLs: postData.imgURLs, + startDate: postData.start_date, + endDate: postData.end_date, + question: postData.question, + quizAnswer: postData.quiz_answer, +}); + export const updatePostDTO = (updatePostData) => { return { ...updatePostData, diff --git a/domains/admin/admin.service.js b/domains/admin/admin.service.js index e9501fa..3c46c53 100644 --- a/domains/admin/admin.service.js +++ b/domains/admin/admin.service.js @@ -19,6 +19,7 @@ import { getRoomsDao, getPostListDao, getSubmitListDao, + getPostDAO, } from "./admin.dao.js"; import { createShortUUID } from "./uuid.js"; import { @@ -27,6 +28,7 @@ import { updatePostDTO, getRoomsDTO, postListDTO, + getPostDTO, } from "./admin.dto.js"; export const createRoomsService = async (body, userId) => { @@ -96,6 +98,19 @@ export const createPostService = async (body, userId) => { } }; +export const getPostService = async (postId, userId) => { + try { + const postData = await getPostDAO(postId, userId); + + if (typeof postData === "number") return postData; + + return getPostDTO(postData); + } catch (error) { + console.error("공지글 수정하기 에러:", error); + throw error; + } +}; + export const updatePostService = async (body, postId) => { try { const postData = await updatePostDao(body, postId); @@ -183,7 +198,7 @@ export const userInviteService = async (roomId) => { export const deleteUserService = async (body) => { try { - if(!body.userId) throw new Error("강퇴할 User의 ID가 필요합니다."); + if (!body.userId) throw new Error("강퇴할 User의 ID가 필요합니다."); const result = await deleteUserDao(body); if (result == -1) throw new Error("공지방에 유저가 없습니다."); return result; diff --git a/domains/admin/admin.sql.js b/domains/admin/admin.sql.js index 0720267..b6c1c5f 100644 --- a/domains/admin/admin.sql.js +++ b/domains/admin/admin.sql.js @@ -57,6 +57,15 @@ export const createPostImgSQL = ` INSERT INTO \`post-image\` (URL, post_id) VALUES(?,?); `; +// admin 공지글 조회 +export const getPostSQL = ` + SELECT p.title, p.content, p.type, p.start_date, p.end_date, p.question, p.quiz_answer, r.admin_id + FROM post p + JOIN room r + ON r.id = p.room_id + WHERE p.id = ?; +`; + // 공지글 수정 & 이미지 삭제 export const updatePostSQL = ` UPDATE post From f790cf2129c1f6f8b42d981d9d3679994c52d37a Mon Sep 17 00:00:00 2001 From: gs0428 Date: Tue, 20 Aug 2024 03:27:41 +0900 Subject: [PATCH 5/6] =?UTF-8?q?chore:=20swagger=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- swagger/admin.swagger.yaml | 94 +++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) diff --git a/swagger/admin.swagger.yaml b/swagger/admin.swagger.yaml index 0b102ca..8bd531f 100644 --- a/swagger/admin.swagger.yaml +++ b/swagger/admin.swagger.yaml @@ -340,6 +340,98 @@ paths: type: string description: 퀴즈 답 /admin/post/{postId}: + get: + tags: + - admin + summary: 공지글 상세 조회 + description: 공지글 수정을 위한 상세 조회를 합니다. + operationId: getPost + consumes: + - application/json + security: + - bearerAuth: [] + parameters: + - in: path + name: postId + required: true + schema: + type: integer + example: 1 + description: postId + 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: + title: + type: string + description: 공지글 제목 + content: + type: string + description: 공지글 본문 + imgURLs: + type: string + description: 공지글 이미지 + startDate: + type: string + description: 시작 기한 + endDate: + type: string + description: 마감 기한 + question: + type: string + description: 퀴즈/미션 질문 + quizAnswer: + type: string + description: 퀴즈 정답 + "400": + description: 공지글 상세 조회 실패 + content: + application/json: + schema: + type: object + properties: + isSuccess: + type: boolean + example: false + code: + type: string + example: "COMMON012" + message: + type: string + example: "존재하지 않는 공지글 ID 입니다." + "404": + description: 공지글 상세 조회 실패 + content: + application/json: + schema: + type: object + properties: + isSuccess: + type: boolean + example: false + code: + type: string + example: "COMMON013" + message: + type: string + example: "본인의 공지글에 대해서만 조회가 가능합니다." + patch: tags: - admin @@ -904,4 +996,4 @@ paths: example: "success!" result: type: string - example: "요청 수행에 성공하였습니다." \ No newline at end of file + example: "요청 수행에 성공하였습니다." From 95b01e342fdce8829823914b1e44aff019e378c9 Mon Sep 17 00:00:00 2001 From: gs0428 Date: Tue, 20 Aug 2024 03:52:01 +0900 Subject: [PATCH 6/6] =?UTF-8?q?chore:=20error=20code=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=EB=B3=84=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/response.status.js | 4 ++-- swagger/admin.swagger.yaml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/response.status.js b/config/response.status.js index cd47a10..783a51a 100644 --- a/config/response.status.js +++ b/config/response.status.js @@ -104,13 +104,13 @@ export const status = { NOT_MY_POST: { status: StatusCodes.BAD_REQUEST, isSuccess: false, - code: "COMMON012", + code: "POST001", message: "본인의 공지글에 대해서만 조회가 가능합니다.", }, NOT_FOUND_POST: { status: StatusCodes.NOT_FOUND, isSuccess: false, - code: "COMMON013", + code: "POST002", message: "존재하지 않는 공지글 ID 입니다.", }, }; diff --git a/swagger/admin.swagger.yaml b/swagger/admin.swagger.yaml index 501bbe6..4f6fe5d 100644 --- a/swagger/admin.swagger.yaml +++ b/swagger/admin.swagger.yaml @@ -409,7 +409,7 @@ paths: example: false code: type: string - example: "COMMON012" + example: "POST001" message: type: string example: "존재하지 않는 공지글 ID 입니다." @@ -425,7 +425,7 @@ paths: example: false code: type: string - example: "COMMON013" + example: "POST002" message: type: string example: "본인의 공지글에 대해서만 조회가 가능합니다." @@ -472,7 +472,7 @@ paths: description: 퀴즈/미션 질문 quizAnswer: type: string - description: 퀴즈/미션 질문 + description: 퀴즈/미션 질문 addImgURLs: type: array items: @@ -503,7 +503,7 @@ paths: result: type: object properties: - + delete: tags: - admin