Toggle navigation
Toggle navigation
This project
Loading...
Sign in
MotherProject
/
Jaksimsamil
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
1
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
송용우
2020-06-24 23:19:27 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
69794fc207c59f24cfa8fbb11fcca484d8665d53
69794fc2
1 parent
bb80436e
Update recommend API
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
98 additions
and
55 deletions
jaksimsamil-page/src/containers/home/HomeContainer.js
jaksimsamil-server/API.md
jaksimsamil-server/access.log
jaksimsamil-server/src/api/profile/index.js
jaksimsamil-server/src/api/profile/profile.ctrl.js
jaksimsamil-server/src/data/problem_set.js
jaksimsamil-server/src/models/profile.js
jaksimsamil-server/src/util/analyzeBJ.js
jaksimsamil-server/src/util/compareBJ.js
jaksimsamil-page/src/containers/home/HomeContainer.js
View file @
69794fc
...
...
@@ -3,7 +3,6 @@ import { useDispatch, useSelector } from 'react-redux';
import
{
withRouter
}
from
'react-router-dom'
;
import
HomeForm
from
'../../components/home/HomeForm'
;
import
{
getPROFILE
}
from
'../../modules/profile'
;
import
{
analyzeBJ
}
from
'../../lib/util/analyzeBJ'
;
const
HomeContainer
=
({
history
})
=>
{
const
dispatch
=
useDispatch
();
const
{
user
,
profile
}
=
useSelector
(({
user
,
profile
})
=>
({
...
...
jaksimsamil-server/API.md
View file @
69794fc
...
...
@@ -18,22 +18,22 @@
## 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 |
| user | 전체 유저 조회 | GET | api/user
| 바로가기 | JWT Token |
| friend | 유저 친구 등록 | POST | api/friend
| 바로가기 | JWT Token |
| friend | 유저의 친구 조회 | GET | api/friend:id
| 바로가기 | None |
| profile | 유저가 푼 문제 조회(백준) | GET | api/profile/solvedBJ:id
| 바로가기 | None |
| profile | 유저가 푼 문제 동기화(백준) | PATCH | api/profile/syncBJ
| 바로가기 | None |
| profile | 유저 정보 수정 | POST | api/profile/setprofile
| 바로가기 | JWT TOKEN |
| profile | 유저 정보 받아오기 | POST | api/profile/getprofile
| 바로가기 | JWT |
| profile | 추천 문제 조회 |
GET | api/profile/recommend:id
| 바로가기 | None |
| notify | 슬랙 메시지 전송 요청 | POST | api/notify/
|
| 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 |
| user | 전체 유저 조회 | GET | api/user | 바로가기 | JWT Token |
| friend | 유저 친구 등록 | POST | api/friend | 바로가기 | JWT Token |
| friend | 유저의 친구 조회 | GET | api/friend:id | 바로가기 | None |
| profile | 유저가 푼 문제 조회(백준) | GET | api/profile/solvedBJ:id | 바로가기 | None |
| profile | 유저가 푼 문제 동기화(백준) | PATCH | api/profile/syncBJ | 바로가기 | None |
| 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 |
| auth | 로그인 | POST | api/auth/login
| 바로가기 | None |
| auth | 로그아웃 | POST | api/auth/logout
| 바로가기 | JWT Token |
| auth | 회원가입 | POST | api/auth/register
| 바로가기 | None |
| auth | 로그인 확인 | GET | api/auth/check
| 바로가기 | None |
| auth | 로그인 | POST | api/auth/login | 바로가기 | None |
| auth | 로그아웃 | POST | api/auth/logout | 바로가기 | JWT Token |
| auth | 회원가입 | POST | api/auth/register | 바로가기 | None |
| auth | 로그인 확인 | GET | api/auth/check | 바로가기 | None |
...
...
jaksimsamil-server/access.log
View file @
69794fc
...
...
@@ -1286,3 +1286,28 @@
::ffff:127.0.0.1 - - [24/Jun/2020:11:31:05 +0000] "POST /api/profile/getprofile HTTP/1.1" 200 16266 "http://localhost:3000/" "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:11:39:21 +0000] "POST /api/profile/getprofile HTTP/1.1" 401 12 "http://localhost:3000/" "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:11:39:22 +0000] "POST /api/profile/getprofile HTTP/1.1" 200 16266 "http://localhost:3000/" "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:13:41:48 +0000] "PATCH /api/profile/syncBJ HTTP/1.1" 200 33281 "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:13:42:48 +0000] "PATCH /api/profile/syncBJ HTTP/1.1" 200 33281 "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:13:52:15 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:53:07 +0000] "POST /api/profile/recommend HTTP/1.1" 500 21 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:54:22 +0000] "POST /api/profile/recommend HTTP/1.1" 500 21 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:54:40 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:55:32 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:57:11 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:57:49 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:58:26 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::ffff:127.0.0.1 - - [24/Jun/2020:13:58:49 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:58:59 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:13:59:43 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:00:09 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:02:01 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:02:52 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:03:53 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:04:43 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:05:13 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:07:09 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:08:00 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:09:35 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:10:57 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:11:19 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
::1 - - [24/Jun/2020:14:12:04 +0000] "POST /api/profile/recommend HTTP/1.1" 404 9 "-" "PostmanRuntime/7.25.0"
...
...
jaksimsamil-server/src/api/profile/index.js
View file @
69794fc
const
Router
=
require
(
"koa-router"
);
const
profile
=
new
Router
();
const
profileCtrl
=
require
(
"./profile.ctrl"
);
profile
.
post
(
"/solved:id"
);
profile
.
get
(
"/solvednum:id"
);
profile
.
get
(
"/recommendps:id"
);
profile
.
post
(
"/recommend"
,
profileCtrl
.
recommend
);
profile
.
patch
(
"/syncBJ"
,
profileCtrl
.
syncBJ
);
profile
.
post
(
"/setprofile"
,
profileCtrl
.
setProfile
);
profile
.
post
(
"/getprofile"
,
profileCtrl
.
getProfile
);
...
...
jaksimsamil-server/src/api/profile/profile.ctrl.js
View file @
69794fc
...
...
@@ -2,6 +2,9 @@ const Profile = require("../../models/profile");
const
mongoose
=
require
(
"mongoose"
);
const
getBJ
=
require
(
"../../util/getBJ"
);
const
Joi
=
require
(
"joi"
);
const
analyzeBJ
=
require
(
"../../util/analyzeBJ"
);
const
compareBJ
=
require
(
"../../util/compareBJ"
);
const
problem_set
=
require
(
"../../data/problem_set"
);
const
{
ObjectId
}
=
mongoose
.
Types
;
...
...
@@ -95,9 +98,10 @@ exports.syncBJ = async function (ctx) {
}
const
BJID
=
await
profile
.
getBJID
();
let
BJdata
=
await
getBJ
.
getBJ
(
BJID
);
let
BJdata_date
=
await
analyzeBJ
.
analyzeBJ
(
BJdata
);
const
updateprofile
=
await
Profile
.
findOneAndUpdate
(
{
username
:
username
},
{
solvedBJ
:
BJdata
},
{
solvedBJ
:
BJdata
,
solvedBJ_date
:
BJdata_date
},
{
new
:
true
}
).
exec
();
ctx
.
body
=
updateprofile
;
...
...
@@ -105,3 +109,34 @@ exports.syncBJ = async function (ctx) {
ctx
.
throw
(
500
,
e
);
}
};
s
;
/*
POST /api/proflie/recommend
{
username: 'userid'
}
*/
exports
.
recommend
=
async
(
ctx
)
=>
{
const
{
username
}
=
ctx
.
request
.
body
;
if
(
!
username
)
{
ctx
.
status
=
401
;
return
;
}
try
{
const
profile
=
await
Profile
.
findByUsername
(
username
);
if
(
!
profile
)
{
ctx
.
status
=
401
;
return
;
}
let
unsolved_data
=
compareBJ
.
compareBJ
(
profile
.
getBJdata
(),
problem_set
.
problem_set
);
ctx
.
body
=
compareBJ
.
randomItem
(
unsolved_data
);
//데이터가 비었을 떄 예외처리 필요
}
catch
(
e
)
{
ctx
.
throw
(
500
,
e
);
}
};
...
...
jaksimsamil-server/src/data/problem_set.js
View file @
69794fc
export
const
problem_set
=
[
export
s
.
problem_set
=
[
"1517"
,
"2448"
,
"1891"
,
...
...
jaksimsamil-server/src/models/profile.js
View file @
69794fc
...
...
@@ -6,6 +6,7 @@ const ProfileSchema = new Schema({
username
:
{
type
:
String
,
required
:
true
,
unique
:
true
},
userBJID
:
String
,
solvedBJ
:
Object
,
solvedBJ_date
:
Object
,
friendList
:
[
String
],
slackWebHookURL
:
String
,
});
...
...
@@ -15,6 +16,9 @@ ProfileSchema.statics.findByUsername = function (username) {
ProfileSchema
.
methods
.
getBJID
=
function
()
{
return
this
.
userBJID
;
};
ProfileSchema
.
methods
.
getBJdata
=
function
()
{
return
this
.
solvedBJ
;
};
ProfileSchema
.
methods
.
serialize
=
function
()
{
const
data
=
this
.
toJSON
();
...
...
jaksimsamil-server/src/util/analyzeBJ.js
View file @
69794fc
/*
2. 현재 날짜와의 차이 =>
3. 오늘 푼 문제 => 앞에서부터 순회하면서 데이트 같은거 찾기
3. 최근 일주일간 푼 문제 수 => 앞에서부터 순회하면서 - 값이
4. 추천 문제 => 정규 셋에서 없는거 찾기
5. 날짜별로 묶기.
데이터베이스에서 처리하자
*/
let
moment
=
require
(
'moment'
);
let
moment
=
require
(
"moment"
);
exports
.
analyzeBJ
=
function
(
solvedBJ
)
{
try
{
if
(
solvedBJ
)
{
console
.
log
(
solvedBJ
[
0
]);
let
presentDate
=
moment
();
let
presentDate_str
=
presentDate
.
format
(
'YYYYMMDD'
);
let
latestDate
=
moment
(
solvedBJ
[
0
].
solved_date
,
'YYYYMMDD'
);
let
difflatest
=
presentDate
.
diff
(
latestDate
,
'days'
);
let
presentDate_str
=
presentDate
.
format
(
"YYYYMMDD"
);
let
latestDate
=
moment
(
solvedBJ
[
0
].
solved_date
,
"YYYYMMDD"
);
let
difflatest
=
presentDate
.
diff
(
latestDate
,
"days"
);
let
solvedBJbyDATE
=
{};
for
(
let
i
=
0
;
i
<
solvedBJ
.
length
;
i
++
)
{
...
...
@@ -34,13 +24,13 @@ exports.analyzeBJ = function (solvedBJ) {
?
solvedBJbyDATE
[
presentDate_str
].
length
:
0
;
let
returnOBJ
=
{
latestDate
:
latestDate
.
format
(
'YYYYMMDD'
),
latestDate
:
latestDate
.
format
(
"YYYYMMDD"
),
difflatest
:
difflatest
,
latestNum
:
latestNum
,
presentNum
:
presentNum
,
solvedBJbyDATE
:
solvedBJbyDATE
,
};
console
.
log
(
returnOBJ
);
return
returnOBJ
;
}
}
catch
(
e
)
{
...
...
jaksimsamil-server/src/util/compareBJ.js
View file @
69794fc
/*
집중을 해보자.
새거와 데이터가 있다.
데이터 기준으로 새거에 자료가 있으면 넘어가기
없으면 새 배열에 추가
키만 모아둔 리스트를 만들자.
그렇게 해서
반복은 새거 길이만큼
데이터에 있으면 추가 X
없으면 추가
그렇게 반환
*/
exports
.
compareBJ
=
function
(
solvedBJ_new
,
problem_set
)
{
try
{
let
new_obj
=
[];
for
(
let
i
=
0
;
i
<
solvedBJ
.
length
;
i
++
)
{
if
(
solvedBJ_new
[
i
].
problem_number
in
problem_set
)
{
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
]);
}
}
console
.
log
(
new_obj
)
;
return
new_obj
;
}
catch
(
e
)
{
console
.
log
(
e
);
}
};
exports
.
randomItem
=
function
(
a
)
{
return
a
[
Math
.
floor
(
Math
.
random
()
*
a
.
length
)];
};
...
...
Please
register
or
login
to post a comment