From c76c759815eb789ff64cb2a824be4efc65549918 Mon Sep 17 00:00:00 2001 From: seoyeoneel02 Date: Fri, 13 Sep 2024 22:10:57 +0900 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20=EA=B4=80=EC=8B=AC=EC=9E=88?= =?UTF-8?q?=EB=8A=94=20=EC=98=B7=20=EC=B6=94=EA=B0=80=20#125?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domains/search/search.controller.js | 8 +++++++- src/domains/search/search.dao.js | 17 ++++++++++++++++- src/domains/search/search.dto.js | 5 +++++ src/domains/search/search.service.js | 8 ++++++-- src/domains/search/search.sql.js | 4 +++- src/routes/search.js | 7 +++++-- 6 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/domains/search/search.controller.js b/src/domains/search/search.controller.js index 1bb60c8..603a82c 100644 --- a/src/domains/search/search.controller.js +++ b/src/domains/search/search.controller.js @@ -1,7 +1,7 @@ import { response } from "../../config/response.js"; import { status } from "../../config/response.status.js"; import { getSearch, getCloth, getSearchResult, getSearchBrand, getMyCloth } from "./search.provider.js"; -import { addMyCloth } from "./search.service.js"; +import { addMyCloth, addMyWish } from "./search.service.js"; export const searchPreview = async (req, res, next) => { console.log("검색 메인화면을 조회합니다"); @@ -33,4 +33,10 @@ export const addCloth = async (req, res, next) => { console.log("옷 등록을 요청하였습니다!"); const userId = res.locals.uuid; res.send(response(status.SUCCESS, await addMyCloth(userId, req.body))); +} + +export const addWish = async (req, res, next) => { + console.log("관심 있는 옷 추가를 요청하였습니다!"); + const userId = res.locals.uuid; + res.send(response(status.SUCCESS, await addMyWish(userId, req.params.clothId))); } \ No newline at end of file diff --git a/src/domains/search/search.dao.js b/src/domains/search/search.dao.js index 4365d6d..212560d 100644 --- a/src/domains/search/search.dao.js +++ b/src/domains/search/search.dao.js @@ -7,7 +7,8 @@ import { UserNicknameToClothId, UserCategoryToClothId, UserNicknameToClothName, UserCategoryToClothName, brandToBrandName, userIdToNickname, userToNickname, getBrandToBrandId, userToBrand, categoryToBrand, clothToBrand, clothCategoryToBrand, - insertCloth, insertRealSize, getCloth } from "./search.sql.js"; + insertCloth, insertRealSize, getCloth, + addWishSQL } from "./search.sql.js"; // nickname+cloth 반환 export const getNicknameToClothId = async (category) => { @@ -224,4 +225,18 @@ export const getAddCloth = async (clothId) => { } catch (err) { throw new BaseError(status.PARAMETER_IS_WRONG); } +} + +// Wish 추가 +export const addWishDAO = async (data) => { + try{ + const conn = await pool.getConnection(); + + const user = await pool.query(addWishSQL, [data.uuid, data.size]); + + conn.release(); + return cloth[0].insertId; + }catch (err) { + throw new BaseError(status.PARAMETER_IS_WRONG); + } } \ No newline at end of file diff --git a/src/domains/search/search.dto.js b/src/domains/search/search.dto.js index 84647e7..899e3bb 100644 --- a/src/domains/search/search.dto.js +++ b/src/domains/search/search.dto.js @@ -170,4 +170,9 @@ export const addClothResponseDTO = (data) => { }) } return {"clothData": cloth}; +} + +export const addWishDTO = (data) => { + + return; } \ No newline at end of file diff --git a/src/domains/search/search.service.js b/src/domains/search/search.service.js index 877edde..ffece9d 100644 --- a/src/domains/search/search.service.js +++ b/src/domains/search/search.service.js @@ -1,7 +1,7 @@ import { BaseError } from "../../config/error.js"; import { status } from "../../config/response.status.js"; -import { addClothResponseDTO } from "./search.dto.js"; -import { clothAdd, getAddCloth } from "./search.dao.js"; +import { addClothResponseDTO, addWishDTO } from "./search.dto.js"; +import { clothAdd, getAddCloth, addWishDAO } from "./search.dao.js"; export const addMyCloth = async (userId, body) => { const requiredFields = ['name', 'product_code', 'category', 'size', 'fit']; @@ -46,4 +46,8 @@ export const addMyCloth = async (userId, body) => { 'hem': body.hem }); return addClothResponseDTO(await getAddCloth(clothData)); +} + +export const addMyWish = async (userId, clothId) => { + return addWishDTO(await addWishDAO(userId, clothId)); } \ No newline at end of file diff --git a/src/domains/search/search.sql.js b/src/domains/search/search.sql.js index 524b020..44e6ad8 100644 --- a/src/domains/search/search.sql.js +++ b/src/domains/search/search.sql.js @@ -105,4 +105,6 @@ export const insertCloth = export const insertRealSize = "INSERT INTO real_size (cloth_id, length, shoulder, chest, armhole, sleeve, sleeve_length, hem) VALUES (?, ?, ?, ?, ?, ?, ?, ?) ;" -export const getCloth = "SELECT * FROM cloth WHERE id = ? ; " \ No newline at end of file +export const getCloth = "SELECT * FROM cloth WHERE id = ? ; " + +export const addWishSQL = "SELECT * FROM wish WHERE from_id = ? AND to_id = ? ; " \ No newline at end of file diff --git a/src/routes/search.js b/src/routes/search.js index a1862a6..037fee7 100644 --- a/src/routes/search.js +++ b/src/routes/search.js @@ -1,7 +1,7 @@ import express from "express"; import asyncHandler from 'express-async-handler'; import { LoginCheck } from "../middlewares/logincheck.js"; -import { searchPreview, clothView, searchView, brandView, addClothPreview, addCloth } from "../domains/search/search.controller.js"; +import { searchPreview, clothView, searchView, brandView, addClothPreview, addCloth, addWish } from "../domains/search/search.controller.js"; export const searchRouter = express.Router({mergeParams: true}); @@ -21,4 +21,7 @@ searchRouter.get('/brand/:brandId', LoginCheck, asyncHandler(brandView)); searchRouter.get('/:clothId/add', LoginCheck, asyncHandler(addClothPreview)); //검색-옷장에 등록 -searchRouter.post('/:clothId/add', LoginCheck, asyncHandler(addCloth)); \ No newline at end of file +searchRouter.post('/:clothId/add', LoginCheck, asyncHandler(addCloth)); + +//검색-wish에 추가 +searchRouter.post('/:clothId/wish', LoginCheck, asyncHandler(addWish)); \ No newline at end of file From 672a3b23b013adc1cea78c126967be3c8db9c0a0 Mon Sep 17 00:00:00 2001 From: seoyeoneel02 Date: Thu, 19 Sep 2024 14:57:41 +0900 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20wish=20=EC=B6=94=EA=B0=80=20#125?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domains/search/search.dao.js | 7 ++- src/domains/search/search.dto.js | 5 +- src/domains/search/search.sql.js | 2 +- src/swagger/search.swagger.yaml | 87 +++++++++++++++++++++++++++++++- 4 files changed, 91 insertions(+), 10 deletions(-) diff --git a/src/domains/search/search.dao.js b/src/domains/search/search.dao.js index 212560d..5259f48 100644 --- a/src/domains/search/search.dao.js +++ b/src/domains/search/search.dao.js @@ -228,14 +228,13 @@ export const getAddCloth = async (clothId) => { } // Wish 추가 -export const addWishDAO = async (data) => { +export const addWishDAO = async (userId, clothId) => { try{ const conn = await pool.getConnection(); - - const user = await pool.query(addWishSQL, [data.uuid, data.size]); + const wish = await pool.query(addWish, [clothId, userId]); conn.release(); - return cloth[0].insertId; + return wish[0].insertId; }catch (err) { throw new BaseError(status.PARAMETER_IS_WRONG); } diff --git a/src/domains/search/search.dto.js b/src/domains/search/search.dto.js index 899e3bb..0168caf 100644 --- a/src/domains/search/search.dto.js +++ b/src/domains/search/search.dto.js @@ -172,7 +172,6 @@ export const addClothResponseDTO = (data) => { return {"clothData": cloth}; } -export const addWishDTO = (data) => { - - return; +export const addWishDTO = (wish) => { + return {"wish_id": wish}; } \ No newline at end of file diff --git a/src/domains/search/search.sql.js b/src/domains/search/search.sql.js index 44e6ad8..7309f8f 100644 --- a/src/domains/search/search.sql.js +++ b/src/domains/search/search.sql.js @@ -107,4 +107,4 @@ export const insertRealSize = export const getCloth = "SELECT * FROM cloth WHERE id = ? ; " -export const addWishSQL = "SELECT * FROM wish WHERE from_id = ? AND to_id = ? ; " \ No newline at end of file +export const addWish = "INSERT INTO wish (cloth_id, wisher_uuid) VALUES (?, ?) ;" \ No newline at end of file diff --git a/src/swagger/search.swagger.yaml b/src/swagger/search.swagger.yaml index 96fb640..2b57613 100644 --- a/src/swagger/search.swagger.yaml +++ b/src/swagger/search.swagger.yaml @@ -3,7 +3,8 @@ paths: get: tags: - Search - summary: 전체 옷장 조회 로직 + summary: 검색 메인화면 조회 로직 + operationId: searchPreview parameters: - name: category in: query @@ -92,6 +93,7 @@ paths: tags: - Search summary: 옷 상세 조회 로직 + operationId: searchView parameters: - name: clothId in: path @@ -189,6 +191,7 @@ paths: tags: - Search summary: 통합 검색 조회 로직 + operationId: searchWord parameters: - name: name in: query @@ -290,6 +293,7 @@ paths: tags: - Search summary: 브랜드 상세 조회 로직 + operationId: searchBrand parameters: - name: brandId in: path @@ -388,6 +392,7 @@ paths: tags: - Search summary: 추가할 옷 상세 조회 로직 + operationId: viewAddCloth security: - bearerAuth: [] parameters: @@ -468,7 +473,7 @@ paths: tags: - Search summary: 옷 등록 로직 - operationId: search + operationId: addSearchCloth security: - bearerAuth: [] requestBody: @@ -595,6 +600,84 @@ paths: type: string example: 잘못된 요청입니다 + '500': + description: 서버 에러 + schema: + type: object + properties: + status: + type: integer + example: 500 + isSuccess: + type: boolean + example: false + code: + type: integer + example: COMMON000 + message: + type: string + example: 서버 에러, 관리자에게 문의 바랍니다. + + /FITple/search/{clothId}/wish: + post: + tags: + - Search + summary: wish 등록 로직 + operationId: addWish + security: + - bearerAuth: [] + parameters: + - name: clothId + in: path + required: true + schema: + type: integer + responses: + '200': + description: wish 등록 성공 + schema: + type: object + properties: + status: + type: integer + example: 200 + isSuccess: + type: boolean + example: true + code: + type: integer + example: 200 + message: + type: string + example: "success!" + data: + type: array + example: { + "clothData": [ + { + "cloth_id": 20 + } + ] + } + + '400': + description: 잘못된 요청 + schema: + type: object + properties: + status: + type: integer + example: 400 + isSuccess: + type: boolean + example: false + code: + type: integer + example: COMMON001 + message: + type: string + example: 잘못된 요청입니다 + '500': description: 서버 에러 schema: From a82493648c803a1b1757154f487d9c0686174fdc Mon Sep 17 00:00:00 2001 From: seoyeoneel02 Date: Fri, 20 Sep 2024 14:54:25 +0900 Subject: [PATCH 3/7] =?UTF-8?q?chore:=20=EB=B3=80=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95=20#125?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domains/search/search.dao.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domains/search/search.dao.js b/src/domains/search/search.dao.js index 5259f48..1280e6e 100644 --- a/src/domains/search/search.dao.js +++ b/src/domains/search/search.dao.js @@ -8,7 +8,7 @@ import { UserNicknameToClothId, UserCategoryToClothId, brandToBrandName, userIdToNickname, userToNickname, getBrandToBrandId, userToBrand, categoryToBrand, clothToBrand, clothCategoryToBrand, insertCloth, insertRealSize, getCloth, - addWishSQL } from "./search.sql.js"; + addWish } from "./search.sql.js"; // nickname+cloth 반환 export const getNicknameToClothId = async (category) => { From 79020dfc6cbe53ae2f7674e26f3041a0029d68c3 Mon Sep 17 00:00:00 2001 From: seoyeoneel02 Date: Fri, 20 Sep 2024 15:08:26 +0900 Subject: [PATCH 4/7] =?UTF-8?q?feat:=20wish=20=EC=82=AD=EC=A0=9C=20#125?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domains/search/search.controller.js | 8 ++- src/domains/search/search.dao.js | 15 ++++- src/domains/search/search.dto.js | 4 ++ src/domains/search/search.service.js | 8 ++- src/domains/search/search.sql.js | 4 +- src/routes/search.js | 7 ++- src/swagger/search.swagger.yaml | 77 +++++++++++++++++++++++++ 7 files changed, 116 insertions(+), 7 deletions(-) diff --git a/src/domains/search/search.controller.js b/src/domains/search/search.controller.js index 603a82c..02d3af2 100644 --- a/src/domains/search/search.controller.js +++ b/src/domains/search/search.controller.js @@ -1,7 +1,7 @@ import { response } from "../../config/response.js"; import { status } from "../../config/response.status.js"; import { getSearch, getCloth, getSearchResult, getSearchBrand, getMyCloth } from "./search.provider.js"; -import { addMyCloth, addMyWish } from "./search.service.js"; +import { addMyCloth, addMyWish, delMyWish } from "./search.service.js"; export const searchPreview = async (req, res, next) => { console.log("검색 메인화면을 조회합니다"); @@ -39,4 +39,10 @@ export const addWish = async (req, res, next) => { console.log("관심 있는 옷 추가를 요청하였습니다!"); const userId = res.locals.uuid; res.send(response(status.SUCCESS, await addMyWish(userId, req.params.clothId))); +} + +export const delWish = async (req, res, next) => { + console.log("관심 있는 옷 삭제를 요청하였습니다!"); + const userId = res.locals.uuid; + res.send(response(status.SUCCESS, await delMyWish(userId, req.params.clothId))); } \ No newline at end of file diff --git a/src/domains/search/search.dao.js b/src/domains/search/search.dao.js index 1280e6e..6080938 100644 --- a/src/domains/search/search.dao.js +++ b/src/domains/search/search.dao.js @@ -8,7 +8,7 @@ import { UserNicknameToClothId, UserCategoryToClothId, brandToBrandName, userIdToNickname, userToNickname, getBrandToBrandId, userToBrand, categoryToBrand, clothToBrand, clothCategoryToBrand, insertCloth, insertRealSize, getCloth, - addWish } from "./search.sql.js"; + addWish, delWish } from "./search.sql.js"; // nickname+cloth 반환 export const getNicknameToClothId = async (category) => { @@ -233,6 +233,19 @@ export const addWishDAO = async (userId, clothId) => { const conn = await pool.getConnection(); const wish = await pool.query(addWish, [clothId, userId]); + conn.release(); + return wish[0].insertId; + }catch (err) { + throw new BaseError(status.PARAMETER_IS_WRONG); + } +} + +// Wish 삭제 +export const delWishDAO = async (userId, clothId) => { + try{ + const conn = await pool.getConnection(); + const wish = await pool.query(delWish, [clothId, userId]); + conn.release(); return wish[0].insertId; }catch (err) { diff --git a/src/domains/search/search.dto.js b/src/domains/search/search.dto.js index 0168caf..260039b 100644 --- a/src/domains/search/search.dto.js +++ b/src/domains/search/search.dto.js @@ -174,4 +174,8 @@ export const addClothResponseDTO = (data) => { export const addWishDTO = (wish) => { return {"wish_id": wish}; +} + +export const delWishDTO = (wish) => { + return {"wish_id": wish}; } \ No newline at end of file diff --git a/src/domains/search/search.service.js b/src/domains/search/search.service.js index ffece9d..442c853 100644 --- a/src/domains/search/search.service.js +++ b/src/domains/search/search.service.js @@ -1,7 +1,7 @@ import { BaseError } from "../../config/error.js"; import { status } from "../../config/response.status.js"; -import { addClothResponseDTO, addWishDTO } from "./search.dto.js"; -import { clothAdd, getAddCloth, addWishDAO } from "./search.dao.js"; +import { addClothResponseDTO, addWishDTO, delWishDTO } from "./search.dto.js"; +import { clothAdd, getAddCloth, addWishDAO, delWishDAO } from "./search.dao.js"; export const addMyCloth = async (userId, body) => { const requiredFields = ['name', 'product_code', 'category', 'size', 'fit']; @@ -50,4 +50,8 @@ export const addMyCloth = async (userId, body) => { export const addMyWish = async (userId, clothId) => { return addWishDTO(await addWishDAO(userId, clothId)); +} + +export const delMyWish = async (userId, clothId) => { + return delWishDTO(await delWishDAO(userId, clothId)); } \ No newline at end of file diff --git a/src/domains/search/search.sql.js b/src/domains/search/search.sql.js index 7309f8f..20705e9 100644 --- a/src/domains/search/search.sql.js +++ b/src/domains/search/search.sql.js @@ -107,4 +107,6 @@ export const insertRealSize = export const getCloth = "SELECT * FROM cloth WHERE id = ? ; " -export const addWish = "INSERT INTO wish (cloth_id, wisher_uuid) VALUES (?, ?) ;" \ No newline at end of file +export const addWish = "INSERT INTO wish (cloth_id, wisher_uuid) VALUES (?, ?) ;" + +export const delWish = "DELETE FROM wish WHERE cloth_id = ? AND wisher_uuid = ? ;" \ No newline at end of file diff --git a/src/routes/search.js b/src/routes/search.js index 037fee7..f81c2ef 100644 --- a/src/routes/search.js +++ b/src/routes/search.js @@ -1,7 +1,7 @@ import express from "express"; import asyncHandler from 'express-async-handler'; import { LoginCheck } from "../middlewares/logincheck.js"; -import { searchPreview, clothView, searchView, brandView, addClothPreview, addCloth, addWish } from "../domains/search/search.controller.js"; +import { searchPreview, clothView, searchView, brandView, addClothPreview, addCloth, addWish, delWish } from "../domains/search/search.controller.js"; export const searchRouter = express.Router({mergeParams: true}); @@ -24,4 +24,7 @@ searchRouter.get('/:clothId/add', LoginCheck, asyncHandler(addClothPreview)); searchRouter.post('/:clothId/add', LoginCheck, asyncHandler(addCloth)); //검색-wish에 추가 -searchRouter.post('/:clothId/wish', LoginCheck, asyncHandler(addWish)); \ No newline at end of file +searchRouter.post('/:clothId/wish', LoginCheck, asyncHandler(addWish)); + +//검색-wish에서 삭제 +searchRouter.delete('/:clothId/wish', LoginCheck, asyncHandler(delWish)); \ No newline at end of file diff --git a/src/swagger/search.swagger.yaml b/src/swagger/search.swagger.yaml index 2b57613..b850774 100644 --- a/src/swagger/search.swagger.yaml +++ b/src/swagger/search.swagger.yaml @@ -678,6 +678,83 @@ paths: type: string example: 잘못된 요청입니다 + '500': + description: 서버 에러 + schema: + type: object + properties: + status: + type: integer + example: 500 + isSuccess: + type: boolean + example: false + code: + type: integer + example: COMMON000 + message: + type: string + example: 서버 에러, 관리자에게 문의 바랍니다. + + delete: + tags: + - Search + summary: wish 등록 로직 + operationId: delWish + security: + - bearerAuth: [] + parameters: + - name: clothId + in: path + required: true + schema: + type: integer + responses: + '200': + description: wish 삭제 성공 + schema: + type: object + properties: + status: + type: integer + example: 200 + isSuccess: + type: boolean + example: true + code: + type: integer + example: 200 + message: + type: string + example: "success!" + data: + type: array + example: { + "clothData": [ + { + "cloth_id": 20 + } + ] + } + + '400': + description: 잘못된 요청 + schema: + type: object + properties: + status: + type: integer + example: 400 + isSuccess: + type: boolean + example: false + code: + type: integer + example: COMMON001 + message: + type: string + example: 잘못된 요청입니다 + '500': description: 서버 에러 schema: From 7f5b629ec2d3f8cfd309468b8fa553174c03c942 Mon Sep 17 00:00:00 2001 From: seoyeoneel02 Date: Fri, 20 Sep 2024 15:44:41 +0900 Subject: [PATCH 5/7] =?UTF-8?q?feat:=20wish=20=EC=A1=B0=ED=9A=8C=20#125?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domains/search/search.controller.js | 8 ++- src/domains/search/search.dao.js | 22 +++++-- src/domains/search/search.dto.js | 12 ++++ src/domains/search/search.provider.js | 14 +++-- src/domains/search/search.sql.js | 6 +- src/routes/search.js | 7 ++- src/swagger/search.swagger.yaml | 83 ++++++++++++++++++++++++- 7 files changed, 135 insertions(+), 17 deletions(-) diff --git a/src/domains/search/search.controller.js b/src/domains/search/search.controller.js index 02d3af2..87509ef 100644 --- a/src/domains/search/search.controller.js +++ b/src/domains/search/search.controller.js @@ -1,6 +1,6 @@ import { response } from "../../config/response.js"; import { status } from "../../config/response.status.js"; -import { getSearch, getCloth, getSearchResult, getSearchBrand, getMyCloth } from "./search.provider.js"; +import { getSearch, getCloth, getSearchResult, getSearchBrand, getMyCloth, getMyWish } from "./search.provider.js"; import { addMyCloth, addMyWish, delMyWish } from "./search.service.js"; export const searchPreview = async (req, res, next) => { @@ -45,4 +45,10 @@ export const delWish = async (req, res, next) => { console.log("관심 있는 옷 삭제를 요청하였습니다!"); const userId = res.locals.uuid; res.send(response(status.SUCCESS, await delMyWish(userId, req.params.clothId))); +} + +export const getWish = async (req, res, next) => { + console.log("관심 있는 옷 조회를 요청하였습니다!"); + const userId = res.locals.uuid; + res.send(response(status.SUCCESS, await getMyWish(userId, req.params.clothId))); } \ No newline at end of file diff --git a/src/domains/search/search.dao.js b/src/domains/search/search.dao.js index 6080938..2376f05 100644 --- a/src/domains/search/search.dao.js +++ b/src/domains/search/search.dao.js @@ -8,7 +8,7 @@ import { UserNicknameToClothId, UserCategoryToClothId, brandToBrandName, userIdToNickname, userToNickname, getBrandToBrandId, userToBrand, categoryToBrand, clothToBrand, clothCategoryToBrand, insertCloth, insertRealSize, getCloth, - addWish, delWish } from "./search.sql.js"; + addWishSQL, delWishSQL, getWishSQL } from "./search.sql.js"; // nickname+cloth 반환 export const getNicknameToClothId = async (category) => { @@ -231,7 +231,7 @@ export const getAddCloth = async (clothId) => { export const addWishDAO = async (userId, clothId) => { try{ const conn = await pool.getConnection(); - const wish = await pool.query(addWish, [clothId, userId]); + const wish = await pool.query(addWishSQL, [clothId, userId]); conn.release(); return wish[0].insertId; @@ -244,10 +244,24 @@ export const addWishDAO = async (userId, clothId) => { export const delWishDAO = async (userId, clothId) => { try{ const conn = await pool.getConnection(); - const wish = await pool.query(delWish, [clothId, userId]); + await pool.query(delWishSQL, [clothId, userId]); + const wish = await pool.query(getWishSQL, [clothId, userId]); conn.release(); - return wish[0].insertId; + return wish; + }catch (err) { + throw new BaseError(status.PARAMETER_IS_WRONG); + } +} + +// Wish 조회 +export const getWishDAO = async (userId, clothId) => { + try{ + const conn = await pool.getConnection(); + const wish = await pool.query(getWishSQL, [clothId, userId]); + + conn.release(); + return wish; }catch (err) { throw new BaseError(status.PARAMETER_IS_WRONG); } diff --git a/src/domains/search/search.dto.js b/src/domains/search/search.dto.js index 260039b..27290cd 100644 --- a/src/domains/search/search.dto.js +++ b/src/domains/search/search.dto.js @@ -178,4 +178,16 @@ export const addWishDTO = (wish) => { export const delWishDTO = (wish) => { return {"wish_id": wish}; +} + +export const getWishDTO = (wish) => { + + let wish_id; + if(wish[0].length == 0){ + wish_id = 0; + } else if(wish[0].length == 1){ + wish_id = wish[0][0].id + } + + return {"wish_id": wish_id}; } \ No newline at end of file diff --git a/src/domains/search/search.provider.js b/src/domains/search/search.provider.js index c1c7538..5e80289 100644 --- a/src/domains/search/search.provider.js +++ b/src/domains/search/search.provider.js @@ -1,8 +1,7 @@ -import { previewSearchResponseDTO, previewClothResponseDTO, SearchResultResponseDTO, SearchBrandResponseDTO, previewMyClothResponseDTO } from "./search.dto.js" -import { getNicknameToClothId, - getPreviewCloth, getUserToClothId, - getNicknameToClothName, getPreviewBrand, getPreviewUser, - getBrand, getNicknameToBrand, getPreviewMyCloth } from "./search.dao.js"; +import { previewSearchResponseDTO, previewClothResponseDTO, SearchResultResponseDTO, SearchBrandResponseDTO, + previewMyClothResponseDTO, getWishDTO } from "./search.dto.js" +import { getNicknameToClothId, getPreviewCloth, getUserToClothId, getNicknameToClothName, getPreviewBrand, getPreviewUser, + getBrand, getNicknameToBrand, getPreviewMyCloth, getWishDAO } from "./search.dao.js"; export const getSearch = async (query) => { const { category } = query; @@ -30,4 +29,9 @@ export const getSearchBrand = async (brandId, query) => { export const getMyCloth = async (userId, clothId) => { return previewMyClothResponseDTO(await getPreviewMyCloth(userId, clothId)); +} + +export const getMyWish = async (userId, clothId) => { + + return getWishDTO(await getWishDAO(userId, clothId)); } \ No newline at end of file diff --git a/src/domains/search/search.sql.js b/src/domains/search/search.sql.js index 20705e9..ebe4685 100644 --- a/src/domains/search/search.sql.js +++ b/src/domains/search/search.sql.js @@ -107,6 +107,8 @@ export const insertRealSize = export const getCloth = "SELECT * FROM cloth WHERE id = ? ; " -export const addWish = "INSERT INTO wish (cloth_id, wisher_uuid) VALUES (?, ?) ;" +export const addWishSQL = "INSERT INTO wish (cloth_id, wisher_uuid) VALUES (?, ?) ;" -export const delWish = "DELETE FROM wish WHERE cloth_id = ? AND wisher_uuid = ? ;" \ No newline at end of file +export const delWishSQL = "DELETE FROM wish WHERE cloth_id = ? AND wisher_uuid = ? ;" + +export const getWishSQL = "SELECT id FROM wish WHERE cloth_id = ? AND wisher_uuid = ? ;" \ No newline at end of file diff --git a/src/routes/search.js b/src/routes/search.js index f81c2ef..31c5508 100644 --- a/src/routes/search.js +++ b/src/routes/search.js @@ -1,7 +1,7 @@ import express from "express"; import asyncHandler from 'express-async-handler'; import { LoginCheck } from "../middlewares/logincheck.js"; -import { searchPreview, clothView, searchView, brandView, addClothPreview, addCloth, addWish, delWish } from "../domains/search/search.controller.js"; +import { searchPreview, clothView, searchView, brandView, addClothPreview, addCloth, addWish, delWish, getWish } from "../domains/search/search.controller.js"; export const searchRouter = express.Router({mergeParams: true}); @@ -27,4 +27,7 @@ searchRouter.post('/:clothId/add', LoginCheck, asyncHandler(addCloth)); searchRouter.post('/:clothId/wish', LoginCheck, asyncHandler(addWish)); //검색-wish에서 삭제 -searchRouter.delete('/:clothId/wish', LoginCheck, asyncHandler(delWish)); \ No newline at end of file +searchRouter.delete('/:clothId/wish', LoginCheck, asyncHandler(delWish)); + +//검색-wish +searchRouter.get('/:clothId/wish', LoginCheck, asyncHandler(getWish)); \ No newline at end of file diff --git a/src/swagger/search.swagger.yaml b/src/swagger/search.swagger.yaml index b850774..318a85b 100644 --- a/src/swagger/search.swagger.yaml +++ b/src/swagger/search.swagger.yaml @@ -655,7 +655,7 @@ paths: example: { "clothData": [ { - "cloth_id": 20 + "wish_id": 20 } ] } @@ -699,7 +699,7 @@ paths: delete: tags: - Search - summary: wish 등록 로직 + summary: wish 삭제 로직 operationId: delWish security: - bearerAuth: [] @@ -732,7 +732,84 @@ paths: example: { "clothData": [ { - "cloth_id": 20 + "wish_id": 20 + } + ] + } + + '400': + description: 잘못된 요청 + schema: + type: object + properties: + status: + type: integer + example: 400 + isSuccess: + type: boolean + example: false + code: + type: integer + example: COMMON001 + message: + type: string + example: 잘못된 요청입니다 + + '500': + description: 서버 에러 + schema: + type: object + properties: + status: + type: integer + example: 500 + isSuccess: + type: boolean + example: false + code: + type: integer + example: COMMON000 + message: + type: string + example: 서버 에러, 관리자에게 문의 바랍니다. + + get: + tags: + - Search + summary: wish 조회 로직 + operationId: getWish + security: + - bearerAuth: [] + parameters: + - name: clothId + in: path + required: true + schema: + type: integer + responses: + '200': + description: wish 조회 성공 + schema: + type: object + properties: + status: + type: integer + example: 200 + isSuccess: + type: boolean + example: true + code: + type: integer + example: 200 + message: + type: string + example: "success!" + data: + type: array + example: { + "clothData": [ + { + "wish_id": 20 } ] } From c7b8bb40085188faf8bb050c536928d24716109e Mon Sep 17 00:00:00 2001 From: seoyeoneel02 Date: Fri, 20 Sep 2024 16:23:51 +0900 Subject: [PATCH 6/7] =?UTF-8?q?feat:=20=EC=9D=B4=EB=AF=B8=20=EB=B6=81?= =?UTF-8?q?=EB=A7=88=ED=81=AC=20=ED=95=9C=20=EC=98=B7=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=20=EC=9A=94=EC=B2=AD=20=EC=8B=9C=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EB=B0=98=ED=99=98=20#125?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domains/search/search.dao.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/domains/search/search.dao.js b/src/domains/search/search.dao.js index 2376f05..153d311 100644 --- a/src/domains/search/search.dao.js +++ b/src/domains/search/search.dao.js @@ -231,6 +231,10 @@ export const getAddCloth = async (clothId) => { export const addWishDAO = async (userId, clothId) => { try{ const conn = await pool.getConnection(); + const is_exist = await pool.query(getWishSQL, [clothId, userId]); + if(is_exist[0].length !== 0){ + throw new BaseError(status.PARAMETER_IS_WRONG); + } const wish = await pool.query(addWishSQL, [clothId, userId]); conn.release(); From 216e35d123c3dbb10a2d06e38a1ce542f175088d Mon Sep 17 00:00:00 2001 From: seoyeoneel02 Date: Fri, 20 Sep 2024 16:39:05 +0900 Subject: [PATCH 7/7] =?UTF-8?q?chore:=20=EC=82=AD=EC=A0=9C=20=EC=8B=9C=20w?= =?UTF-8?q?ish=5Fid=200=EC=9C=BC=EB=A1=9C=20=EB=B0=98=ED=99=98=20#125?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domains/search/search.dto.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/domains/search/search.dto.js b/src/domains/search/search.dto.js index 27290cd..6ed6d28 100644 --- a/src/domains/search/search.dto.js +++ b/src/domains/search/search.dto.js @@ -177,7 +177,12 @@ export const addWishDTO = (wish) => { } export const delWishDTO = (wish) => { - return {"wish_id": wish}; + let wish_id; + if(wish[0].length == 0){ + wish_id = 0; + } + + return {"wish_id": wish_id}; } export const getWishDTO = (wish) => {