Skip to content

Commit

Permalink
- added extra checks
Browse files Browse the repository at this point in the history
- typing.List -> list
- enums & str
- updated endpoints
  • Loading branch information
HardMax71 committed Aug 28, 2024
1 parent 11d551d commit 54fd3bc
Show file tree
Hide file tree
Showing 34 changed files with 149 additions and 185 deletions.
2 changes: 1 addition & 1 deletion desktop_app/src/services/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .background_tasks import BackgroundTaskManager
from .authentication import AuthenticationService
from .offline_manager import OfflineManager
from .update_manager import UpdateManager
34 changes: 0 additions & 34 deletions desktop_app/src/services/background_tasks.py

This file was deleted.

2 changes: 1 addition & 1 deletion desktop_app/src/ui/icon_path_enum.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum


class IconPath(Enum):
class IconPath(str, Enum):
REFRESH: str = "icons:refresh.png" # ":" stuff is a Qt resource path
BARCODE: str = "icons:barcode.png"
SAVE: str = "icons:save.png"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ def init_ui(self):

# Set layout proportions
main_layout.setStretch(0, 1) # Left side
main_layout.setStretch(1, 2) # Right side
main_layout.setStretch(1, 2) # Right side
17 changes: 15 additions & 2 deletions desktop_app/src/ui/views/user_mgmt/user_dialog.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from PySide6.QtWidgets import (QVBoxLayout, QDialog, QLineEdit, QMessageBox, QComboBox, QDialogButtonBox, QCheckBox,
QFormLayout)
from PySide6.QtGui import QIcon, QAction
from PySide6.QtWidgets import (QVBoxLayout, QDialog, QLineEdit, QComboBox, QDialogButtonBox, QCheckBox,
QFormLayout, QMessageBox)

from public_api.api import UsersAPI, RolesAPI
from public_api.shared_schemas import UserSanitized, UserCreate, UserUpdate
Expand All @@ -26,6 +27,13 @@ def init_ui(self):
self.role_combo = QComboBox()
self.is_active_checkbox = QCheckBox()

# Create and add the show password action
show_password_icon = QIcon("icons:eye_view.png")
self.show_password_action = QAction(show_password_icon, "Show password", self)
self.show_password_action.setCheckable(True)
self.password_input.addAction(self.show_password_action, QLineEdit.TrailingPosition)
self.show_password_action.toggled.connect(self.toggle_password_visibility)

form_layout.addRow("Username:", self.username_input)
form_layout.addRow("Email:", self.email_input)
form_layout.addRow("Password:", self.password_input)
Expand All @@ -43,6 +51,11 @@ def init_ui(self):
if self.user:
self.populate_data()

def toggle_password_visibility(self, show):
self.password_input.setEchoMode(QLineEdit.Normal if show else QLineEdit.Password)
icon = QIcon("icons:eye_hide.png" if show else "icons:eye_view.png")
self.show_password_action.setIcon(icon)

def load_roles(self):
all_roles = self.roles_api.get_all_roles()
for role in all_roles:
Expand Down
4 changes: 2 additions & 2 deletions public_api/permissions/permission_enums.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from enum import Enum


class PermissionType(Enum):
class PermissionType(str, Enum):
READ = "read"
WRITE = "write"
EDIT = "edit"
DELETE = "delete"


class PermissionName(Enum):
class PermissionName(str, Enum):
ASSET = "Asset"
ASSET_MAINTENANCE = "Asset Maintenance"
DASHBOARD = "Dashboard"
Expand Down
1 change: 1 addition & 0 deletions public_api/shared_schemas/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class OrderStatus(str, Enum):
SHIPPED = "Shipped"
DELIVERED = "Delivered"
CANCELLED = "Cancelled"
BACKORDER = "Backorder"


class OrderItemBase(BaseModel):
Expand Down
5 changes: 2 additions & 3 deletions server/app/api/v1/endpoints/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from public_api import shared_schemas
from public_api.permissions import PermissionName, PermissionType
from public_api.shared_schemas import AssetMaintenanceFilter
from .... import crud, models
from ....api import deps

