Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.

Commit e0da17c

Browse files
authored
Merge pull request #45 from dcsil/deploy_try
Final version MVP
2 parents 79b7783 + c904e68 commit e0da17c

27 files changed

Lines changed: 3491 additions & 371 deletions

.github/workflows/ci.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
node-version: [16.x]
17+
node-version: [ 16.x ]
1818

1919
steps:
2020
- uses: actions/checkout@v2
@@ -24,7 +24,22 @@ jobs:
2424
node-version: ${{ matrix.node-version }}
2525
- name: Install requirements
2626
run: npm install | pip3 install -r requirements.txt
27-
- name: Run tests
28-
run: npm run test
27+
28+
- name: Run tests & coverage
29+
run: npm run coverage
2930
env:
3031
CI: true
32+
33+
- name: Upload to CodeClimate
34+
env:
35+
CC_TEST_REPORTER_ID: 197bd3ea34503bd3f3b767813ef33137c182c8b524f90b1611ce03a46c18791e
36+
run: |
37+
export GIT_BRANCH="master"
38+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
39+
chmod +x ./cc-test-reporter
40+
./cc-test-reporter format-coverage ./coverage/clover.xml -t clover --output "coverage/frontend.json"
41+
./cc-test-reporter format-coverage ./coverage.xml -t coverage.py --output "coverage/backend.json"
42+
./cc-test-reporter sum-coverage --output - --parts 2 coverage/frontend.json coverage/backend.json > "coverage/codeclimate.json"
43+
./cc-test-reporter upload-coverage --id $CC_TEST_REPORTER_ID
44+
45+

db_helper/mongodb_connect.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ def insert_one_user(user_info: dict):
9494

9595

9696
def update_one_user(user_info):
97-
# check if already store in DB
9897
username = user_info["username"]
9998

10099
query = get_one_user(username)
101-
# exists, update
102100
if query:
103-
pass
104-
# insert
105-
user_col.replace_one({"username": username}, user_info)
101+
# replace
102+
103+
user_col.replace_one({"username": username}, user_info)
104+
else:
105+
user_col.insert_one(user_info)
106106
return "Success"
107107

108108

@@ -115,19 +115,17 @@ def update_user_history(username: str, influ_id: Optional[str], mode: str):
115115
if mode == "delete":
116116
user_info['history'] = []
117117
else:
118-
update = False
119118
for i, history in enumerate(user_info['history']):
120119
if history['influ_id'] == influ_id:
121120
# update history by time
122121
if mode == "post":
123-
history['time'] = time
124-
update = True
122+
user_info['history'].pop(i)
125123
break
126-
if not update:
127-
user_info['history'].append({
128-
"influ_id": influ_id,
129-
"time": time
130-
})
124+
125+
user_info['history'].insert(0, {
126+
"influ_id": influ_id,
127+
"time": time
128+
})
131129

132130
update_one_user(user_info)
133131
return user_info
@@ -153,12 +151,31 @@ def update_user_likes(username: str, influ_id: str, mode: str):
153151
'influ_id': influ_id,
154152
'time': time
155153
}
156-
user_info['likes'].append(like_info)
154+
user_info['likes'].insert(0, like_info)
157155
update_one_user(user_info)
158156

159157
return user_info
160158

161159

160+
def update_username(username: str, new_name):
161+
user_info = get_one_user(new_name)
162+
if user_info:
163+
return "Username exists"
164+
user_info = get_one_user(username)
165+
user_info['username'] = new_name
166+
user_col.replace_one({"username": username}, user_info)
167+
return user_info
168+
169+
170+
def update_password(username: str, password):
171+
user_info = get_one_user(username)
172+
if user_info['password'] == password:
173+
return "Same password"
174+
user_info['password'] = password
175+
user_col.replace_one({"username": username}, user_info)
176+
return user_info
177+
178+
162179
if __name__ == '__main__':
163180
print(DB.list_collection_names())
164181
#

influco_web.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def get_influencers_by_tag(tag_str):
9797
all_influ = dbc.get_all_influencer()
9898
match_list = da.get_match_influ(tag_str, all_influ)
9999
res = match_list
100-
# Return error if and only if connection error
100+
# Return error if and only if connection error
101101
except Exception:
102102
return jsonify("error")
103103
return jsonify(res)
@@ -114,6 +114,40 @@ def get_one_user(username):
114114
return jsonify(res)
115115

116116

117+
@app.route('/influco.api/username/<string:username>', methods=['post'])
118+
def update_username(username):
119+
response_object = {'status': 'fail'}
120+
try:
121+
new_name = request.get_json().get("new_name")
122+
# cannot update duplicate
123+
user = dbc.get_one_user(new_name)
124+
if user:
125+
return jsonify(response_object)
126+
res = dbc.update_username(username, new_name)
127+
# no error message
128+
if not isinstance(res, str):
129+
response_object['status'] = 'success'
130+
response_object['data'] = res
131+
except Exception:
132+
return jsonify({'status': 'error'})
133+
return jsonify(response_object)
134+
135+
136+
@app.route('/influco.api/password/<string:username>', methods=['post'])
137+
def update_password(username):
138+
response_object = {'status': 'fail'}
139+
try:
140+
password = request.get_json().get("password")
141+
res = dbc.update_password(username, password)
142+
# no error message
143+
if not isinstance(res, str):
144+
response_object['status'] = 'success'
145+
response_object['data'] = res
146+
except Exception:
147+
return jsonify({'status': 'error'})
148+
return jsonify(response_object)
149+
150+
117151
@app.route('/influco.api/register/<string:username>', methods=['put'])
118152
def register(username):
119153
"""get info for one user"""
@@ -147,9 +181,7 @@ def login(username):
147181
user_info = dbc.get_one_user(data["username"])
148182
if not user_info:
149183
return jsonify(response_object)
150-
############## will be replaced ##############
151184
if user_info['password'] != data["password"]:
152-
##############################################
153185
return jsonify(response_object)
154186
response_object['status'] = 'success'
155187
# Frontend: get user data

0 commit comments

Comments
 (0)