Toggle navigation
Toggle navigation
This project
Loading...
Sign in
정나리
/
Jaksimsamil
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
송용우
2020-06-25 03:02:57 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ccd63467a6e5979f508b027fc748db49f49a2dc3
ccd63467
1 parent
803e5995
Update Slack api
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
177 additions
and
17 deletions
jaksimsamil-server/API.md
jaksimsamil-server/access.log
jaksimsamil-server/src/api/index.js
jaksimsamil-server/src/api/notify/index.js
jaksimsamil-server/src/api/notify/slack.ctrl.js
jaksimsamil-server/src/data/problem_set.js
jaksimsamil-server/src/models/profile.js
jaksimsamil-server/src/util/compareBJ.js
jaksimsamil-server/src/util/sendSlack.js
jaksimsamil-server/src/util/test.js
jaksimsamil-server/src/util/test.json
jaksimsamil-server/API.md
View file @
ccd6346
...
...
@@ -19,7 +19,7 @@
## API Table
| group | description | method | URL | Detail | Auth |
| ------- | ---------------------------
| ---
------ | ----------------------- | -------- | --------- |
| ------- | ---------------------------
------ |
------ | ----------------------- | -------- | --------- |
| user | 유저 등록 | POST | api/user | 바로가기 | JWT Token |
| user | 유저 삭제 | DELETE | api/user:id | 바로가기 | JWT Token |
| user | 특정 유저 조회 | GET | api/user:id | 바로가기 | None |
...
...
@@ -31,8 +31,8 @@
| profile | 유저 정보 수정 | POST | api/profile/setprofile | 바로가기 | JWT TOKEN |
| profile | 유저 정보 받아오기 | POST | api/profile/getprofile | 바로가기 | JWT |
| profile | 추천 문제 조회 | POST | api/profile/recommend | 바로가기 | None |
| notify | 슬랙 메시지 전송 요청
| POST | api/notify/
|
|
slack | 바로가기 | Jwt Token
|
| notify | 슬랙 메시지 전송 요청
(성취여부) | POST | api/notify/goal | 바로가기 | Jwt Token
|
|
notify | 슬랙 메시지 전송 요청 (문제 추천) | POST | api/notify/recommend | 바로가기 | None
|
| auth | 로그인 | POST | api/auth/login | 바로가기 | None |
| auth | 로그아웃 | POST | api/auth/logout | 바로가기 | JWT Token |
| auth | 회원가입 | POST | api/auth/register | 바로가기 | None |
...
...
jaksimsamil-server/access.log
View file @
ccd6346
...
...
@@ -1341,3 +1341,44 @@
::ffff:127.0.0.1 - - [24/Jun/2020:15:41:51 +0000] "GET /api/auth/check HTTP/1.1" 200 55 "http://localhost:3000/setting" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36 Edg/83.0.478.54"
::ffff:127.0.0.1 - - [24/Jun/2020:15:41:51 +0000] "POST /api/profile/getprofile HTTP/1.1" 401 12 "http://localhost:3000/setting" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36 Edg/83.0.478.54"
::ffff:127.0.0.1 - - [24/Jun/2020:15:41:51 +0000] "POST /api/profile/getprofile HTTP/1.1" 200 33293 "http://localhost:3000/setting" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36 Edg/83.0.478.54"
::1 - - [24/Jun/2020:16:47:20 +0000] "POST /api/notify/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:16:47:43 +0000] "POST /api/notify/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:16:48:07 +0000] "POST /api/notify/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:16:49:04 +0000] "POST /api/notify/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:16:50:59 +0000] "POST /api/notify/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:16:52:40 +0000] "POST /api/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::ffff:127.0.0.1 - - [24/Jun/2020:16:52:55 +0000] "POST /api/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:16:54:01 +0000] "POST /api/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:16:54:14 +0000] "POST /api/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:16:54:28 +0000] "POST /api/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:16:56:14 +0000] "POST /api/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:16:56:33 +0000] "POST /api/profile/getprofile HTTP/1.1" 200 33293 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:16:56:52 +0000] "POST /api/notify/slack/goal HTTP/1.1" 500 21 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:16:57:18 +0000] "POST /api/notify/slack/goal HTTP/1.1" 500 21 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:16:57:50 +0000] "POST /api/notify/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:00:04 +0000] "POST /api/notify/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::ffff:127.0.0.1 - - [24/Jun/2020:17:00:27 +0000] "POST /api/profile/getprofile HTTP/1.1" 200 33293 "http://localhost:3000/setting" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36 Edg/83.0.478.54"
::ffff:127.0.0.1 - - [24/Jun/2020:17:00:29 +0000] "POST /api/profile/setprofile HTTP/1.1" 200 33293 "http://localhost:3000/setting" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36 Edg/83.0.478.54"
::1 - - [24/Jun/2020:17:00:37 +0000] "POST /api/notify/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:01:46 +0000] "POST /api/notify/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::ffff:127.0.0.1 - - [24/Jun/2020:17:12:37 +0000] "POST /api/notify/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:13:17 +0000] "POST /api/notify/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:13:36 +0000] "POST /api/notify/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:14:19 +0000] "POST /api/notify/slack/goal HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:22:37 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:23:06 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:27:52 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:30:55 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:32:42 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:34:03 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:36:50 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:40:43 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 500 21 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:42:09 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:43:17 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:53:11 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:53:24 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:54:40 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:55:11 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:55:24 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:17:55:39 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:18:00:32 +0000] "POST /api/notify/slack/recommend HTTP/1.1" 500 21 "-" "PostmanRuntime/7.25.0"
...
...
jaksimsamil-server/src/api/index.js
View file @
ccd6346
...
...
@@ -3,7 +3,7 @@ const api = new Router();
const
auth
=
require
(
"./auth"
);
const
friend
=
require
(
"./friend"
);
const
notify
=
require
(
"./
profile
"
);
const
notify
=
require
(
"./
notify
"
);
const
user
=
require
(
"./user"
);
const
profile
=
require
(
"./profile"
);
...
...
jaksimsamil-server/src/api/notify/index.js
View file @
ccd6346
const
Router
=
require
(
"koa-router"
);
const
notify
=
new
Router
();
notify
.
post
(
"/slack"
);
const
slackCtrl
=
require
(
"./slack.ctrl"
);
notify
.
post
(
"/slack/goal"
,
slackCtrl
.
slackGoal
);
notify
.
post
(
"/slack/recommend"
,
slackCtrl
.
slackRecommend
);
module
.
exports
=
notify
;
...
...
jaksimsamil-server/src/api/notify/slack.ctrl.js
0 → 100644
View file @
ccd6346
const
Profile
=
require
(
"../../models/profile"
);
const
sendSlack
=
require
(
"../../util/sendSlack"
);
const
problem_set
=
require
(
"../../data/problem_set"
);
const
compareBJ
=
require
(
"../../util/compareBJ"
);
/*
POST api/notify/slack/goal
{
username: "username"
}
*/
exports
.
slackGoal
=
async
(
ctx
)
=>
{
try
{
const
{
username
}
=
ctx
.
request
.
body
;
const
profile
=
await
Profile
.
findByUsername
(
username
);
if
(
!
profile
)
{
ctx
.
status
=
401
;
return
;
}
let
slackURL
=
profile
.
getslackURL
();
if
(
!
slackURL
)
{
ctx
.
status
=
401
;
return
;
}
let
goalNum
=
profile
.
getgoalNum
();
let
todayNum
=
profile
.
getTodaySovled
();
let
message
=
""
;
if
(
goalNum
<
todayNum
)
{
message
=
"오늘의 목표 "
+
goalNum
+
"문제 중 "
+
todayNum
+
"문제를 풀었습니다."
+
"\n"
+
"잘하셨습니다!"
;
}
else
{
message
=
"오늘의 목표 "
+
goalNum
+
"문제 중 "
+
todayNum
+
"문제를 풀었습니다."
+
"\n"
+
"분발하세요!"
;
}
sendSlack
.
send
(
message
,
slackURL
);
}
catch
(
e
)
{
ctx
.
throw
(
500
,
e
);
}
};
/*
POST api/notify/slack/recommend
{
username: "username"
}
*/
exports
.
slackRecommend
=
async
(
ctx
)
=>
{
try
{
console
.
log
(
"1"
);
const
{
username
}
=
ctx
.
request
.
body
;
const
profile
=
await
Profile
.
findByUsername
(
username
);
if
(
!
profile
)
{
ctx
.
status
=
401
;
return
;
}
let
slackURL
=
profile
.
getslackURL
();
if
(
!
slackURL
)
{
ctx
.
status
=
401
;
return
;
}
let
unsolved_data
=
compareBJ
.
compareBJ
(
profile
.
getBJdata
(),
problem_set
.
problem_set
);
let
recommendData
=
compareBJ
.
randomItem
(
unsolved_data
);
if
(
!
recommendData
)
{
ctx
.
status
=
401
;
return
;
}
let
message
=
"오늘의 추천 문제는 "
+
recommendData
.
problem_number
+
"번 "
+
" <https://www.boj.kr/"
+
recommendData
.
problem_number
+
"|"
+
recommendData
.
problem_title
+
">"
+
" 입니다."
;
sendSlack
.
send
(
message
,
slackURL
);
}
catch
(
e
)
{
ctx
.
throw
(
500
,
e
);
}
};
jaksimsamil-server/src/data/problem_set.js
View file @
ccd6346
This diff is collapsed. Click to expand it.
jaksimsamil-server/src/models/profile.js
View file @
ccd6346
...
...
@@ -20,6 +20,17 @@ ProfileSchema.methods.getBJID = function () {
ProfileSchema
.
methods
.
getBJdata
=
function
()
{
return
this
.
solvedBJ
;
};
ProfileSchema
.
methods
.
getslackURL
=
function
()
{
return
this
.
slackWebHookURL
;
};
ProfileSchema
.
methods
.
getgoalNum
=
function
()
{
return
this
.
goalNum
;
};
ProfileSchema
.
methods
.
getTodaySovled
=
function
()
{
if
(
this
.
solvedBJ_date
)
{
return
this
.
solvedBJ_date
.
presentNum
;
}
};
ProfileSchema
.
methods
.
serialize
=
function
()
{
const
data
=
this
.
toJSON
();
...
...
jaksimsamil-server/src/util/compareBJ.js
View file @
ccd6346
exports
.
compareBJ
=
function
(
solvedBJ_new
,
problem_set
)
{
try
{
let
new_obj
=
[];
for
(
let
i
=
0
;
i
<
solvedBJ_new
.
length
;
i
++
)
{
if
(
!
problem_set
.
includes
(
String
(
solvedBJ_new
[
i
].
problem_number
)))
{
new_obj
.
push
(
solvedBJ_new
[
i
]);
for
(
let
i
=
0
;
i
<
problem_set
.
length
;
i
++
)
{
let
found
=
false
;
for
(
let
j
=
0
;
j
<
solvedBJ_new
.
length
;
j
++
)
{
if
(
solvedBJ_new
[
j
].
problem_number
==
problem_set
[
i
].
problem_number
)
{
found
=
true
;
break
;
}
}
if
(
!
found
)
{
new_obj
.
push
(
problem_set
[
i
]);
}
}
console
.
log
(
new_obj
);
return
new_obj
;
}
catch
(
e
)
{
console
.
log
(
e
);
...
...
jaksimsamil-server/src/util/sendSlack.js
View file @
ccd6346
const
Slack
=
require
(
"slack-node"
);
// 슬랙 모듈 사용
/*
const webhookUri =
"https://hooks.slack.com/services/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"
;
// Webhook URL
"https://hooks.slack.com/services/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"; // Webhook URL
*/
const
slack
=
new
Slack
();
slack
.
setWebhook
(
webhookUri
);
const
send
=
async
(
message
)
=>
{
exports
.
send
=
async
(
message
,
webhookUri
)
=>
{
const
slack
=
new
Slack
();
slack
.
setWebhook
(
webhookUri
);
slack
.
webhook
(
{
text
:
message
,
...
...
@@ -16,5 +17,3 @@ const send = async (message) => {
}
);
};
send
(
"hello"
);
...
...
jaksimsamil-server/src/util/test.js
View file @
ccd6346
...
...
@@ -8,7 +8,7 @@ const test = async (userid) => {
return_lst
.
push
(
lst
[
i
].
problem_number
);
}
var
stringJson
=
JSON
.
stringify
(
return_
lst
)
+
"\n"
;
var
stringJson
=
JSON
.
stringify
(
lst
)
+
"\n"
;
fs
.
open
(
"test.json"
,
"a"
,
"666"
,
function
(
err
,
id
)
{
if
(
err
)
{
console
.
log
(
"file open err!!"
);
...
...
jaksimsamil-server/src/util/test.json
View file @
ccd6346
This diff is collapsed. Click to expand it.
Please
register
or
login
to post a comment