Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated and improved search api #22

Merged
merged 1 commit into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class Config:

MONGO_URI = os.getenv("MONGO_URI")
SECRET_KEY = os.getenv("SECRET_KEY")
# MONGO_URI = "mongodb+srv://scooptroop:scooptroop123@elixir.csdhw.mongodb.net/elixir?retryWrites=true&w=majority"
# SECRET_KEY = "thiswillcontainsecretkey"
ALLOWED_EXTENSIONS = {"txt", "pdf", "doc", "jpg", "jpeg", "png"}
Path("server/static/uploads").mkdir(parents=True, exist_ok=True)
UPLOAD_FOLDER = os.path.join(os.getcwd(), "server", "static", "uploads")
24 changes: 18 additions & 6 deletions server/records/routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import json
import re
import datetime
from bson import ObjectId
from server.config import Config
Expand Down Expand Up @@ -156,16 +156,28 @@ def addAttachment(_id, rid):
return jsonify({"message": "Attachement Added!"}), 200


@records.route("/api/users/search", defaults={"hid": None}, methods=["GET"])
@records.route("/api/users/search/<hid>", methods=["GET"])
@records.route("/api/users/search", methods=["GET"])
@token_required
def getHealthOfficials(_id, hid):
if hid is None:
def getHealthOfficials(_id):
hid = request.args.get("hid", default=None, type=str)
name = request.args.get("name", default=None, type=str)
regex = re.compile(f".*{name}.*", re.IGNORECASE)

if hid is None and name is None:
healthOfficials = HealthOfficial.objects.scalar("name", "email").to_json()
return healthOfficials, 200
else:

elif hid and name is None:
healthOfficial = HealthOfficial.objects(_id=ObjectId(hid)).scalar(
"name", "email"
)
healthOfficial = healthOfficial.to_json()
return healthOfficial, 200

elif name and hid is None:
healthOfficial = HealthOfficial.objects(name=regex).scalar("name", "email")
healthOfficial = healthOfficial.to_json()
return healthOfficial, 200

else:
return jsonify({"message": "Bad Request"}), 400