use db::conn::sea_orm::*; use time::OffsetDateTime; use uuid::Uuid; use crate::error::{IssueError, IssueResult}; use crate::features::IssueService; use super::super::{LabelView, UpdateLabelOption}; use super::helpers::{load_label, require_authenticated}; pub async fn update_label( svc: &IssueService, actor: Uuid, channel_id: Uuid, label_id: Uuid, input: UpdateLabelOption, ) -> IssueResult { require_authenticated(actor)?; let cur = load_label(svc, channel_id, label_id).await?; if let Some(ref n) = input.name { let trimmed = n.trim().to_string(); if trimmed.is_empty() || trimmed.len() > svc.config.max_label_name_len { return Err(IssueError::BadRequest("invalid label name".into())); } } if let Some(ref c) = input.color && c.len() > svc.config.max_label_color_len { return Err(IssueError::BadRequest("invalid label color".into())); } let db = svc.db.writer(); let mut active: db::issue::issue_label::ActiveModel = cur.into(); if let Some(n) = input.name { active.name = Set(n.trim().to_string()); } if let Some(c) = input.color { active.color = Set(c); } if let Some(e) = input.exclusive { active.exclusive = Set(e); } if let Some(o) = input.exclusive_order { active.exclusive_order = Set(o); } if let Some(opt) = input.description { active.description = Set(opt); } if let Some(a) = input.is_archived { active.is_archived = Set(a); } active.updated_at = Set(Some(OffsetDateTime::now_utc())); let saved = active.update(&db).await?; Ok(LabelView::from(saved)) }