Refactoring the history tab of the requirements details
This commit is contained in:
@@ -13,6 +13,7 @@ from src.models import (
|
||||
ValidationStatusResponse, ValidationHistoryResponse, ValidationCreateRequest,
|
||||
RelationshipTypeResponse, RelationshipTypeCreateRequest, RelationshipTypeUpdateRequest,
|
||||
RequirementLinkResponse, RequirementLinkCreateRequest, RequirementSearchResult,
|
||||
RequirementLinkHistoryResponse, RequirementGroupHistoryResponse, CurrentRequirementGroupResponse,
|
||||
RoleResponse, ProjectMemberResponse, UserRoleUpdateRequest, ROLE_DISPLAY_NAMES,
|
||||
CommentResponse, CommentReplyResponse, CommentCreateRequest, ReplyCreateRequest,
|
||||
RequirementStatusResponse, DeletedRequirementResponse
|
||||
@@ -1600,6 +1601,117 @@ async def delete_requirement_link(
|
||||
await db.commit()
|
||||
|
||||
|
||||
@app.get("/api/requirements/{requirement_id}/links/history", response_model=List[RequirementLinkHistoryResponse])
|
||||
async def get_requirement_link_history(
|
||||
requirement_id: int,
|
||||
request: Request,
|
||||
db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
Get the link history for a requirement (deleted/changed links).
|
||||
Returns all historical links where this requirement was source or target.
|
||||
|
||||
Args:
|
||||
requirement_id: The requirement to get link history for
|
||||
|
||||
Returns:
|
||||
List of historical links with relationship type snapshots and requirement info.
|
||||
"""
|
||||
user = await _get_current_user_db(request, db)
|
||||
|
||||
# Check if requirement exists
|
||||
req_repo = RequirementRepository(db)
|
||||
requirement = await req_repo.get_by_id(requirement_id)
|
||||
if not requirement:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=f"Requirement with id {requirement_id} not found"
|
||||
)
|
||||
|
||||
# Verify user is a member of the requirement's project
|
||||
await _verify_project_membership(requirement.project_id, user.id, db)
|
||||
|
||||
# Get link history
|
||||
link_repo = RequirementLinkRepository(db)
|
||||
history = await link_repo.get_history_by_requirement_id(requirement_id)
|
||||
|
||||
return [RequirementLinkHistoryResponse(**h) for h in history]
|
||||
|
||||
|
||||
@app.get("/api/requirements/{requirement_id}/groups/history", response_model=List[RequirementGroupHistoryResponse])
|
||||
async def get_requirement_group_history(
|
||||
requirement_id: int,
|
||||
request: Request,
|
||||
db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
Get the group association history for a requirement (removed groups).
|
||||
Returns all historical group associations for this requirement.
|
||||
|
||||
Args:
|
||||
requirement_id: The requirement to get group history for
|
||||
|
||||
Returns:
|
||||
List of historical group associations with group name/color snapshots.
|
||||
"""
|
||||
user = await _get_current_user_db(request, db)
|
||||
|
||||
# Check if requirement exists
|
||||
req_repo = RequirementRepository(db)
|
||||
requirement = await req_repo.get_by_id(requirement_id)
|
||||
if not requirement:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=f"Requirement with id {requirement_id} not found"
|
||||
)
|
||||
|
||||
# Verify user is a member of the requirement's project
|
||||
await _verify_project_membership(requirement.project_id, user.id, db)
|
||||
|
||||
# Get group history
|
||||
group_repo = GroupRepository(db)
|
||||
history = await group_repo.get_group_history_by_requirement_id(requirement_id)
|
||||
|
||||
return [RequirementGroupHistoryResponse(**h) for h in history]
|
||||
|
||||
|
||||
@app.get("/api/requirements/{requirement_id}/groups/current", response_model=List[CurrentRequirementGroupResponse])
|
||||
async def get_requirement_current_groups(
|
||||
requirement_id: int,
|
||||
request: Request,
|
||||
db: AsyncSession = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
Get the current groups for a requirement with their association timestamps.
|
||||
Returns all current group associations with when they were added.
|
||||
|
||||
Args:
|
||||
requirement_id: The requirement to get current groups for
|
||||
|
||||
Returns:
|
||||
List of current group associations with group name/color and created_at timestamp.
|
||||
"""
|
||||
user = await _get_current_user_db(request, db)
|
||||
|
||||
# Check if requirement exists
|
||||
req_repo = RequirementRepository(db)
|
||||
requirement = await req_repo.get_by_id(requirement_id)
|
||||
if not requirement:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=f"Requirement with id {requirement_id} not found"
|
||||
)
|
||||
|
||||
# Verify user is a member of the requirement's project
|
||||
await _verify_project_membership(requirement.project_id, user.id, db)
|
||||
|
||||
# Get current groups
|
||||
group_repo = GroupRepository(db)
|
||||
groups = await group_repo.get_current_groups_by_requirement_id(requirement_id)
|
||||
|
||||
return [CurrentRequirementGroupResponse(**g) for g in groups]
|
||||
|
||||
|
||||
# ===========================================
|
||||
# Comment Endpoints
|
||||
# ===========================================
|
||||
|
||||
Reference in New Issue
Block a user