-
Notifications
You must be signed in to change notification settings - Fork 4
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
Dev user endpoint #25
Merged
+63
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from flask import Blueprint, Flask, request, Response, Request | ||
from ..database import db | ||
from ..models.user import User | ||
from sqlalchemy_helpers import get_or_create | ||
from .util import success, bad_request, conflict, created, not_found, validate_request, unprocessable_entity | ||
|
||
|
||
app = Flask(__name__) | ||
user_endpoint = Blueprint("user_endpoint", __name__) | ||
|
||
brngylni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@user_endpoint.route("/user", methods=["POST"]) | ||
@validate_request | ||
def create_user(): | ||
"""Used for creating a new user by sending a post request to /user/ path. | ||
Request Body: | ||
username: Username of the user | ||
""" | ||
session = db.Session() | ||
user, is_created = get_or_create(session, User, username=request.json['username']) | ||
if not is_created: | ||
return conflict({'message': 'User Already Exists'}) | ||
else: | ||
return created({'message': 'Created', 'uuid': user.id}) | ||
|
||
|
||
@user_endpoint.route("/user/search", methods=["GET"]) | ||
@validate_request | ||
def get_user(): | ||
"""Used for retrieving a user by sending a get request to /user/search path. | ||
Request Body: | ||
username: Username of the user | ||
""" | ||
session = db.Session() | ||
users = session.query(User).filter(User.username.like(request.json['username'])).all() | ||
brngylni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if users is None or users == []: | ||
return not_found() | ||
else: | ||
return success({'user_list': users}) | ||
|
||
|
||
@user_endpoint.route("/user", methods=["GET"]) | ||
@validate_request | ||
def lookup_user(): | ||
brngylni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Used for searching a user by sending a get request to /user/ path. | ||
Request Body: | ||
username: Username of the user | ||
""" | ||
session = db.Session() | ||
|
||
user = session.query(User).filter(User.username == request.json['username']).first() | ||
gridhead marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if user is None: | ||
return not_found() | ||
else: | ||
return success({'uuid': user.id, 'username': user.username}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
from .config import get_config | ||
from .config.defaults import LOGGER_CONFIG | ||
from logging.config import dictConfig | ||
from .endpoints.user import user_endpoint | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ref. #24 (comment) |
||
from webhook_to_fedora_messaging.exceptions import ConfigError | ||
import logging | ||
|
||
|
@@ -22,7 +23,6 @@ def create_app(): | |
main = Flask( | ||
"webhook_to_fedora_messaging" | ||
) | ||
|
||
# First attempt loading the defaults from the Defaults object | ||
main.config.from_object( | ||
"webhook_to_fedora_messaging.config.defaults.Defaults" | ||
|
@@ -39,5 +39,6 @@ def create_app(): | |
main.config.from_mapping(confdata) | ||
db.init_app(main) | ||
dictConfig(confdata["logsconf"]) | ||
|
||
main.register_blueprint(user_endpoint) | ||
|
||
return main |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref. #24 (comment)