feat(relations): update issue pull linking to use IssuePullLinkDto and adjust OpenAPI schema
ZhenYi committed
This change is very large, so some diffs are not shown. Clone the repository to see the full change.
Modified lib/pulls/src/handlers/relations/list_issue_pulls.rs lib/pulls/src/handlers/relations/list_issue_pulls.rs +3 −3 View lib/pulls/src/handlers/relations/list_issue_pulls.rs
@@ -5,7 +5,7 @@
55
66use crate::errors::ApiError;
77use crate::handlers::relations::resolve_issue;
8use crate::services::pulls::PullDto;
8use crate::services::relations::IssuePullLinkDto;
99use crate::services::service::PullService;
1010
1111#[utoipa::path(
@@ -15,14 +15,14 @@
1515 description = "列出与该工单关联的合并请求,私有仓库仅在调用者可见时返回。",
1616 params(IssuePath),
1717 responses(
18 (status = 200, description = "linked pull requests", body = AppResponseData<Vec<PullDto>>)
18 (status = 200, description = "linked pull requests", body = AppResponseData<Vec<IssuePullLinkDto>>)
1919 )
2020)]
2121pub async fn list_issue_pulls(
2222 State(service): State<PullService>,
2323 session: Session,
2424 Path(path): Path<IssuePath>,
25) -> Result<AppResponseData<Vec<PullDto>>, ApiError> {
25) -> Result<AppResponseData<Vec<IssuePullLinkDto>>, ApiError> {
2626 let (space_id, _, issue_id) = resolve_issue(&service, &session, &path).await?;
2727 let pulls = service.list_linked_pulls(issue_id, space_id).await?;
2828 Ok(AppResponseData::ok(pulls))
Modified lib/pulls/src/services/relations.rs lib/pulls/src/services/relations.rs +22 −4 View lib/pulls/src/services/relations.rs
@@ -4,7 +4,8 @@
44use sea_orm::{
55 ActiveModelTrait, ActiveValue::Set, ColumnTrait, EntityTrait, QueryFilter, QueryOrder,
66};
7use serde::Deserialize;
7use serde::{Deserialize, Serialize};
8use std::collections::HashMap;
89use time::OffsetDateTime;
910use utoipa::ToSchema;
1011use uuid::Uuid;
@@ -19,6 +20,15 @@
1920 pub pull_ref: String,
2021}
2122
23#[derive(Debug, Clone, Serialize, ToSchema)]
24pub struct IssuePullLinkDto {
25 /// 关联行主键(issue_relation_pull.id),解除关联时作为路径参数回传。
26 pub relation_id: Uuid,
27 /// 建立关联的时间。
28 pub linked_at: OffsetDateTime,
29 pub pull: PullDto,
30}
31
2232impl PullService {
2333 /// 关联/解绑工单时必须对目标 PR 所在仓库有写权限,且工单与仓库同属一个空间。
2434 pub async fn link_issue(
@@ -70,7 +80,7 @@
7080 &self,
7181 issue_id: Uuid,
7282 space_id: Uuid,
73 ) -> Result<Vec<PullDto>, PullError> {
83 ) -> Result<Vec<IssuePullLinkDto>, PullError> {
7484 let links = issue_relation_pull::Entity::find()
7585 .filter(issue_relation_pull::Column::IssueId.eq(issue_id))
7686 .order_by_asc(issue_relation_pull::Column::CreatedAt)
@@ -101,9 +111,17 @@
101111 }
102112 }
103113 let users = self.pull_users(&visible).await?;
104 Ok(visible
114 let by_id: HashMap<Uuid, &pull_requests::Model> =
115 visible.iter().map(|row| (row.id, row)).collect();
116 Ok(links
105117 .iter()
106 .map(|row| PullService::dto(row, &users))
118 .filter_map(|link| {
119 by_id.get(&link.pull_request_id).map(|row| IssuePullLinkDto {
120 relation_id: link.id,
121 linked_at: link.created_at,
122 pull: PullService::dto(row, &users),
123 })
124 })
107125 .collect())
108126 }
109127}
Modified lib/pulls/src/openapi.rs lib/pulls/src/openapi.rs +1 −0 View lib/pulls/src/openapi.rs
@@ -68,6 +68,7 @@
6868 AppResponseData<Vec<crate::services::reviewers::PullReviewerDto>>,
6969 AppResponseData<Vec<issues::services::labels::LabelDto>>,
7070 AppResponseData<Vec<crate::services::assignees::PullAssigneeDto>>,
71 AppResponseData<Vec<crate::services::relations::IssuePullLinkDto>>,
7172 AppResponseData<crate::services::checks::PullChecksDto>,
7273 AppResponseData<crate::services::checks::PullGateDto>,
7374 AppResponseData<crate::services::inbox::InboxPage>,
Modified openapi.json openapi.json View openapi.json
Diff too large to display.