Expand All @@ -33,7 +32,7 @@ def read_assets(
):
assets = crud.asset.get_multi_with_filter(db, skip=skip, limit=limit, filter_params=asset_filter)
total = len(assets)
return {"assets": assets, "total": total}
return shared_schemas.AssetWithMaintenanceList(assets=assets, total=total)


@router.get("/types", response_model=list[str])
Expand Down Expand Up @@ -127,7 +126,7 @@ def read_asset_maintenance_history(
limit: int = 100,
current_user: models.User = Depends(deps.has_permission(PermissionName.ASSET_MAINTENANCE, PermissionType.READ))
):
filter_params = AssetMaintenanceFilter(asset_id=asset_id)
filter_params = shared_schemas.AssetMaintenanceFilter(asset_id=asset_id)
return crud.asset_maintenance.get_multi_with_filter(db, skip=skip, limit=limit, filter_params=filter_params)


Expand Down
13 changes: 6 additions & 7 deletions server/app/api/v1/endpoints/audit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# /server/app/api/v1/endpoints/audit.py
from datetime import datetime
from typing import List

from fastapi import APIRouter, Depends, HTTPException, Query, Path
from sqlalchemy.orm import Session
Expand All @@ -21,7 +20,7 @@ def create_audit_log(
return crud.audit_log.create(db=db, obj_in=log)


@router.get("/logs", response_model=List[shared_schemas.AuditLogWithUser])
@router.get("/logs", response_model=list[shared_schemas.AuditLogWithUser])
def read_audit_logs(
db: Session = Depends(deps.get_db),
skip: int = 0,
Expand Down Expand Up @@ -54,7 +53,7 @@ def get_audit_summary(
return crud.audit_log.get_summary(db, date_from=date_from, date_to=date_to)


@router.get("/logs/user/{user_id}", response_model=List[shared_schemas.AuditLog])
@router.get("/logs/user/{user_id}", response_model=list[shared_schemas.AuditLog])
def get_user_audit_logs(
user_id: int = Path(..., title="The ID of the user to get audit logs for"),
db: Session = Depends(deps.get_db),
Expand All @@ -66,7 +65,7 @@ def get_user_audit_logs(
return crud.audit_log.get_multi_with_filter(db, skip=skip, limit=limit, filter_params=filter_params)


@router.get("/logs/table/{table_name}", response_model=List[shared_schemas.AuditLog])
@router.get("/logs/table/{table_name}", response_model=list[shared_schemas.AuditLog])
def get_table_audit_logs(
table_name: str = Path(..., title="The name of the table to get audit logs for"),
db: Session = Depends(deps.get_db),
Expand All @@ -78,7 +77,7 @@ def get_table_audit_logs(
return crud.audit_log.get_multi_with_filter(db, skip=skip, limit=limit, filter_params=filter_params)


@router.get("/logs/record/{table_name}/{record_id}", response_model=List[shared_schemas.AuditLog])
@router.get("/logs/record/{table_name}/{record_id}", response_model=list[shared_schemas.AuditLog])
def get_record_audit_logs(
table_name: str = Path(..., title="The name of the table"),
record_id: int = Path(..., title="The ID of the record to get audit logs for"),
Expand All @@ -103,15 +102,15 @@ def export_audit_logs(
return shared_schemas.AuditLogExport(logs=logs, export_timestamp=int(datetime.now().timestamp()))


@router.get("/logs/actions", response_model=List[str])
@router.get("/logs/actions", response_model=list[str])
def get_audit_log_actions(
db: Session = Depends(deps.get_db),
current_user: models.User = Depends(deps.get_current_active_user)
):
return crud.audit_log.get_distinct_actions(db)


@router.get("/logs/tables", response_model=List[str])
@router.get("/logs/tables", response_model=list[str])
def get_audited_tables(
db: Session = Depends(deps.get_db),
current_user: models.User = Depends(deps.get_current_active_user)
Expand Down
3 changes: 1 addition & 2 deletions server/app/api/v1/endpoints/carriers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# /server/app/api/v1/endpoints/carriers.py
from typing import List

from fastapi import APIRouter, Depends, HTTPException, Path, Body
from sqlalchemy.orm import Session
Expand All @@ -21,7 +20,7 @@ def create_carrier(
return crud.carrier.create(db=db, obj_in=carrier)


@router.get("/", response_model=List[Carrier])
@router.get("/", response_model=list[Carrier])
def read_carriers(
db: Session = Depends(deps.get_db),
skip: int = 0,
Expand Down
5 changes: 2 additions & 3 deletions server/app/api/v1/endpoints/customers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# /server/app/api/v1/endpoints/customers.py
from typing import List

from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
Expand All @@ -20,7 +19,7 @@ def create_customer(
return crud.customer.create(db=db, obj_in=customer)


@router.get("/", response_model=List[shared_schemas.Customer])
@router.get("/", response_model=list[shared_schemas.Customer])
def read_customers(
db: Session = Depends(deps.get_db),
skip: int = 0,
Expand Down Expand Up @@ -68,7 +67,7 @@ def delete_customer(
crud.customer.remove(db, id=customer_id)


@router.get("/{customer_id}/orders", response_model=List[shared_schemas.Order])
@router.get("/{customer_id}/orders", response_model=list[shared_schemas.Order])
def read_customer_orders(
customer_id: int,
db: Session = Depends(deps.get_db),
Expand Down
32 changes: 15 additions & 17 deletions server/app/api/v1/endpoints/inventory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# /server/app/api/v1/endpoints/inventory.py

from typing import List, Dict

from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy.orm import Session

Expand Down Expand Up @@ -31,7 +29,7 @@ def read_inventory(
):
items = crud.inventory.get_multi_with_products(db, skip=skip, limit=limit, filter_params=inventory_filter)
total = len(items)
return {"items": items, "total": total}
return shared_schemas.InventoryList(items=items, total=total)


@router.post("/transfer", response_model=shared_schemas.Inventory)
Expand All @@ -51,17 +49,17 @@ def get_inventory_report(
return crud.inventory.get_inventory_report(db)


@router.post("/cycle_count", response_model=List[shared_schemas.Inventory])
@router.post("/cycle_count", response_model=list[shared_schemas.Inventory])
def perform_cycle_count(
location_id: int,
counted_items: List[shared_schemas.InventoryUpdate],
counted_items: list[shared_schemas.InventoryUpdate],
db: Session = Depends(deps.get_db),
current_user: models.User = Depends(deps.get_current_active_user)
):
return crud.inventory.perform_cycle_count(db, location_id=location_id, counted_items=counted_items)


@router.get("/low_stock", response_model=List[shared_schemas.ProductWithInventory])
@router.get("/low_stock", response_model=list[shared_schemas.ProductWithInventory])
def get_low_stock_items(
threshold: int = Query(10, ge=0),
db: Session = Depends(deps.get_db),
Expand All @@ -70,15 +68,15 @@ def get_low_stock_items(
return crud.inventory.get_low_stock_items(db, threshold=threshold)


@router.get("/out_of_stock", response_model=List[shared_schemas.Product])
@router.get("/out_of_stock", response_model=list[shared_schemas.Product])
def get_out_of_stock_items(
db: Session = Depends(deps.get_db),
current_user: models.User = Depends(deps.get_current_active_user)
):
return crud.inventory.get_out_of_stock_items(db)


@router.post("/reorder", response_model=List[shared_schemas.Product])
@router.post("/reorder", response_model=list[shared_schemas.Product])
def create_reorder_list(
threshold: int = Query(10, ge=0),
db: Session = Depends(deps.get_db),
Expand All @@ -87,7 +85,7 @@ def create_reorder_list(
return crud.inventory.get_low_stock_items(db, threshold=threshold)


@router.get("/product_locations/{product_id}", response_model=List[shared_schemas.LocationWithInventory])
@router.get("/product_locations/{product_id}", response_model=list[shared_schemas.LocationWithInventory])
def get_product_locations(
product_id: int,
db: Session = Depends(deps.get_db),
Expand All @@ -96,16 +94,16 @@ def get_product_locations(
return crud.inventory.get_product_locations(db, product_id=product_id)


@router.post("/batch_update", response_model=List[shared_schemas.Inventory])
@router.post("/batch_update", response_model=list[shared_schemas.Inventory])
def batch_update_inventory(
updates: List[shared_schemas.InventoryUpdate],
updates: list[shared_schemas.InventoryUpdate],
db: Session = Depends(deps.get_db),
current_user: models.User = Depends(deps.get_current_active_user)
):
return crud.inventory.batch_update(db, updates=updates)


@router.get("/movement_history/{product_id}", response_model=List[shared_schemas.InventoryMovement])
@router.get("/movement_history/{product_id}", response_model=list[shared_schemas.InventoryMovement])
def get_inventory_movement_history(
product_id: int,
start_date: int = Query(None),
Expand Down Expand Up @@ -141,15 +139,15 @@ def perform_abc_analysis(
return crud.inventory.perform_abc_analysis(db)


@router.post("/optimize_locations", response_model=List[shared_schemas.InventoryLocationSuggestion])
@router.post("/optimize_locations", response_model=list[shared_schemas.InventoryLocationSuggestion])
def optimize_inventory_locations(
db: Session = Depends(deps.get_db),
current_user: models.User = Depends(deps.get_current_active_user)
):
return crud.inventory.optimize_locations(db)


@router.get("/expiring_soon", response_model=List[shared_schemas.ProductWithInventory])
@router.get("/expiring_soon", response_model=list[shared_schemas.ProductWithInventory])
def get_expiring_soon_inventory(
days: int = Query(30, description="Number of days to consider for expiration"),
db: Session = Depends(deps.get_db),
Expand All @@ -175,7 +173,7 @@ def get_storage_utilization(
return crud.inventory.get_storage_utilization(db)


@router.get("/forecast/{product_id}", response_model=Dict)
@router.get("/forecast/{product_id}", response_model=dict)
def get_inventory_forecast(
product_id: int,
db: Session = Depends(deps.get_db),
Expand All @@ -184,7 +182,7 @@ def get_inventory_forecast(
return crud.inventory.get_forecast_for_product_id(db, product_id=product_id)


@router.get("/trend", response_model=Dict[str, List[shared_schemas.InventoryTrendItem]])
@router.get("/trend", response_model=dict[str, list[shared_schemas.InventoryTrendItem]])
def get_inventory_trend(
db: Session = Depends(deps.get_db),
current_user: models.User = Depends(deps.get_current_active_user),
Expand All @@ -196,7 +194,7 @@ def get_inventory_trend(
return {"past": historical_items, "predictions": prediction_items}


@router.get("/reorder_suggestions", response_model=List[Dict])
@router.get("/reorder_suggestions", response_model=list[dict])
def get_reorder_suggestions(
db: Session = Depends(deps.get_db),
current_user: models.User = Depends(deps.get_current_active_user)
Expand Down
3 changes: 1 addition & 2 deletions server/app/api/v1/endpoints/locations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# /server/app/api/v1/endpoints/locations.py
from typing import List

from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
Expand All @@ -20,7 +19,7 @@ def create_location(
return crud.location.create(db=db, obj_in=location)


@router.get("/", response_model=List[shared_schemas.LocationWithInventory])
@router.get("/", response_model=list[shared_schemas.LocationWithInventory])
def read_locations(
db: Session = Depends(deps.get_db),
skip: int = 0,
Expand Down
Loading

0 comments on commit 54fd3bc

Please sign in to comment.