Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions jupiter/src/storage/conversation_storage.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::ops::Deref;

use sea_orm::prelude::Expr;
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter};

use callisto::sea_orm_active_enums::ConvTypeEnum;
Expand Down Expand Up @@ -35,6 +36,24 @@ impl ConversationStorage {
Ok(res.id)
}

pub async fn update_comment(
&self,
comment_id: i64,
comment: Option<String>,
) -> Result<(), MegaError> {
mega_conversation::Entity::update_many()
.col_expr(mega_conversation::Column::Comment, Expr::value(comment))
.col_expr(
mega_conversation::Column::UpdatedAt,
Expr::value(chrono::Utc::now().naive_utc()),
)
.filter(mega_conversation::Column::Id.eq(comment_id))
.filter(mega_conversation::Column::ConvType.eq(ConvTypeEnum::Comment))
.exec(self.get_connection())
.await?;
Ok(())
}

pub async fn remove_conversation(&self, id: i64) -> Result<(), MegaError> {
mega_conversation::Entity::delete_by_id(id)
.exec(self.get_connection())
Expand Down
14 changes: 14 additions & 0 deletions jupiter/src/storage/issue_storage.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::ops::Deref;

use sea_orm::prelude::Expr;
use sea_orm::{
ActiveModelTrait, ColumnTrait, Condition, EntityTrait, IntoActiveModel, JoinType,
PaginatorTrait, QueryFilter, QuerySelect, RelationTrait, Set, TransactionTrait,
Expand Down Expand Up @@ -163,6 +164,19 @@ impl IssueStorage {
Ok(res)
}

pub async fn edit_title(&self, link: &str, title: &str) -> Result<(), MegaError> {
mega_issue::Entity::update_many()
.col_expr(mega_issue::Column::Title, Expr::value(title))
.col_expr(
mega_issue::Column::UpdatedAt,
Expr::value(chrono::Utc::now().naive_utc()),
)
.filter(mega_issue::Column::Link.eq(link))
.exec(self.get_connection())
.await?;
Ok(())
}

pub async fn close_issue(&self, link: &str) -> Result<(), MegaError> {
if let Some(model) = self.get_issue(link).await.unwrap() {
let mut issue = model.into_active_model();
Expand Down
25 changes: 19 additions & 6 deletions jupiter/src/storage/mr_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::ops::Deref;

use common::model::Pagination;
use sea_orm::prelude::Expr;
use sea_orm::{
ActiveModelTrait, ColumnTrait, Condition, EntityTrait, IntoActiveModel, JoinType,
PaginatorTrait, QueryFilter, QuerySelect, RelationTrait, Set,
Expand Down Expand Up @@ -146,12 +147,11 @@ impl MrStorage {
&self,
link: &str,
) -> Result<Option<(mega_mr::Model, Vec<item_assignees::Model>)>, MegaError> {
let assignees: Vec<(mega_mr::Model, Vec<item_assignees::Model>)> =
mega_mr::Entity::find()
.filter(mega_mr::Column::Link.eq(link))
.find_with_related(item_assignees::Entity)
.all(self.get_connection())
.await?;
let assignees: Vec<(mega_mr::Model, Vec<item_assignees::Model>)> = mega_mr::Entity::find()
.filter(mega_mr::Column::Link.eq(link))
.find_with_related(item_assignees::Entity)
.all(self.get_connection())
.await?;
Ok(assignees.first().cloned())
}

Expand Down Expand Up @@ -181,6 +181,19 @@ impl MrStorage {
Ok(link)
}

pub async fn edit_title(&self, link: &str, title: &str) -> Result<(), MegaError> {
mega_mr::Entity::update_many()
.col_expr(mega_mr::Column::Title, Expr::value(title))
.col_expr(
mega_mr::Column::UpdatedAt,
Expr::value(chrono::Utc::now().naive_utc()),
)
.filter(mega_mr::Column::Link.eq(link))
.exec(self.get_connection())
.await?;
Ok(())
}

pub async fn close_mr(&self, model: mega_mr::Model) -> Result<(), MegaError> {
let mut a_model = model.into_active_model();
a_model.status = Set(MergeStatusEnum::Closed);
Expand Down
52 changes: 50 additions & 2 deletions mono/src/api/conversation/conv_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use utoipa_axum::{router::OpenApiRouter, routes};

use common::model::CommonResult;

use crate::api::conversation::ReactionRequest;
use crate::api::conversation::{ContentPayload, ReactionRequest};
use crate::api::oauth::model::LoginUser;
use crate::api::MonoApiServiceState;
use crate::{api::error::ApiError, server::https_server::CONV_TAG};
Expand All @@ -16,7 +16,9 @@ pub fn routers() -> OpenApiRouter<MonoApiServiceState> {
"/conversation",
OpenApiRouter::new()
.routes(routes!(comment_reactions))
.routes(routes!(delete_comment_reaction)),
.routes(routes!(delete_comment_reaction))
.routes(routes!(delete_comment))
.routes(routes!(edit_comment)),
)
}

Expand Down Expand Up @@ -74,3 +76,49 @@ async fn delete_comment_reaction(
.await?;
Ok(Json(CommonResult::success(None)))
}

/// Delete Comment
#[utoipa::path(
delete,
params(
("comment_id", description = "A numeric ID representing a comment"),
),
path = "/{comment_id}",
responses(
(status = 200, body = CommonResult<String>, content_type = "application/json")
),
tag = CONV_TAG
)]
async fn delete_comment(
Path(comment_id): Path<i64>,
state: State<MonoApiServiceState>,
) -> Result<Json<CommonResult<String>>, ApiError> {
state.conv_stg().remove_conversation(comment_id).await?;
Ok(Json(CommonResult::success(None)))
}

/// Edit comment
#[utoipa::path(
post,
params(
("comment_id", description = "A numeric ID representing a comment"),
),
path = "/{comment_id}",
request_body = ContentPayload,
responses(
(status = 200, body = CommonResult<String>, content_type = "application/json")
),
tag = CONV_TAG
)]
async fn edit_comment(
_: LoginUser,
Path(comment_id): Path<i64>,
state: State<MonoApiServiceState>,
Json(payload): Json<ContentPayload>,
) -> Result<Json<CommonResult<String>>, ApiError> {
state
.conv_stg()
.update_comment(comment_id, Some(payload.content))
.await?;
Ok(Json(CommonResult::success(None)))
}
2 changes: 1 addition & 1 deletion mono/src/api/conversation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub struct ReactionItem {
}

#[derive(Deserialize, ToSchema)]
pub struct SaveCommentRequest {
pub struct ContentPayload {
pub content: String,
}

Expand Down
66 changes: 37 additions & 29 deletions mono/src/api/issue/issue_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use common::model::{CommonPage, CommonResult, PageParams};
use jupiter::service::issue_service::IssueService;

use crate::api::{
api_common::model::ListPayload, conversation::SaveCommentRequest, label::LabelUpdatePayload,
api_common::model::ListPayload, conversation::ContentPayload, label::LabelUpdatePayload,
};
use crate::api::{
api_common::{self, model::AssigneeUpdatePayload},
Expand All @@ -31,9 +31,9 @@ pub fn routers() -> OpenApiRouter<MonoApiServiceState> {
.routes(routes!(reopen_issue))
.routes(routes!(issue_detail))
.routes(routes!(save_comment))
.routes(routes!(delete_comment))
.routes(routes!(labels))
.routes(routes!(assignees)),
.routes(routes!(assignees))
.routes(routes!(edit_title)),
)
}

Expand Down Expand Up @@ -79,7 +79,10 @@ async fn issue_detail(
state: State<MonoApiServiceState>,
) -> Result<Json<CommonResult<IssueDetailRes>>, ApiError> {
let issue_service: IssueService = state.storage.issue_service.clone();
let issue_details: IssueDetailRes = issue_service.get_issue_details(&link, user.username).await?.into();
let issue_details: IssueDetailRes = issue_service
.get_issue_details(&link, user.username)
.await?
.into();
Ok(Json(CommonResult::success(Some(issue_details))))
}

Expand Down Expand Up @@ -182,7 +185,7 @@ async fn reopen_issue(
("link", description = "Issue link"),
),
path = "/{link}/comment",
request_body = SaveCommentRequest,
request_body = ContentPayload,
responses(
(status = 200, body = CommonResult<String>, content_type = "application/json")
),
Expand All @@ -192,7 +195,7 @@ async fn save_comment(
user: LoginUser,
Path(link): Path<String>,
state: State<MonoApiServiceState>,
Json(payload): Json<SaveCommentRequest>,
Json(payload): Json<ContentPayload>,
) -> Result<Json<CommonResult<String>>, ApiError> {
state
.conv_stg()
Expand All @@ -206,28 +209,7 @@ async fn save_comment(
Ok(Json(CommonResult::success(None)))
}

/// Delete Issue Comment
#[utoipa::path(
delete,
params(
("id", description = "Conversation id"),
),
path = "/comment/{id}/delete",
responses(
(status = 200, body = CommonResult<String>, content_type = "application/json")
),
tag = ISSUE_TAG
)]
async fn delete_comment(
_: LoginUser,
Path(id): Path<i64>,
state: State<MonoApiServiceState>,
) -> Result<Json<CommonResult<String>>, ApiError> {
state.conv_stg().remove_conversation(id).await?;
Ok(Json(CommonResult::success(None)))
}

/// update issue related labels
/// Update issue related labels
#[utoipa::path(
post,
path = "/labels",
Expand All @@ -245,7 +227,7 @@ async fn labels(
api_common::label_assignee::label_update(user, state, payload, String::from("issue")).await
}

/// update issue related assignees
/// Update issue related assignees
#[utoipa::path(
post,
path = "/assignees",
Expand All @@ -262,3 +244,29 @@ async fn assignees(
) -> Result<Json<CommonResult<()>>, ApiError> {
api_common::label_assignee::assignees_update(user, state, payload, String::from("issue")).await
}

/// Edit issue title
#[utoipa::path(
post,
params(
("link", description = "A string ID representing a Issue"),
),
path = "/{link}/title",
request_body = ContentPayload,
responses(
(status = 200, body = CommonResult<String>, content_type = "application/json")
),
tag = ISSUE_TAG
)]
async fn edit_title(
_: LoginUser,
Path(link): Path<String>,
state: State<MonoApiServiceState>,
Json(payload): Json<ContentPayload>,
) -> Result<Json<CommonResult<String>>, ApiError> {
state
.issue_stg()
.edit_title(&link, &payload.content)
.await?;
Ok(Json(CommonResult::success(None)))
}
34 changes: 20 additions & 14 deletions mono/src/api/mr/mr_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::api::{
self,
model::{AssigneeUpdatePayload, ListPayload},
},
conversation::SaveCommentRequest,
conversation::ContentPayload,
issue::ItemRes,
label::LabelUpdatePayload,
mr::{FilesChangedList, MRDetailRes, MrFilesRes, MuiTreeNode},
Expand All @@ -40,9 +40,9 @@ pub fn routers() -> OpenApiRouter<MonoApiServiceState> {
.routes(routes!(mr_files_changed))
.routes(routes!(mr_files_list))
.routes(routes!(save_comment))
.routes(routes!(delete_comment))
.routes(routes!(labels))
.routes(routes!(assignees)),
.routes(routes!(assignees))
.routes(routes!(edit_title)),
)
}

