From b901e4515d2ad1574a2e3cf55957d84de2d08724 Mon Sep 17 00:00:00 2001 From: seoyeoneel02 Date: Sun, 27 Oct 2024 06:49:00 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20userId=20=EC=B6=94=EA=B0=80=20#84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domains/search/search.controller.js | 3 ++- src/domains/search/search.repository.js | 6 +++--- src/domains/search/search.service.js | 4 ++-- src/domains/search/search.sql.js | 8 ++++---- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/domains/search/search.controller.js b/src/domains/search/search.controller.js index 12ea3ba..eecc933 100644 --- a/src/domains/search/search.controller.js +++ b/src/domains/search/search.controller.js @@ -4,5 +4,6 @@ import { searchService } from "./search.service.js"; export const searchController = async (req, res, next) => { console.log("수업을 검색합니다!"); - res.send(response(status.SUCCESS, await searchService(req.query))); + const userId = req.decoded.userId; + res.send(response(status.SUCCESS, await searchService(userId, req.query))); } \ No newline at end of file diff --git a/src/domains/search/search.repository.js b/src/domains/search/search.repository.js index 19866e7..74e5813 100644 --- a/src/domains/search/search.repository.js +++ b/src/domains/search/search.repository.js @@ -3,18 +3,18 @@ import { status } from "../../response.status.js"; import { pool } from "../../db.config.js"; import { searchSql, searchNameSql } from "./search.sql.js"; -export const searchRepo = async (type, name) => { +export const searchRepo = async (userId, type, name) => { const conn = await pool.getConnection(); try { if(typeof type == "undefined") { throw new BaseError(status.PARAMETER_IS_WRONG); } if(typeof name == "undefined"){ - const major = await pool.query(searchSql, type); + const major = await pool.query(searchSql, [userId, type]); conn.release(); return major; }else{ - const major = await pool.query(searchNameSql, [type, name]); + const major = await pool.query(searchNameSql, [userId, type, name]); conn.release(); return major; } diff --git a/src/domains/search/search.service.js b/src/domains/search/search.service.js index 8e3d962..f4ac472 100644 --- a/src/domains/search/search.service.js +++ b/src/domains/search/search.service.js @@ -1,8 +1,8 @@ import { searchDTO } from "./search.dto.js"; import { searchRepo } from "./search.repository.js"; -export const searchService = async (query) => { +export const searchService = async (userId, query) => { const { type, name } = query; - const major = await searchRepo(type, name); + const major = await searchRepo(userId, type, name); return searchDTO(major); } \ No newline at end of file diff --git a/src/domains/search/search.sql.js b/src/domains/search/search.sql.js index f250a22..a8abacc 100644 --- a/src/domains/search/search.sql.js +++ b/src/domains/search/search.sql.js @@ -1,9 +1,9 @@ export const searchSql = -"SELECT credit, name, CASE WHEN us.user_id IS NOT NULL THEN 1 ELSE 0 END AS bookmark FROM subject s " -+ "JOIN user_subject us ON s.name = us.subject_name " +"SELECT s.id, credit, name, CASE WHEN us.user_id IS NOT NULL THEN 1 ELSE 0 END AS bookmark FROM subject s " ++ "JOIN user_subject us ON s.name = us.subject_name AND user_id = ? " + "WHERE type = ? ORDER BY s.id;" export const searchNameSql = -"SELECT credit, name, CASE WHEN us.user_id IS NOT NULL THEN 1 ELSE 0 END AS bookmark FROM subject s " -+ "JOIN user_subject us ON s.name = us.subject_name " +"SELECT s.id, credit, name, CASE WHEN us.user_id IS NOT NULL THEN 1 ELSE 0 END AS bookmark FROM subject s " ++ "JOIN user_subject us ON s.name = us.subject_name AND user_id = ? " + "WHERE type = ? AND name REGEXP ? ORDER BY s.id;" \ No newline at end of file