-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-4: Using python-inject to inject the UserRepository
- Loading branch information
1 parent
9dac19f
commit 902a47a
Showing
8 changed files
with
58 additions
and
35 deletions.
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
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
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 |
---|---|---|
@@ -1,20 +1,21 @@ | ||
from flask import Blueprint, Response, current_app, request | ||
import inject | ||
from flask import Blueprint, Response, request | ||
|
||
from schemes.users import User, UserRepository | ||
|
||
bp = Blueprint("api", __name__) | ||
|
||
|
||
@bp.route("/users", methods=["POST"]) | ||
def add_user() -> Response: | ||
@inject.autoparams() | ||
def add_user(users: UserRepository) -> Response: | ||
user = User(request.get_json()["email"]) | ||
users: UserRepository = current_app.extensions["users"] | ||
users.add(user) | ||
return Response(status=201) | ||
|
||
|
||
@bp.route("/users", methods=["DELETE"]) | ||
def clear_users() -> Response: | ||
users: UserRepository = current_app.extensions["users"] | ||
@inject.autoparams() | ||
def clear_users(users: UserRepository) -> Response: | ||
users.clear() | ||
return Response(status=204) |
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
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
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
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
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