Refactor contact handling across backend and frontend

Replaced usage of "ContactPerson" with "Contact" for consistency across the codebase. Updated related component props, state variables, API calls, and database queries to align with the new model. Also enhanced backend functionality with stricter validations and added support for handling active pgroups in contact management.
This commit is contained in:
GotthardG
2025-01-22 16:31:08 +01:00
parent 6cde57f783
commit 382b1eaba8
24 changed files with 627 additions and 373 deletions

View File

@ -1,4 +1,4 @@
from fastapi import Depends, HTTPException, status, Query
from fastapi import Depends, HTTPException, status, Query, APIRouter
from sqlalchemy.orm import Session
from sqlalchemy import or_
from typing import List
@ -12,10 +12,11 @@ from app.schemas import (
)
from app.models import Address as AddressModel
from app.dependencies import get_db
from app.routers.protected_router import protected_router
address_router = APIRouter()
@protected_router.get("/", response_model=List[AddressSchema])
@address_router.get("/", response_model=List[AddressSchema])
async def get_return_addresses(
active_pgroup: str = Query(...),
db: Session = Depends(get_db),
@ -36,7 +37,7 @@ async def get_return_addresses(
return user_addresses
@protected_router.get("/all", response_model=List[AddressSchema])
@address_router.get("/all", response_model=List[AddressSchema])
async def get_all_addresses(
db: Session = Depends(get_db),
current_user: loginData = Depends(get_current_user),
@ -52,7 +53,7 @@ async def get_all_addresses(
return user_addresses
@protected_router.post(
@address_router.post(
"/", response_model=AddressSchema, status_code=status.HTTP_201_CREATED
)
async def create_return_address(address: AddressCreate, db: Session = Depends(get_db)):
@ -81,7 +82,7 @@ async def create_return_address(address: AddressCreate, db: Session = Depends(ge
return db_address
@protected_router.put("/{address_id}", response_model=AddressSchema)
@address_router.put("/{address_id}", response_model=AddressSchema)
async def update_return_address(
address_id: int, address: AddressUpdate, db: Session = Depends(get_db)
):
@ -140,7 +141,7 @@ async def update_return_address(
return new_address
@protected_router.delete("/{address_id}", status_code=status.HTTP_204_NO_CONTENT)
@address_router.delete("/{address_id}", status_code=status.HTTP_204_NO_CONTENT)
async def delete_return_address(address_id: int, db: Session = Depends(get_db)):
db_address = db.query(AddressModel).filter(AddressModel.id == address_id).first()
if not db_address: