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