Skip to content

Commit

Permalink
fix: some errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Angel-Dijoux committed Jan 4, 2024
1 parent 8e18064 commit 32e4091
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def create_app(environment=None):
spec=get_swagger_api_spec(config=config, plugins=plugins),
definitions=schemas,
)
Swagger(app, config=swagger_config, template=template, parse=True)
Swagger(app, config=swagger_config, template=template)

app.after_request(after_request)
register_error_handlers(app)
Expand Down
10 changes: 5 additions & 5 deletions src/blueprints/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def login() -> Tuple[Response, int] | HTTPException:
email = data.get("email")
password = data.get("password")

user = User.query.filter_by(email=email).first()
user = db.session.query(User).filter_by(email=email).first()

if user:
# Verify if password check with password in database
Expand Down Expand Up @@ -119,7 +119,7 @@ def login() -> Tuple[Response, int] | HTTPException:
def me() -> Tuple[Response, int]:
user_id = get_jwt_identity()

user = User.query.filter_by(id=user_id).first()
user = db.session.query(User).filter_by(id=user_id).first()

return (
jsonify(user),
Expand Down Expand Up @@ -148,7 +148,7 @@ def refresh_token() -> Tuple[Response, int]:
def edit_user() -> Tuple[Response, int] | HTTPException:
user_id = get_jwt_identity()

user = User.query.filter_by(id=user_id).first()
user = db.session.query(User).filter_by(id=user_id).first()

data = request.json

Expand Down Expand Up @@ -212,7 +212,7 @@ def edit_user() -> Tuple[Response, int] | HTTPException:


def remove_favoris(user_id: int) -> None:
favoris = UserFavori.query.filter(UserFavori.user_id == user_id).all()
favoris = db.session.query(UserFavori).filter(UserFavori.user_id == user_id).all()
[db.session.delete(f) for f in favoris]
db.session.commit()

Expand All @@ -222,7 +222,7 @@ def remove_favoris(user_id: int) -> None:
@swag_from("../docs/auth/remove.yaml")
def remove_user() -> Tuple[Response, int] | HTTPException:
user_id = get_jwt_identity()
user = User.query.filter_by(id=user_id).first()
user = db.session.query(User).filter_by(id=user_id).first()

if not user:
abort(HTTP_404_NOT_FOUND, "User not found")
Expand Down
3 changes: 2 additions & 1 deletion src/business_logic/formation/get_formation_by_url.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from src.models.formation import Formation
from src import db


def get_formation_by_url(url: str) -> Formation | None:
return Formation.query.filter(Formation.url == url).first()
return db.session.query(Formation).filter(Formation.url == url).first()
3 changes: 1 addition & 2 deletions src/config/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ def get_swagger_api_spec(
plugins=plugins,
info=info,
)
api_key_scheme = {"type": "apiKey", "in": "header", "name": "X-API-Key"}
api_key_scheme = {"type": "apiKey", "in": "header", "name": "Authorization"}
spec.components.security_scheme("Bearer", api_key_scheme)
return spec


swagger_config = {
"host": ["localhost:5005" if is_dev() else "api.nc-elki.v6.army"],
"basePath": "/api/v1",
"schemes": ["http" if is_dev() else "https"],
"headers": [
("Access-Control-Allow-Origin", "*"),
Expand Down
22 changes: 20 additions & 2 deletions src/docs/favoris/postFavoris.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,30 @@ post:
in: body
required: true
schema:
$ref: "#/definitions/Formation"
allOf:
- $ref: "#/definitions/Formation"
- type: object
properties:
updated_at:
created_at:
id:
responses:
201:
description: L'url est bien enregistrée.
schema:
$ref: "#/definitions/Formation"
type: object
properties:
created_at:
type: string
format: date-time
formation_id:
type: string
format: uuid
updated_at:
type: string
format: date-time
user_id:
type: integer

400:
description: L'url n'est pas valide.
Expand Down
1 change: 1 addition & 0 deletions src/models/schemas/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class UserSchema(SQLAlchemyAutoSchema):
class Meta:
model = User
exclude = ("created_at", "updated_at", "password")


class FormationSchema(SQLAlchemyAutoSchema):
Expand Down

0 comments on commit 32e4091

Please sign in to comment.