i add tow fields in depertement
Browse files- app/models/__pycache__/department.cpython-313.pyc +0 -0
- app/models/department.py +2 -0
- app/schemas/__pycache__/admin.cpython-313.pyc +0 -0
- app/schemas/__pycache__/department.cpython-313.pyc +0 -0
- app/schemas/admin.py +2 -0
- app/schemas/department.py +2 -0
- app/services/__pycache__/admin_service.cpython-313.pyc +0 -0
- app/services/admin_service.py +8 -0
- tests/__pycache__/conftest.cpython-313-pytest-8.4.2.pyc +0 -0
- tests/__pycache__/test_admin.cpython-313-pytest-8.4.2.pyc +0 -0
- tests/__pycache__/test_auth.cpython-313-pytest-8.4.2.pyc +0 -0
- tests/test_admin.py +32 -0
app/models/__pycache__/department.cpython-313.pyc
CHANGED
|
Binary files a/app/models/__pycache__/department.cpython-313.pyc and b/app/models/__pycache__/department.cpython-313.pyc differ
|
|
|
app/models/department.py
CHANGED
|
@@ -12,5 +12,7 @@ class Department(Base):
|
|
| 12 |
code = Column(String(20), unique=True, nullable=False)
|
| 13 |
description = Column(Text, nullable=True)
|
| 14 |
keywords = Column(Text, nullable=True)
|
|
|
|
|
|
|
| 15 |
is_active = Column(Boolean, default=True, nullable=False)
|
| 16 |
users = relationship("User", back_populates="department")
|
|
|
|
| 12 |
code = Column(String(20), unique=True, nullable=False)
|
| 13 |
description = Column(Text, nullable=True)
|
| 14 |
keywords = Column(Text, nullable=True)
|
| 15 |
+
user_id = Column(Integer, nullable=True)
|
| 16 |
+
query = Column(Text, nullable=True)
|
| 17 |
is_active = Column(Boolean, default=True, nullable=False)
|
| 18 |
users = relationship("User", back_populates="department")
|
app/schemas/__pycache__/admin.cpython-313.pyc
CHANGED
|
Binary files a/app/schemas/__pycache__/admin.cpython-313.pyc and b/app/schemas/__pycache__/admin.cpython-313.pyc differ
|
|
|
app/schemas/__pycache__/department.cpython-313.pyc
CHANGED
|
Binary files a/app/schemas/__pycache__/department.cpython-313.pyc and b/app/schemas/__pycache__/department.cpython-313.pyc differ
|
|
|
app/schemas/admin.py
CHANGED
|
@@ -6,6 +6,8 @@ class AdminDepartmentUpdate(BaseModel):
|
|
| 6 |
code: str | None = Field(default=None, max_length=20)
|
| 7 |
description: str | None = None
|
| 8 |
keywords: str | None = None
|
|
|
|
|
|
|
| 9 |
is_active: bool | None = None
|
| 10 |
|
| 11 |
|
|
|
|
| 6 |
code: str | None = Field(default=None, max_length=20)
|
| 7 |
description: str | None = None
|
| 8 |
keywords: str | None = None
|
| 9 |
+
user_id: int | None = None
|
| 10 |
+
query: str | None = None
|
| 11 |
is_active: bool | None = None
|
| 12 |
|
| 13 |
|
app/schemas/department.py
CHANGED
|
@@ -6,6 +6,8 @@ class DepartmentCreate(BaseModel):
|
|
| 6 |
code: str
|
| 7 |
description: str | None = None
|
| 8 |
keywords: str | None = None
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
class DepartmentResponse(DepartmentCreate):
|
|
|
|
| 6 |
code: str
|
| 7 |
description: str | None = None
|
| 8 |
keywords: str | None = None
|
| 9 |
+
user_id: int | None = None
|
| 10 |
+
query: str | None = None
|
| 11 |
|
| 12 |
|
| 13 |
class DepartmentResponse(DepartmentCreate):
|
app/services/__pycache__/admin_service.cpython-313.pyc
CHANGED
|
Binary files a/app/services/__pycache__/admin_service.cpython-313.pyc and b/app/services/__pycache__/admin_service.cpython-313.pyc differ
|
|
|
app/services/admin_service.py
CHANGED
|
@@ -40,6 +40,8 @@ def create_department(
|
|
| 40 |
code: str,
|
| 41 |
description: str | None = None,
|
| 42 |
keywords: str | None = None,
|
|
|
|
|
|
|
| 43 |
) -> Department:
|
| 44 |
if _department_exists_with_name_or_code(db, name=name):
|
| 45 |
raise ValueError("Department name is already registered")
|
|
@@ -51,6 +53,8 @@ def create_department(
|
|
| 51 |
code=code,
|
| 52 |
description=description,
|
| 53 |
keywords=keywords,
|
|
|
|
|
|
|
| 54 |
)
|
| 55 |
db.add(department)
|
| 56 |
db.commit()
|
|
@@ -89,6 +93,10 @@ def update_department(
|
|
| 89 |
department.description = payload.description
|
| 90 |
if payload.keywords is not None:
|
| 91 |
department.keywords = payload.keywords
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
if payload.is_active is not None:
|
| 93 |
department.is_active = payload.is_active
|
| 94 |
|
|
|
|
| 40 |
code: str,
|
| 41 |
description: str | None = None,
|
| 42 |
keywords: str | None = None,
|
| 43 |
+
user_id: int | None = None,
|
| 44 |
+
query: str | None = None,
|
| 45 |
) -> Department:
|
| 46 |
if _department_exists_with_name_or_code(db, name=name):
|
| 47 |
raise ValueError("Department name is already registered")
|
|
|
|
| 53 |
code=code,
|
| 54 |
description=description,
|
| 55 |
keywords=keywords,
|
| 56 |
+
user_id=user_id,
|
| 57 |
+
query=query,
|
| 58 |
)
|
| 59 |
db.add(department)
|
| 60 |
db.commit()
|
|
|
|
| 93 |
department.description = payload.description
|
| 94 |
if payload.keywords is not None:
|
| 95 |
department.keywords = payload.keywords
|
| 96 |
+
if payload.user_id is not None:
|
| 97 |
+
department.user_id = payload.user_id
|
| 98 |
+
if payload.query is not None:
|
| 99 |
+
department.query = payload.query
|
| 100 |
if payload.is_active is not None:
|
| 101 |
department.is_active = payload.is_active
|
| 102 |
|
tests/__pycache__/conftest.cpython-313-pytest-8.4.2.pyc
CHANGED
|
Binary files a/tests/__pycache__/conftest.cpython-313-pytest-8.4.2.pyc and b/tests/__pycache__/conftest.cpython-313-pytest-8.4.2.pyc differ
|
|
|
tests/__pycache__/test_admin.cpython-313-pytest-8.4.2.pyc
CHANGED
|
Binary files a/tests/__pycache__/test_admin.cpython-313-pytest-8.4.2.pyc and b/tests/__pycache__/test_admin.cpython-313-pytest-8.4.2.pyc differ
|
|
|
tests/__pycache__/test_auth.cpython-313-pytest-8.4.2.pyc
CHANGED
|
Binary files a/tests/__pycache__/test_auth.cpython-313-pytest-8.4.2.pyc and b/tests/__pycache__/test_auth.cpython-313-pytest-8.4.2.pyc differ
|
|
|
tests/test_admin.py
CHANGED
|
@@ -70,6 +70,38 @@ def test_admin_can_create_update_and_deactivate_department():
|
|
| 70 |
Base.metadata.drop_all(bind=engine)
|
| 71 |
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
def test_admin_can_list_and_update_user_department():
|
| 74 |
engine, db = _make_session()
|
| 75 |
try:
|
|
|
|
| 70 |
Base.metadata.drop_all(bind=engine)
|
| 71 |
|
| 72 |
|
| 73 |
+
def test_admin_can_store_user_and_query_on_department():
|
| 74 |
+
engine, db = _make_session()
|
| 75 |
+
try:
|
| 76 |
+
created = create_department(
|
| 77 |
+
db,
|
| 78 |
+
name="Student Support",
|
| 79 |
+
code="SSUP",
|
| 80 |
+
description="Student support desk",
|
| 81 |
+
keywords="support, help",
|
| 82 |
+
user_id=19,
|
| 83 |
+
query="Initial student support request",
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
assert created.user_id == 19
|
| 87 |
+
assert created.query == "Initial student support request"
|
| 88 |
+
|
| 89 |
+
updated = update_department(
|
| 90 |
+
db,
|
| 91 |
+
department_id=created.id,
|
| 92 |
+
payload=AdminDepartmentUpdate(
|
| 93 |
+
query="I need help with my fee payment",
|
| 94 |
+
is_active=True,
|
| 95 |
+
),
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
assert updated.query == "I need help with my fee payment"
|
| 99 |
+
assert updated.user_id == 19
|
| 100 |
+
finally:
|
| 101 |
+
db.close()
|
| 102 |
+
Base.metadata.drop_all(bind=engine)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
def test_admin_can_list_and_update_user_department():
|
| 106 |
engine, db = _make_session()
|
| 107 |
try:
|