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

Commit

Permalink
Merge pull request #45 from dcsil/deploy_try
Browse files Browse the repository at this point in the history
Final version MVP
  • Loading branch information
WeiTao3 authored Dec 8, 2022
2 parents 79b7783 + c904e68 commit e0da17c
Show file tree
Hide file tree
Showing 27 changed files with 3,491 additions and 371 deletions.
21 changes: 18 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [ 16.x ]

steps:
- uses: actions/checkout@v2
Expand All @@ -24,7 +24,22 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install requirements
run: npm install | pip3 install -r requirements.txt
- name: Run tests
run: npm run test

- name: Run tests & coverage
run: npm run coverage
env:
CI: true

- name: Upload to CodeClimate
env:
CC_TEST_REPORTER_ID: 197bd3ea34503bd3f3b767813ef33137c182c8b524f90b1611ce03a46c18791e
run: |
export GIT_BRANCH="master"
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter format-coverage ./coverage/clover.xml -t clover --output "coverage/frontend.json"
./cc-test-reporter format-coverage ./coverage.xml -t coverage.py --output "coverage/backend.json"
./cc-test-reporter sum-coverage --output - --parts 2 coverage/frontend.json coverage/backend.json > "coverage/codeclimate.json"
./cc-test-reporter upload-coverage --id $CC_TEST_REPORTER_ID
45 changes: 31 additions & 14 deletions db_helper/mongodb_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ def insert_one_user(user_info: dict):


def update_one_user(user_info):
# check if already store in DB
username = user_info["username"]

query = get_one_user(username)
# exists, update
if query:
pass
# insert
user_col.replace_one({"username": username}, user_info)
# replace

user_col.replace_one({"username": username}, user_info)
else:
user_col.insert_one(user_info)
return "Success"


Expand All @@ -115,19 +115,17 @@ def update_user_history(username: str, influ_id: Optional[str], mode: str):
if mode == "delete":
user_info['history'] = []
else:
update = False
for i, history in enumerate(user_info['history']):
if history['influ_id'] == influ_id:
# update history by time
if mode == "post":
history['time'] = time
update = True
user_info['history'].pop(i)
break
if not update:
user_info['history'].append({
"influ_id": influ_id,
"time": time
})

user_info['history'].insert(0, {
"influ_id": influ_id,
"time": time
})

update_one_user(user_info)
return user_info
Expand All @@ -153,12 +151,31 @@ def update_user_likes(username: str, influ_id: str, mode: str):
'influ_id': influ_id,
'time': time
}
user_info['likes'].append(like_info)
user_info['likes'].insert(0, like_info)
update_one_user(user_info)

return user_info


def update_username(username: str, new_name):
user_info = get_one_user(new_name)
if user_info:
return "Username exists"
user_info = get_one_user(username)
user_info['username'] = new_name
user_col.replace_one({"username": username}, user_info)
return user_info


def update_password(username: str, password):
user_info = get_one_user(username)
if user_info['password'] == password:
return "Same password"
user_info['password'] = password
user_col.replace_one({"username": username}, user_info)
return user_info


if __name__ == '__main__':
print(DB.list_collection_names())
#
Expand Down
38 changes: 35 additions & 3 deletions influco_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def get_influencers_by_tag(tag_str):
all_influ = dbc.get_all_influencer()
match_list = da.get_match_influ(tag_str, all_influ)
res = match_list
# Return error if and only if connection error
# Return error if and only if connection error
except Exception:
return jsonify("error")
return jsonify(res)
Expand All @@ -114,6 +114,40 @@ def get_one_user(username):
return jsonify(res)


@app.route('/influco.api/username/<string:username>', methods=['post'])
def update_username(username):
response_object = {'status': 'fail'}
try:
new_name = request.get_json().get("new_name")
# cannot update duplicate
user = dbc.get_one_user(new_name)
if user:
return jsonify(response_object)
res = dbc.update_username(username, new_name)
# no error message
if not isinstance(res, str):
response_object['status'] = 'success'
response_object['data'] = res
except Exception:
return jsonify({'status': 'error'})
return jsonify(response_object)


@app.route('/influco.api/password/<string:username>', methods=['post'])
def update_password(username):
response_object = {'status': 'fail'}
try:
password = request.get_json().get("password")
res = dbc.update_password(username, password)
# no error message
if not isinstance(res, str):
response_object['status'] = 'success'
response_object['data'] = res
except Exception:
return jsonify({'status': 'error'})
return jsonify(response_object)


@app.route('/influco.api/register/<string:username>', methods=['put'])
def register(username):
"""get info for one user"""
Expand Down Expand Up @@ -147,9 +181,7 @@ def login(username):
user_info = dbc.get_one_user(data["username"])
if not user_info:
return jsonify(response_object)
############## will be replaced ##############
if user_info['password'] != data["password"]:
##############################################
return jsonify(response_object)
response_object['status'] = 'success'
# Frontend: get user data
Expand Down
Loading

0 comments on commit e0da17c

Please sign in to comment.