유명현

ADD: Implement to add Keyword to server

1 +// Line chatbot + Message generate functions
1 const line = require("@line/bot-sdk"); 2 const line = require("@line/bot-sdk");
2 const setFlexMessage = require("./message/setFlexMessage"); 3 const setFlexMessage = require("./message/setFlexMessage");
3 const setCarouselMessage = require("./message/setCarouselMessage"); 4 const setCarouselMessage = require("./message/setCarouselMessage");
4 -const fs = require("fs"); 5 +
6 +// Market Search
5 const { daangnSingleSearch } = require("./search/daangnSearch"); 7 const { daangnSingleSearch } = require("./search/daangnSearch");
6 const { daangnMultiSearch } = require("./search/daangnSearch"); 8 const { daangnMultiSearch } = require("./search/daangnSearch");
7 const { joongnaSingleSearch } = require("./search/joongnaSearch"); 9 const { joongnaSingleSearch } = require("./search/joongnaSearch");
...@@ -10,6 +12,20 @@ const { bunjangSingleSearch } = require("./search/bunjangSearch"); ...@@ -10,6 +12,20 @@ const { bunjangSingleSearch } = require("./search/bunjangSearch");
10 const { bunjangMultiSearch } = require("./search/bunjangSearch"); 12 const { bunjangMultiSearch } = require("./search/bunjangSearch");
11 const { marketMultiSearch } = require("./search/marketSearch"); 13 const { marketMultiSearch } = require("./search/marketSearch");
12 14
15 +// File search - Will be deleted (Unused)
16 +const fs = require("fs");
17 +
18 +// Database APIs
19 +const db = require("../apis/database");
20 +// API List
21 +// database.addKeyword = async function(keyword, userId)
22 +// database.deleteKeyword = async function(userId, keyword)
23 +// database.getKeywordsByUserId = async function(userId)
24 +// database.getUsersByKeyword = async function(keyword)
25 +// database.getAllUsers = async function()
26 +// database.getAllKeywords = async function()
27 +
28 +// Import credentials for Line chatbot
13 require("dotenv").config({ path: __dirname + "/../.env" }); 29 require("dotenv").config({ path: __dirname + "/../.env" });
14 const config = { 30 const config = {
15 channelAccessToken: process.env.channelAccessToken, 31 channelAccessToken: process.env.channelAccessToken,
...@@ -28,7 +44,7 @@ function handleEvent(event) { ...@@ -28,7 +44,7 @@ function handleEvent(event) {
28 var found = waitNewMamulList.indexOf(event.source.userId); 44 var found = waitNewMamulList.indexOf(event.source.userId);
29 if (found == -1) { 45 if (found == -1) {
30 waitNewMamulList.push(event.source.userId); 46 waitNewMamulList.push(event.source.userId);
31 - console.log(waitNewMamulList); 47 + console.log(`waitNewMamulList Changed : ${waitNewMamulList}`);
32 return Promise.resolve( 48 return Promise.resolve(
33 client.replyMessage(event.replyToken, { 49 client.replyMessage(event.replyToken, {
34 type: "text", 50 type: "text",
...@@ -75,6 +91,7 @@ function handleEvent(event) { ...@@ -75,6 +91,7 @@ function handleEvent(event) {
75 waitNewMamulList.splice(found, 1); 91 waitNewMamulList.splice(found, 1);
76 console.log(waitNewMamulList[found]); 92 console.log(waitNewMamulList[found]);
77 return Promise.resolve( 93 return Promise.resolve(
94 + db.addKeyword(event.message.text, event.source.userId),
78 client.replyMessage(event.replyToken, { 95 client.replyMessage(event.replyToken, {
79 type: "text", 96 type: "text",
80 text: `매물이 등록되었습니다!\n등록된 매물: ${event.message.text}`, 97 text: `매물이 등록되었습니다!\n등록된 매물: ${event.message.text}`,
......