Expand Down Expand Up @@ -299,7 +299,7 @@ async fn mr_files_list(
("link", description = "MR link"),
),
path = "/{link}/comment",
request_body = SaveCommentRequest,
request_body = ContentPayload,
responses(
(status = 200, body = CommonResult<String>, content_type = "application/json")
),
Expand All @@ -309,7 +309,7 @@ async fn save_comment(
user: LoginUser,
Path(link): Path<String>,
state: State<MonoApiServiceState>,
Json(payload): Json<SaveCommentRequest>,
Json(payload): Json<ContentPayload>,
) -> Result<Json<CommonResult<String>>, ApiError> {
let res = state.mr_stg().get_mr(&link).await?;
let model = res.ok_or(MegaError::with_message("Not Found"))?;
Expand All @@ -325,23 +325,29 @@ async fn save_comment(
Ok(Json(CommonResult::success(None)))
}

/// Delete Comment
/// Edit MR title
#[utoipa::path(
delete,
post,
params(
("conv_id", description = "Conversation id"),
("link", description = "A string ID representing a Merge Request"),
),
path = "/comment/{conv_id}/delete",
path = "/{link}/title",
request_body = ContentPayload,
responses(
(status = 200, body = CommonResult<String>, content_type = "application/json")
),
tag = MR_TAG
)]
async fn delete_comment(
Path(conv_id): Path<i64>,
async fn edit_title(
_: LoginUser,
Path(link): Path<String>,
state: State<MonoApiServiceState>,
Json(payload): Json<ContentPayload>,
) -> Result<Json<CommonResult<String>>, ApiError> {
state.conv_stg().remove_conversation(conv_id).await?;
state
.mr_stg()
.edit_title(&link, &payload.content)
.await?;
Ok(Json(CommonResult::success(None)))
}

Expand All @@ -365,7 +371,7 @@ fn extract_files_with_status(diff_output: &str) -> HashMap<String, String> {
files
}

/// update mr related labels
/// Update mr related labels
#[utoipa::path(
post,
path = "/labels",
Expand All @@ -383,7 +389,7 @@ async fn labels(
api_common::label_assignee::label_update(user, state, payload, String::from("mr")).await
}

/// update MR related assignees
/// Update MR related assignees
#[utoipa::path(
post,
path = "/assignees",
Expand Down
Loading
Loading